Josh,
Thank you for your answer.
I looked into the code and it seems to me I'm better off with redefining
_load. Something like:
sub _load {
# ....
elsif (-f $name) {
if (open(FH, $name)) {
my $text = <FH>;
$text = $self->_decode_unicode($text) if $self->{ UNICODE };
+ $self->_processMultilang(\$text);
$data = {
name => $alias,
path => $name,
text => $text,
time => (stat $name)[9],
load => $now,
};
}
elsif ($tolerant) {
($data, $error) = (undef,
Template::Constants::STATUS_DECLINED);
}
else {
$data = "$alias: $!";
$error = Template::Constants::STATUS_ERROR;
}
}
else {
($data, $error) = (undef, Template::Constants::STATUS_DECLINED);
}
}
# ...
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?
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.
- Fagzal
Hi, I just ran through the code and I do not believe there is a way to
do this. I think you will need to subclass Provider.pm, and redefine
the _fetch routine. You can probably just copy it over into your
subclassed module, and then make the modifications you need.
There are a few examples how you can subclass Provider.pm on the web:
http://template-toolkit.org/pipermail/templates/2001-June/001037.html
http://66.102.7.104/search?q=cache:vBQNoGAjDa0J:www.grahamnet.org.uk/test/slash/Slash/Display/Provider/Provider.pm+%22use+base+qw(Template::Provider)%3B%22&hl=en
http://www.mail-archive.com/[email protected]/msg05852.html
Here tells you how to use your subclassed Provider.pm I think.
http://www.template-toolkit.org/docs/plain/Manual/Config.html
I believe it is the LOAD_TEMPLATES config option, although I could be
entirely wrong as I have not done this myself before.
Hopefully that helps you out. If anyone thinks what I've proposed is
wrong, feel free to yell. :) This is all based on a quick run-thru of
the code.
-- Josh
Fagyal Csongor wrote:
Hi folks,
I would like to kind of pre-process the templates I pass to TT.
However, I want to keep all the nice caching features (disk+memory),
so what I would like to do is to first filter the file TT is
processing through a sub I wrote, but *only* when the file is changed
on disk (which TT knows and handles anyway). So I need something like:
sub process {
# ....
# do lots of magic
# ...
# if (template_changed_on_disk) $text = slurp ....
# ...
&my_filter_hack(\$text); # doing some multilingual preporcessing
# ...
# continue magic
# ...
}
Is there an easy way to do what's above? Preferably without
subclassing / rewriting Template.pm :)
Thanks,
- Fagzal
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates