text::template::preprocess(3)

NAME

Text::Template::Preprocess - Expand template text with
embedded Perl

VERSION

This file documents "Text::Template::Preprocess" version
1.43

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 sup
plied, it must be a reference to a preprocessor subrou
tine. When filling out a template, "Text::Template::Pre
processor" will use this subroutine to preprocess the pro
gram 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 exe
cute contents of $_ and insert the result into the appro
priate part of the template.

"Text::Template::Preprocess" objects also support a util
ity method, "preprocessor()", which sets a new preproces
sor 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 argu
ments, "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 }
<script language=JavaScript>
if (br== "n3") {
// etc.
}
</script>
{ 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(<script(.*?)</script>)(q{$1})gsi;
}
Then use "PREPROCESSOR => quote_scripts". This will
transform

SEE ALSO

Text::Template

AUTHOR

Mark-Jason Dominus, Plover Systems

Please send questions and other remarks about this soft
ware to "mjd-perl-template+@plover.com"

You can join a very low-volume (<10 messages per year)
mailing list for announcements about this package. Send
an empty note to "mjd-perl-template-request@plover.com" to
join.

For updates, visit "http://www.plover.com/~mjd/perl/Tem
plate/".

LICENSE

Text::Template::Preprocess version 1.43
Copyright (C) 2001 Mark Jason Dominus

This program is free software; you can redistribute it
and/or
modify it under the terms of the GNU General Public
License as
published by the Free Software Foundation; either ver
sion 2 of the
License, or (at your option) any later version. You
may also can
redistribute it and/or modify it under the terms of
the Perl
Artistic License.
This program is distributed in the hope that it will
be useful,
but WITHOUT ANY WARRANTY; without even the implied
warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the
GNU General Public License for more details.
You should have received copies of the GNU General
Public License
along with this program; if not, write to the Free
Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
Copyright © 2010-2025 Platon Technologies, s.r.o.           Home | Man pages | tLDP | Documents | Utilities | About
Design by styleshout