[Templates] TT for error messages

Andy Wardley abw@wardley.org
Thu, 19 Jul 2007 08:06:53 +0100


Brad Bowman wrote:
> Can I avoid reparsing the message templates somehow?

Yes, if you pre-declare the templates as named BLOCKS:

> my $tt = Template->new(
>             INTERPOLATE     => 1,
>             START_TAG       => quotemeta('<<'),
>             END_TAG         => quotemeta('>>'),
+             BLOCKS          => {
+                msg1 => 'The [% thing %] is broken',
+             }
>         );

And then process them by name:

> $tt->process(\$msg_template, $context, \$message)

   $tt->process($msg_template_name, $context, \$message)

HTH
A