<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
package Text::Template::Preprocess;
use Text::Template;
@ISA = qw(Text::Template);
$Text::Template::Preprocess::VERSION = 1.46;

sub fill_in {
  my $self = shift;
  my (%args) = @_;
  my $pp = $args{PREPROCESSOR} || $self-&gt;{PREPROCESSOR} ;
  if ($pp) {
    local $_ = $self-&gt;source();
#    print "# fill_in: before &lt;$_&gt;\n";
    &amp;$pp;
#    print "# fill_in: after &lt;$_&gt;\n";
    $self-&gt;set_source_data($_);
  }
  $self-&gt;SUPER::fill_in(@_);
}

sub preprocessor {
  my ($self, $pp) = @_;
  my $old_pp = $self-&gt;{PREPROCESSOR};
  $self-&gt;{PREPROCESSOR} = $pp if @_ &gt; 1;  # OK to pass $pp=undef
  $old_pp;
}

1;


=head1 NAME 

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

=head1 VERSION

This file documents C&lt;Text::Template::Preprocess&gt; version B&lt;1.46&gt;

=head1 SYNOPSIS

 use Text::Template::Preprocess;

 my $t = Text::Template::Preprocess-&gt;new(...);  # identical to Text::Template

 # Fill in template, but preprocess each code fragment with pp().
 my $result = $t-&gt;fill_in(..., PREPROCESSOR =&gt; \&amp;pp);

 my $old_pp = $t-&gt;preprocessor(\&amp;new_pp);

=head1 DESCRIPTION

C&lt;Text::Template::Preprocess&gt; provides a new C&lt;PREPROCESSOR&gt; option to
C&lt;fill_in&gt;.  If the C&lt;PREPROCESSOR&gt; option is supplied, it must be a
reference to a preprocessor subroutine.  When filling out a template,
C&lt;Text::Template::Preprocessor&gt; 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 C&lt;$_&gt;.  The
subroutine should modify the contents of C&lt;$_&gt; and return.
C&lt;Text::Template::Preprocess&gt; will then execute contents of C&lt;$_&gt; and
insert the result into the appropriate part of the template.

C&lt;Text::Template::Preprocess&gt; objects also support a utility method,
C&lt;preprocessor()&gt;, which sets a new preprocessor for the object.  This
preprocessor is used for all subsequent calls to C&lt;fill_in&gt; except
where overridden by an explicit C&lt;PREPROCESSOR&gt; option.
C&lt;preprocessor()&gt; returns the previous default preprocessor function,
or undefined if there wasn't one.  When invoked with no arguments,
C&lt;preprocessor()&gt; returns the object's current default preprocessor
function without changing it.

In all other respects, C&lt;Text::Template::Preprocess&gt; is identical to
C&lt;Text::Template&gt;.

=head1 WHY?

One possible purpose:  If your files contain a lot of JavaScript, like
this:


        Plain text here...
        { perl code }
        &lt;script language=JavaScript&gt;
     	      if (br== "n3") { 
	  	  // etc.
	      }
        &lt;/script&gt;
        { more perl code }
        More plain text...

You don't want C&lt;Text::Template&gt; to confuse the curly braces in the
JavaScript program with executable Perl code.  One strategy:

        sub quote_scripts {
          s(&lt;script(.*?)&lt;/script&gt;)(q{$1})gsi;
        }

Then use C&lt;PREPROCESSOR =E&lt;gt&gt; \&amp;quote_scripts&gt;.  This will transform 



=head1 SEE ALSO

L&lt;Text::Template&gt;

=head1 AUTHOR


Mark Jason Dominus, Plover Systems

Please send questions and other remarks about this software to
C&lt;mjd-perl-template+@plover.com&gt;

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

For updates, visit C&lt;http://www.plover.com/~mjd/perl/Template/&gt;.

=head1 LICENSE

    Text::Template::Preprocess version 1.46
    Copyright 2013 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 version 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.


=cut

</pre></body></html>