> Can I avoid reparsing the message templates somehow?

This is one of the things that will be fixed if TT3 uses MD5 sums to identify 
stringrefs.  Template::Alloy does it for you currently.

use Template::Alloy;

my $tt = Template::Alloy->new(
             INTERPOLATE     => 1,
             START_TAG       => quotemeta('<<'),
             END_TAG         => quotemeta('>>'),
             # need some way to tell it to cache between uses
             COMPILE_DIR     => '/tmp',
         );
>
> # msg_template would come from a database
> my $msg_template =
>     'Line $lineno too short, length <<line.length || 0>>, line.quote';
> my $context = { line => "a b c\cM", lineno => 123 };
>
> my $message;
> $tt->process(\$msg_template, $context, \$message)
>      or do {
>          warn "Message template error: ".$tt->error;
>          $message = $msg_template;
>      };
>
> print $message, "\n";

That bit should work without modification.

Paul

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

Reply via email to