1Text::Template::PreprocUessesr(3C)ontributed Perl DocumeTnetxatt:i:oTnemplate::Preprocess(3)
2
3
4
6 Text::Template::Preprocess - Expand template text with embedded Perl
7
9 version 1.58
10
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
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
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 => \"e_scripts". This will transform
68
70 Text::Template
71
73 The development version is on github at
74 <https://https://github.com/mschout/perl-text-template> and may be
75 cloned from <git://https://github.com/mschout/perl-text-template.git>
76
78 Please report any bugs or feature requests on the bugtracker website
79 <https://github.com/mschout/perl-text-template/issues>
80
81 When submitting a bug or request, please include a test-file or a patch
82 to an existing test-file that illustrates the bug or desired feature.
83
85 Mark Jason Dominus, Plover Systems
86
87 Please send questions and other remarks about this software to
88 "mjd-perl-template+@plover.com"
89
90 You can join a very low-volume (<10 messages per year) mailing list for
91 announcements about this package. Send an empty note to
92 "mjd-perl-template-request@plover.com" to join.
93
94 For updates, visit "http://www.plover.com/~mjd/perl/Template/".
95
97 This software is copyright (c) 2013 by Mark Jason Dominus
98 <mjd@cpan.org>.
99
100 This is free software; you can redistribute it and/or modify it under
101 the same terms as the Perl 5 programming language system itself.
102
103
104
105perl v5.30.1 2020-01-30 Text::Template::Preprocess(3)