[Catalyst] New Catalyst + TT problem
Zbigniew Lukasiak
zzbbyy at gmail.com
Wed Dec 14 18:18:09 CET 2005
OK - now I understand what happened. As far as I understand it you can
provide config arguments from the main application module or from the
component (view) module. The $arguments are from the component
configuration. That's how I understand it.
Anyway the @include_path array can be in both places so we need to
take that into account as well.
Here is my patch:
Index: lib/Catalyst/View/TT.pm
===================================================================
--- lib/Catalyst/View/TT.pm (revision 2684)
+++ lib/Catalyst/View/TT.pm (working copy)
@@ -250,21 +250,29 @@
sub new {
my ( $class, $c, $arguments ) = @_;
my $delim = $class->config->{DELIMITER} || $arguments->{DELIMITER};
- my @include_path = _coerce_paths($arguments->{INCLUDE_PATH}, $delim);
- if(!@include_path){
- @include_path = _coerce_paths($class->config->{INCLUDE_PATH}, $delim);
+ my $include_path;
+ if(ref $arguments->{INCLUDE_PATH} eq 'ARRAY'){
+ $include_path = $arguments->{INCLUDE_PATH};
+ }elsif(ref $class->config->{INCLUDE_PATH} eq 'ARRAY'){
+ $include_path = $class->config->{INCLUDE_PATH};
+ }else{
+ my @include_path = _coerce_paths($arguments->{INCLUDE_PATH}, $delim);
+ if(!@include_path){
+ @include_path =
_coerce_paths($class->config->{INCLUDE_PATH}, $delim);
+ }
+ if(!@include_path){
+ my $root = $c->config->{root};
+ my $base = Path::Class::dir($root, 'base');
+ @include_path = ( "$root", "$base" );
+ }
+ $include_path = \@include_path;
}
- if(!@include_path){
- my $root = $c->config->{root};
- my $base = Path::Class::dir($root, 'base');
- @include_path = ( "$root", "$base" );
- }
my $config = {
EVAL_PERL => 0,
TEMPLATE_EXTENSION => '',
%{ $class->config },
%{$arguments},
- INCLUDE_PATH => \@include_path,
+ INCLUDE_PATH => $include_path,
};
# if we're debugging and/or the TIMER option is set, then we install
@@ -298,7 +306,7 @@
%{$config},
},
);
- $self->include_path(\@include_path);
+ $self->include_path($include_path);
$self->config($config);
return $self;
@@ -345,7 +353,6 @@
%{ $c->stash() }
};
- my @tmp_path = @{$self->include_path};
unshift @{$self->include_path},
@{$c->stash->{additional_template_paths}} if ref
$c->stash->{additional_template_paths};
unless ( $self->template->process( $template, $vars, \$output ) ) {
my $error = $self->template->error;
@@ -354,7 +361,7 @@
$c->error($error);
return 0;
}
- @{$self->include_path} = @tmp_path if ref
$c->stash->{additional_template_paths};
+ splice @{$self->include_path}, 0, scalar
@{$c->stash->{additional_template_paths}} if ref
$c->stash->{additional_template_paths};
unless ( $c->response->content_type ) {
$c->response->content_type('text/html; charset=utf-8');
=============================================
-- Zbyszek
On 12/14/05, Bill Moseley <moseley at hank.org> wrote:
> On Wed, Dec 14, 2005 at 11:12:27AM +0100, Albert Vila wrote:
> > After upgrade to the last Catalyst version my custom TT view does not
> > work propertly.
> >
> >
> > I've solved the problem using the
> > $c->stash->{additional_template_paths}. However, I think some people is
> > using a similar solution to mine. Won't this option work anymore? I have
> > to switch to the additional_template_paths variable?
>
> I've avoided upgrading as it will break my code, too. I didn't think
> it was that hard to alter the include path the old way.
>
> The old code simply passed the include path to TT, so you could save a
> reference to that array and change as needed.
>
> The new system makes a copy of the INCLUDE_PATH first, so the array
> passed to TT is not the same one as in INCLUDE_PATH -- so you can't
> modify it per-request.
>
> I'm not really following the code. When does new() get passed
> $arguments and how do INCLUDE_PATH and DELIMITER get set in that case?
>
> http://dev.catalyst.perl.org/file/trunk/Catalyst-View-TT/lib/Catalyst/View/TT.pm
>
> Here's a patch to keep it backward compatible. It should be reviewed
> as I wasn't clear about the $arguments being passed to new().
>
>
>
> Index: lib/Catalyst/View/TT.pm
> ===================================================================
> --- lib/Catalyst/View/TT.pm (revision 2686)
> +++ lib/Catalyst/View/TT.pm (working copy)
> @@ -249,22 +249,29 @@
>
> sub new {
> my ( $class, $c, $arguments ) = @_;
> - my $delim = $class->config->{DELIMITER} || $arguments->{DELIMITER};
> - my @include_path = _coerce_paths($arguments->{INCLUDE_PATH}, $delim);
> - if(!@include_path){
> - @include_path = _coerce_paths($class->config->{INCLUDE_PATH}, $delim);
> +
> + my $include_path = $class->config->{INCLUDE_PATH};
> +
> + unless ( ref $include_path eq 'ARRAY' ) {
> + my $delim = $class->config->{DELIMITER} || $arguments->{DELIMITER};
> + my @include_path = _coerce_paths($arguments->{INCLUDE_PATH}, $delim);
> + if(!@include_path){
> + @include_path = _coerce_paths($class->config->{INCLUDE_PATH}, $delim);
> + }
> + if(!@include_path){
> + my $root = $c->config->{root};
> + my $base = Path::Class::dir($root, 'base');
> + @include_path = ( "$root", "$base" );
> + }
> + $include_path = \@include_path;
> }
> - if(!@include_path){
> - my $root = $c->config->{root};
> - my $base = Path::Class::dir($root, 'base');
> - @include_path = ( "$root", "$base" );
> - }
> +
> my $config = {
> EVAL_PERL => 0,
> TEMPLATE_EXTENSION => '',
> %{ $class->config },
> %{$arguments},
> - INCLUDE_PATH => \@include_path,
> + INCLUDE_PATH => $include_path,
> };
>
> # if we're debugging and/or the TIMER option is set, then we install
> @@ -298,7 +305,7 @@
> %{$config},
> },
> );
> - $self->include_path(\@include_path);
> + $self->include_path($include_path);
> $self->config($config);
>
> return $self;
> @@ -344,9 +351,9 @@
> ),
> %{ $c->stash() }
> };
> -
> - my @tmp_path = @{$self->include_path};
> +
> unshift @{$self->include_path}, @{$c->stash->{additional_template_paths}} if ref $c->stash->{additional_template_paths};
> +
> unless ( $self->template->process( $template, $vars, \$output ) ) {
> my $error = $self->template->error;
> $error = qq/Couldn't render template "$error"/;
> @@ -354,8 +361,12 @@
> $c->error($error);
> return 0;
> }
> - @{$self->include_path} = @tmp_path if ref $c->stash->{additional_template_paths};
> -
> +
> + splice @{$self->include_path}, 0, scalar @{$c->stash->{additional_template_paths}}
> + if ref $c->stash->{additional_template_paths};
> +
> +
> +
> unless ( $c->response->content_type ) {
> $c->response->content_type('text/html; charset=utf-8');
> }
>
>
>
>
>
>
>
>
>
> >
> > Thanks.
> >
> > _______________________________________________
> > Catalyst mailing list
> > Catalyst at lists.rawmode.org
> > http://lists.rawmode.org/mailman/listinfo/catalyst
> >
>
> --
> Bill Moseley
> moseley at hank.org
>
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>
More information about the Catalyst
mailing list