# phpman > perldoc > Text::Template::Preprocess

## NAME
    [Text::Template::Preprocess](https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ATemplate%3A%3APreprocess/markdown) - Expand template text with embedded Perl

## VERSION
    version 1.60

## SYNOPSIS
     use [Text::Template::Preprocess](https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ATemplate%3A%3APreprocess/markdown);

     my $t = [Text::Template::Preprocess](https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ATemplate%3A%3APreprocess/markdown)->new(...);  # identical to [Text::Template](https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ATemplate/markdown)

     # 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](https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ATemplate%3A%3APreprocess/markdown)" 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](https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ATemplate%3A%3APreprocessor/markdown)" 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](https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ATemplate%3A%3APreprocess/markdown)" will then execute contents of $_ and insert the result into the
    appropriate part of the template.

    "[Text::Template::Preprocess](https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ATemplate%3A%3APreprocess/markdown)" 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](https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ATemplate%3A%3APreprocess/markdown)" is identical to "[Text::Template](https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ATemplate/markdown)".

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](https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ATemplate/markdown)" 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](https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ATemplate/markdown)

## SOURCE
    The development version is on github at <<https://https://github.com/mschout/perl-text-template>>
    and may be cloned from <git://<https://github.com/mschout/perl-text-template.git>>

## BUGS
    Please report any bugs or feature requests on the bugtracker website
    <<https://github.com/mschout/perl-text-template/issues>>

    When submitting a bug or request, please include a test-file or a patch to an existing test-file
    that illustrates the bug or desired feature.

## AUTHOR
    Mark Jason Dominus, Plover Systems

    Please send questions and other remarks about this software 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/Template/>".

## COPYRIGHT AND LICENSE
    This software is copyright (c) 2013 by Mark Jason Dominus <<mjd@cpan.org>>.

    This is free software; you can redistribute it and/or modify it under the same terms as the Perl
    5 programming language system itself.

