Text::Template::Preprocess(3) User Contributed Perl Documentation
NAME
Text::Template::Preprocess - Expand template text with embedded Perl
VERSION
version 1.61
SYNOPSIS
use Text::Template::Preprocess;
my $t = Text::Template::Preprocess->new(...); # identical to Text::Template
# Fill in template, but preprocess each code fragment with pp().
my $result = $t->fill_in(..., PREPROCESSOR => \&pp);
my $old_pp = $t->preprocessor(\&new_pp);
DESCRIPTION
"Text::Template::Preprocess" provides a new "PREPROCESSOR" option to
"fill_in". If the "PREPROCESSOR" option is supplied, it must be a
reference to a preprocessor subroutine. When filling out a template,
"Text::Template::Preprocessor" will use this subroutine to preprocess
the program fragment prior to evaluating the code.
The preprocessor subroutine will be called repeatedly, once for each
program fragment. The program fragment will be in $_. The subroutine
should modify the contents of $_ and return.
"Text::Template::Preprocess" will then execute contents of $_ and
insert the result into the appropriate part of the template.
"Text::Template::Preprocess" objects also support a utility method,
preprocessor(), which sets a new preprocessor for the object. This
preprocessor is used for all subsequent calls to "fill_in" except where
overridden by an explicit "PREPROCESSOR" option. preprocessor()
returns the previous default preprocessor function, or undefined if
there wasn't one. When invoked with no arguments, preprocessor()
returns the object's current default preprocessor function without
changing it.
In all other respects, "Text::Template::Preprocess" is identical to
"Text::Template".
WHY?
One possible purpose: If your files contain a lot of JavaScript, like
this:
Plain text here...
{ perl code }
{ more perl code }
More plain text...
You don't want "Text::Template" to confuse the curly braces in the
JavaScript program with executable Perl code. One strategy:
sub quote_scripts {
s(