Fagyal Csongor wrote:
I looked into the code and it seems to me I'm better off with redefining _load. Something like:

-------
Yeah, I thought about mentioning this myself after I sent that email. :) You 
can do it in fetch, but it's a bit more complicated, since you have to check 
the $data hash returned.
-------

+              $self->_processMultilang(\$text);

-------
Yeah, that looks like it would do the trick for you.
-------



BTW, it would be nice to have something like a Template::Provider::_preprocess ()

sub _preporcess {
   my ($self, $textref) = @_;
   $self->{CUSTOM_PREPORCESS} && &{$self->{CUSTOM_PREPORCESS}}($textref);
}

in Provider.pm, called from _load() as $self->_preprocess(\$text), and Template::_init () as

#...
die("Nope, I need a coderef!") if ($self->{CUSTOM_PREPROCESS} && (ref $self->{CUSTOM_PREPROCESS} ne 'CODE'));
$self->{CUSTOM_PREPROCESS} = $config->{CUSTOM_PREPROCESS};
#...


:)) What do you think?

-------
I think you're probably better off subclassing. I think you'll find that you'll 
be hard pressed to get Andy to do any patches on the TT2 line. From what I've 
read, he's busy in normal life, and TT3 development has even slowed or is 
non-existent at the moment until he gets someone to fund it.

Other than that, if he did include a patch like this, it'd probably be better 
to rename the config item to be more specific. Something along the lines of:
'ON_FILE_LOAD_PREPROCESS'.
-------


And another thing. Is there a mechanism to preload a list of templates into Template.pm? I have an application server that uses TT, and as far as I know, templates are (???) cached in $self, which is not very efficient in my case as all forked children have their separate copies of the compiled code.

-------
Hmm, I think I've read something in the mailing lists related to this, but am 
not sure. Maybe someone else can answer this for you.

I think you'll end up being ok here, because once templates are complied they 
load pretty quickly, even from disk. The most used files will usually be cached 
by the OS, so it's pretty much a perl eval from memory which should be somewhat 
quick. Also, if the forked children stay around for a while, then they'll 
gradually get their own caches built up quickly.

*WARNING: Possible bogus statement from me.*
Looking at the code, $context->template() seems to do the loading and compiling in Service.pm::process() (which is called from Template::process). Perhaps you could run that on each template to load them in the cache. I think you might need to call $context->reset() before each time you do that, though.
This is a guess, and I have not looked into it at all. I'm not sure if it's a 
good idea to do, whether it will work, or anything else about it. :) Basically 
I just threw it out as an idea for you do with as you will.
*END WARNING*

Perhaps someone else has an experience here they can share with you.
-------

_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to