[Catalyst] Context sensitive template locations

Johan Lindström johanl at DarSerMan.com
Mon Nov 21 22:22:08 CET 2005


At 21:36 2005-11-21, Perrin Harkins wrote:
>There are lots in the TT archives.  I've lost count of the number of
>times I answered this one.

Yeah, I found a post where you said to look in the archives, but I couldn't 
find any actual code :)  The array ref modification it is.


New code in case anyone is interested:

-----
__PACKAGE__->mk_accessors('include_path');

sub new {
     my ($class, $c, $arguments) = @_;

     my $root = $c->config->{root};

     #Note: Tight coupling with the parent class: Repeat of the
     #default and overridden values
     my $include_path =
             $arguments->{INCLUDE_PATH} ||
             $class->config->{INCLUDE_PATH} ||
             [ $root, "$root/base" ];
     $arguments->{INCLUDE_PATH} = $include_path;

     my $self = $class->SUPER::new($c, $arguments);
     $self->include_path($include_path);

     return($self);
}

sub process {
     my ($self, $c) = @_;

     my $dir_action = $c->path_to('root', $c->namespace || "base");

     unshift(@{$self->include_path}, $dir_action);
     eval { $self->SUPER::process($c); };
     shift(@{$self->include_path});
     $@ and die;

     return 1;
}
-----

Input welcome.


/J




More information about the Catalyst mailing list