[Templates] TT Speed Question

David Dick david_dick@mbox.com.au
Thu, 09 Jan 2003 09:21:57 +1100


how about this?

my ($template) = Template->new({ 
                         INCLUDE_PATH => [ sub { return ( [
'/path/to/include' ] ); } ],
                               });

Hopefully i included enuff brackets there.  The include path can handle
an anonymous array of subs, which must return a reference to an array. 

http://www.template-toolkit.org/docs/plain/Manual/Config.html mentions
it in the section about the INCLUDE directive

----- Original Message -----
From: Paul Makepeace <tt2.org@paulm.com>
Date: Thursday, January 9, 2003 9:17 am
Subject: Re: [Templates] TT Speed Question

> On Wed, Jan 08, 2003 at 03:15:14PM +0000, Mark Fowler wrote:
> > The most important thing with TT performance, the thing that most 
> people> get wrong, is that you need to have one Template object 
> that persists
> > between requests.
> > 
> > This means doing something like:
> > 
> >   our $template ||= Template->new();
> 
> When I'm handling each page, I have create an INCLUDE_PATH that's
> dependent on the URL, so that bits can be dropped into any of the 
> parentdirectories.
> 
>    # @libs is an array of absolute paths searched in order
>    # for the file specified in the URL. Check from most specific to
>    # least.
>    my @libs = map { "$template_root/$_" } (
>            "",
>            # etc
>    );
>    unshift @libs, map { m~/$~ ? "$_$path" : "$_/$path" } @libs if 
> $path;    # etc
> 
>    my $template = Template->new({
>            INCLUDE_PATH    => [ @libs ],
>            # ...
> 
> So as it stands it's creating a new Template object per request. Do 
> youhave any suggestions how I might get around this i.e. retain 
> this or
> similar behaviour but also make it persist? I didn't 'til now realise
> the persistence was that important.
> 
> I suppose this boils down to: does the INCLUDE_PATH affect its
> internal cache? And can it be set after the creation?
> 
> Cheers,
> Paul
> 
> -- 
> Paul Makepeace ....................................... 
> http://paulm.com/
> "What is a telephone? Try weeding instead."
>   -- http://paulm.com/toys/surrealism/
> 
> _______________________________________________
> templates mailing list
> templates@template-toolkit.org
> http://lists.ourshack.com/mailman/listinfo/templates
> 

---------------------------------------------------------------------
Would you like to receive faxes to your personal email address?
You can with mBox.  Visit http://www.mbox.com.au/fax