1Text::Template::PreprocUessesr(3C)ontributed Perl DocumeTnetxatt:i:oTnemplate::Preprocess(3)
2
3
4

NAME

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

VERSION

9       This file documents "Text::Template::Preprocess" version 1.45
10

SYNOPSIS

12        use Text::Template::Preprocess;
13
14        my $t = Text::Template::Preprocess->new(...);  # identical to Text::Template
15
16        # Fill in template, but preprocess each code fragment with pp().
17        my $result = $t->fill_in(..., PREPROCESSOR => \&pp);
18
19        my $old_pp = $t->preprocessor(\&new_pp);
20

DESCRIPTION

22       "Text::Template::Preprocess" provides a new "PREPROCESSOR" option to
23       "fill_in".  If the "PREPROCESSOR" option is supplied, it must be a
24       reference to a preprocessor subroutine.  When filling out a template,
25       "Text::Template::Preprocessor" will use this subroutine to preprocess
26       the program fragment prior to evaluating the code.
27
28       The preprocessor subroutine will be called repeatedly, once for each
29       program fragment.  The program fragment will be in $_.  The subroutine
30       should modify the contents of $_ and return.
31       "Text::Template::Preprocess" will then execute contents of $_ and
32       insert the result into the appropriate part of the template.
33
34       "Text::Template::Preprocess" objects also support a utility method,
35       "preprocessor()", which sets a new preprocessor for the object.  This
36       preprocessor is used for all subsequent calls to "fill_in" except where
37       overridden by an explicit "PREPROCESSOR" option.  "preprocessor()"
38       returns the previous default preprocessor function, or undefined if
39       there wasn't one.  When invoked with no arguments, "preprocessor()"
40       returns the object's current default preprocessor function without
41       changing it.
42
43       In all other respects, "Text::Template::Preprocess" is identical to
44       "Text::Template".
45

WHY?

47       One possible purpose:  If your files contain a lot of JavaScript, like
48       this:
49
50               Plain text here...
51               { perl code }
52               <script language=JavaScript>
53                     if (br== "n3") {
54                         // etc.
55                     }
56               </script>
57               { more perl code }
58               More plain text...
59
60       You don't want "Text::Template" to confuse the curly braces in the
61       JavaScript program with executable Perl code.  One strategy:
62
63               sub quote_scripts {
64                 s(<script(.*?)</script>)(q{$1})gsi;
65               }
66
67       Then use "PREPROCESSOR => \&quote_scripts".  This will transform
68

SEE ALSO

70       Text::Template
71

AUTHOR

73       Mark-Jason Dominus, Plover Systems
74
75       Please send questions and other remarks about this software to
76       "mjd-perl-template+@plover.com"
77
78       You can join a very low-volume (<10 messages per year) mailing list for
79       announcements about this package.  Send an empty note to
80       "mjd-perl-template-request@plover.com" to join.
81
82       For updates, visit "http://www.plover.com/~mjd/perl/Template/".
83

LICENSE

85           Text::Template::Preprocess version 1.45
86           Copyright (C) 2008 Mark Jason Dominus
87
88           This program is free software; you can redistribute it and/or
89           modify it under the terms of the GNU General Public License as
90           published by the Free Software Foundation; either version 2 of the
91           License, or (at your option) any later version.  You may also can
92           redistribute it and/or modify it under the terms of the Perl
93           Artistic License.
94
95           This program is distributed in the hope that it will be useful,
96           but WITHOUT ANY WARRANTY; without even the implied warranty of
97           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
98           GNU General Public License for more details.
99
100           You should have received copies of the GNU General Public License
101           along with this program; if not, write to the Free Software
102           Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
103
104
105
106perl v5.12.0                      2008-04-16     Text::Template::Preprocess(3)
Impressum