logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: Global default for Templates: msg#00139

Subject: Re: Global default for Templates
Thilo Planz wrote:
Dan,

 I guess the other benefit I'm looking to receive is the caching
of templates. But I don't want to go through all of my modules adding the
cache option to load_tmpl. Can I set this somehow in my base class's prerun
or init methods?


You can override your base class's load_tmpl method (now inherited from CGI::App).

Have a look at the source of CGI::App's load_tmpl , copy that code into your base class
and just add the cache option.

A better solution would be to extend it rather than duplicate it. Don't copy/paste the code, but rely on it. From the C::A docs -

   The load_tmpl() method will pass any extra parameters sent to it
   directly to HTML::Template->new_file(). This will allow the
   HTML::Template object to be further customized:

So you can put this in your base class:

sub load_tmpl {
  my ($self, @args) = @_;
  return $self->SUPER::load_tmpl(@args, cache => 1);
}

Much simpler and easier to maintain if C::A changes the interanals of it's load_tmpl method.

--
Michael Peters
Developer
Plus Three, LP


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/cgiapp@xxxxxxxxxxxxxxxxx/
             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: cgiapp-unsubscribe@xxxxxxxxxxxxxxxxx
For additional commands, e-mail: cgiapp-help@xxxxxxxxxxxxxxxxx




<Prev in Thread] Current Thread [Next in Thread>