home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Config.pod < prev    next >
Encoding:
Text File  |  2004-01-30  |  59.4 KB  |  2,123 lines

  1. #============================================================= -*-perl-*-
  2. #
  3. # Template::Manual::Config
  4. #
  5. # DESCRIPTION
  6. #   This section contains details of all the configuration options that
  7. #   can be used to customise the behaviour and extend the features of
  8. #   the Template Toolkit.
  9. #
  10. # AUTHOR
  11. #   Andy Wardley  <abw@andywardley.com>
  12. #
  13. # COPYRIGHT
  14. #   Copyright (C) 1996-2001 Andy Wardley.  All Rights Reserved.
  15. #   Copyright (C) 1998-2001 Canon Research Centre Europe Ltd.
  16. #
  17. #   This module is free software; you can redistribute it and/or
  18. #   modify it under the same terms as Perl itself.
  19. #
  20. # REVISION
  21. #   
  22. #
  23. #========================================================================
  24.  
  25.  
  26. #------------------------------------------------------------------------
  27. # IMPORTANT NOTE
  28. #   This documentation is generated automatically from source
  29. #   templates.  Any changes you make here may be lost.
  30. #   The 'docsrc' documentation source bundle is available for download
  31. #   from http://www.template-toolkit.org/docs.html and contains all
  32. #   the source templates, XML files, scripts, etc., from which the
  33. #   documentation for the Template Toolkit is built.
  34. #------------------------------------------------------------------------
  35.  
  36. =head1 NAME
  37.  
  38. Template::Manual::Config - Configuration options
  39.  
  40. =head1 DESCRIPTION
  41.  
  42. This section contains details of all the configuration options that can
  43. be used to customise the behaviour and extend the features of the
  44. Template Toolkit.
  45.  
  46. =head2 Template Style and Parsing Options
  47.  
  48. =over 4
  49.  
  50.  
  51.  
  52. =item START_TAG, END_TAG
  53.  
  54. The START_TAG and END_TAG options are used to specify character
  55. sequences or regular expressions that mark the start and end of a
  56. template directive.  The default values for START_TAG and END_TAG are
  57. '[%' and '%]' respectively, giving us the familiar directive style:
  58.  
  59.     [% example %]
  60.  
  61. Any Perl regex characters can be used and therefore should be escaped
  62. (or use the Perl C<quotemeta> function) if they are intended to
  63. represent literal characters.
  64.  
  65.     my $template = Template->new({ 
  66.       START_TAG => quotemeta('<+'),
  67.       END_TAG   => quotemeta('+>'),
  68.     });
  69.  
  70. example:
  71.  
  72.     <+ INCLUDE foobar +>
  73.  
  74. The TAGS directive can also be used to set the START_TAG and END_TAG values
  75. on a per-template file basis.
  76.  
  77.     [% TAGS <+ +> %]
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84. =item TAG_STYLE
  85.  
  86. The TAG_STYLE option can be used to set both START_TAG and END_TAG
  87. according to pre-defined tag styles.  
  88.  
  89.     my $template = Template->new({ 
  90.       TAG_STYLE => 'star',
  91.     });
  92.  
  93. Available styles are:
  94.  
  95.     template    [% ... %]               (default)
  96.     template1   [% ... %] or %% ... %%  (TT version 1)
  97.     metatext    %% ... %%               (Text::MetaText)
  98.     star        [* ... *]               (TT alternate)
  99.     php         <? ... ?>               (PHP)
  100.     asp         <% ... %>               (ASP)
  101.     mason       <% ...  >               (HTML::Mason)
  102.     html        <!-- ... -->            (HTML comments)
  103.  
  104. Any values specified for START_TAG and/or END_TAG will over-ride
  105. those defined by a TAG_STYLE.  
  106.  
  107. The TAGS directive may also be used to set a TAG_STYLE
  108.  
  109.     [% TAGS html %]
  110.     <!-- INCLUDE header -->
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. =item PRE_CHOMP, POST_CHOMP
  118.  
  119. Anything outside a directive tag is considered plain text and is
  120. generally passed through unaltered (but see the INTERPOLATE option).
  121. This includes all whitespace and newlines characters surrounding
  122. directive tags.  Directives that don't generate any output will leave
  123. gaps in the output document.
  124.  
  125. Example:
  126.  
  127.     Foo
  128.     [% a = 10 %]
  129.     Bar
  130.  
  131. Output:
  132.  
  133.     Foo
  134.  
  135.     Bar
  136.  
  137. The PRE_CHOMP and POST_CHOMP options can help to clean up some of this
  138. extraneous whitespace.  Both are disabled by default.
  139.  
  140.     my $template = Template->new({
  141.     PRE_CHOMP  => 1,
  142.     POST_CHOMP => 1,
  143.     });
  144.  
  145. With PRE_CHOMP set to 1, the newline and whitespace preceding a directive
  146. at the start of a line will be deleted.  This has the effect of 
  147. concatenating a line that starts with a directive onto the end of the 
  148. previous line.
  149.  
  150.      Foo <----------.
  151.                 |
  152.     ,---(PRE_CHOMP)----'
  153.     |
  154.     `-- [% a = 10 %] --.
  155.                 |
  156.     ,---(POST_CHOMP)---'
  157.     |
  158.     `-> Bar
  159.  
  160. With POST_CHOMP set to 1, any whitespace after a directive up to and
  161. including the newline will be deleted.  This has the effect of joining
  162. a line that ends with a directive onto the start of the next line.
  163.  
  164. If PRE_CHOMP or POST_CHOMP is set to 2, then instead of removing all
  165. the whitespace, the whitespace will be collapsed to a single space.
  166. This is useful for HTML, where (usually) a contiguous block of
  167. whitespace is rendered the same as a single space.
  168.  
  169. You may use the CHOMP_NONE, CHOMP_ALL, and CHOMP_COLLAPSE constants
  170. from the Template::Constants module to deactivate chomping, remove
  171. all whitespace, or collapse whitespace to a single space.
  172.  
  173. PRE_CHOMP and POST_CHOMP can be activated for individual directives by
  174. placing a '-' immediately at the start and/or end of the directive.
  175.  
  176.     [% FOREACH user = userlist %]
  177.        [%- user -%]
  178.     [% END %]
  179.  
  180. The '-' characters activate both PRE_CHOMP and POST_CHOMP for the one
  181. directive '[%- name -%]'.  Thus, the template will be processed as if
  182. written:
  183.  
  184.     [% FOREACH user = userlist %][% user %][% END %]
  185.  
  186. Note that this is the same as if PRE_CHOMP and POST_CHOMP were set
  187. to CHOMP_ALL; the only way to get the CHOMP_COLLAPSE behavior is
  188. to set PRE_CHOMP or POST_CHOMP accordingly.  If PRE_CHOMP or POST_CHOMP
  189. is already set to CHOMP_COLLAPSE, using '-' will give you CHOMP_COLLAPSE
  190. behavior, not CHOMP_ALL behavior.
  191.  
  192. Similarly, '+' characters can be used to disable PRE_CHOMP or
  193. POST_CHOMP (i.e.  leave the whitespace/newline intact) options on a
  194. per-directive basis.
  195.  
  196.     [% FOREACH user = userlist %]
  197.     User: [% user +%]
  198.     [% END %]
  199.  
  200. With POST_CHOMP enabled, the above example would be parsed as if written:
  201.  
  202.     [% FOREACH user = userlist %]User: [% user %]
  203.     [% END %]
  204.  
  205.  
  206.  
  207.  
  208.  
  209. =item TRIM
  210.  
  211. The TRIM option can be set to have any leading and trailing whitespace 
  212. automatically removed from the output of all template files and BLOCKs.
  213.  
  214. By example, the following BLOCK definition
  215.  
  216.     [% BLOCK foo %]
  217.     Line 1 of foo
  218.     [% END %]
  219.  
  220. will be processed is as "\nLine 1 of foo\n".  When INCLUDEd, the surrounding
  221. newlines will also be introduced.
  222.  
  223.     before 
  224.     [% INCLUDE foo %]
  225.     after
  226.  
  227. output:
  228.     before
  229.  
  230.     Line 1 of foo
  231.  
  232.     after
  233.  
  234. With the TRIM option set to any true value, the leading and trailing
  235. newlines (which count as whitespace) will be removed from the output 
  236. of the BLOCK.
  237.  
  238.     before
  239.     Line 1 of foo
  240.     after
  241.  
  242. The TRIM option is disabled (0) by default.
  243.  
  244.  
  245.  
  246.  
  247.  
  248. =item INTERPOLATE
  249.  
  250. The INTERPOLATE flag, when set to any true value will cause variable 
  251. references in plain text (i.e. not surrounded by START_TAG and END_TAG)
  252. to be recognised and interpolated accordingly.  
  253.  
  254.     my $template = Template->new({ 
  255.       INTERPOLATE => 1,
  256.     });
  257.  
  258. Variables should be prefixed by a '$' to identify them.  Curly braces
  259. can be used in the familiar Perl/shell style to explicitly scope the
  260. variable name where required.
  261.  
  262.     # INTERPOLATE => 0
  263.     <a href="http://[% server %]/[% help %]">
  264.     <img src="[% images %]/help.gif"></a>
  265.     [% myorg.name %]
  266.   
  267.     # INTERPOLATE => 1
  268.     <a href="http://$server/$help">
  269.     <img src="$images/help.gif"></a>
  270.     $myorg.name
  271.   
  272.     # explicit scoping with {  }
  273.     <img src="$images/${icon.next}.gif">
  274.  
  275. Note that a limitation in Perl's regex engine restricts the maximum length
  276. of an interpolated template to around 32 kilobytes or possibly less.  Files
  277. that exceed this limit in size will typically cause Perl to dump core with
  278. a segmentation fault.  If you routinely process templates of this size 
  279. then you should disable INTERPOLATE or split the templates in several 
  280. smaller files or blocks which can then be joined backed together via 
  281. PROCESS or INCLUDE.
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289. =item ANYCASE
  290.  
  291. By default, directive keywords should be expressed in UPPER CASE.  The 
  292. ANYCASE option can be set to allow directive keywords to be specified
  293. in any case.
  294.  
  295.     # ANYCASE => 0 (default)
  296.     [% INCLUDE foobar %]    # OK
  297.     [% include foobar %]        # ERROR
  298.     [% include = 10   %]        # OK, 'include' is a variable
  299.  
  300.     # ANYCASE => 1
  301.     [% INCLUDE foobar %]    # OK
  302.     [% include foobar %]    # OK
  303.     [% include = 10   %]        # ERROR, 'include' is reserved word
  304.  
  305. One side-effect of enabling ANYCASE is that you cannot use a variable
  306. of the same name as a reserved word, regardless of case.  The reserved
  307. words are currently:
  308.  
  309.         GET CALL SET DEFAULT INSERT INCLUDE PROCESS WRAPPER 
  310.     IF UNLESS ELSE ELSIF FOR FOREACH WHILE SWITCH CASE
  311.     USE PLUGIN FILTER MACRO PERL RAWPERL BLOCK META
  312.     TRY THROW CATCH FINAL NEXT LAST BREAK RETURN STOP 
  313.     CLEAR TO STEP AND OR NOT MOD DIV END
  314.  
  315.  
  316. The only lower case reserved words that cannot be used for variables,
  317. regardless of the ANYCASE option, are the operators:
  318.  
  319.     and or not mod div
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326. =back
  327.  
  328. =head2 Template Files and Blocks
  329.  
  330. =over 4
  331.  
  332.  
  333.  
  334. =item INCLUDE_PATH
  335.  
  336. The INCLUDE_PATH is used to specify one or more directories in which
  337. template files are located.  When a template is requested that isn't
  338. defined locally as a BLOCK, each of the INCLUDE_PATH directories is
  339. searched in turn to locate the template file.  Multiple directories
  340. can be specified as a reference to a list or as a single string where
  341. each directory is delimited by ':'.
  342.  
  343.     my $template = Template->new({
  344.         INCLUDE_PATH => '/usr/local/templates',
  345.     });
  346.   
  347.     my $template = Template->new({
  348.         INCLUDE_PATH => '/usr/local/templates:/tmp/my/templates',
  349.     });
  350.   
  351.     my $template = Template->new({
  352.         INCLUDE_PATH => [ '/usr/local/templates', 
  353.                           '/tmp/my/templates' ],
  354.     });
  355.  
  356. On Win32 systems, a little extra magic is invoked, ignoring delimiters
  357. that have ':' followed by a '/' or '\'.  This avoids confusion when using
  358. directory names like 'C:\Blah Blah'.
  359.  
  360. When specified as a list, the INCLUDE_PATH path can contain elements 
  361. which dynamically generate a list of INCLUDE_PATH directories.  These 
  362. generator elements can be specified as a reference to a subroutine or 
  363. an object which implements a paths() method.
  364.  
  365.     my $template = Template->new({
  366.         INCLUDE_PATH => [ '/usr/local/templates', 
  367.                           \&incpath_generator, 
  368.               My::IncPath::Generator->new( ... ) ],
  369.     });
  370.  
  371. Each time a template is requested and the INCLUDE_PATH examined, the
  372. subroutine or object method will be called.  A reference to a list of
  373. directories should be returned.  Generator subroutines should report
  374. errors using die().  Generator objects should return undef and make an
  375. error available via its error() method.
  376.  
  377. For example:
  378.  
  379.     sub incpath_generator {
  380.  
  381.     # ...some code...
  382.     
  383.     if ($all_is_well) {
  384.         return \@list_of_directories;
  385.     }
  386.     else {
  387.         die "cannot generate INCLUDE_PATH...\n";
  388.     }
  389.     }
  390.  
  391. or:
  392.  
  393.     package My::IncPath::Generator;
  394.  
  395.     # Template::Base (or Class::Base) provides error() method
  396.     use Template::Base;
  397.     use base qw( Template::Base );
  398.  
  399.     sub paths {
  400.     my $self = shift;
  401.  
  402.     # ...some code...
  403.  
  404.         if ($all_is_well) {
  405.         return \@list_of_directories;
  406.     }
  407.     else {
  408.         return $self->error("cannot generate INCLUDE_PATH...\n");
  409.     }
  410.     }
  411.  
  412.     1;
  413.  
  414.  
  415.  
  416.  
  417.  
  418. =item DELIMITER
  419.  
  420. Used to provide an alternative delimiter character sequence for 
  421. separating paths specified in the INCLUDE_PATH.  The default
  422. value for DELIMITER is ':'.
  423.  
  424.     # tolerate Silly Billy's file system conventions
  425.     my $template = Template->new({
  426.     DELIMITER    => '; ',
  427.         INCLUDE_PATH => 'C:/HERE/NOW; D:/THERE/THEN',
  428.     });
  429.  
  430.     # better solution: install Linux!  :-)
  431.  
  432. On Win32 systems, the default delimiter is a little more intelligent,
  433. splitting paths only on ':' characters that aren't followed by a '/'.
  434. This means that the following should work as planned, splitting the 
  435. INCLUDE_PATH into 2 separate directories, C:/foo and C:/bar.
  436.  
  437.     # on Win32 only
  438.     my $template = Template->new({
  439.     INCLUDE_PATH => 'C:/Foo:C:/Bar'
  440.     });
  441.  
  442. However, if you're using Win32 then it's recommended that you
  443. explicitly set the DELIMITER character to something else (e.g. ';')
  444. rather than rely on this subtle magic.
  445.  
  446.  
  447.  
  448.  
  449. =item ABSOLUTE
  450.  
  451. The ABSOLUTE flag is used to indicate if templates specified with
  452. absolute filenames (e.g. '/foo/bar') should be processed.  It is
  453. disabled by default and any attempt to load a template by such a
  454. name will cause a 'file' exception to be raised.
  455.  
  456.     my $template = Template->new({
  457.     ABSOLUTE => 1,
  458.     });
  459.  
  460.     # this is why it's disabled by default
  461.     [% INSERT /etc/passwd %]
  462.  
  463. On Win32 systems, the regular expression for matching absolute 
  464. pathnames is tweaked slightly to also detect filenames that start
  465. with a driver letter and colon, such as:
  466.  
  467.     C:/Foo/Bar
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474. =item RELATIVE
  475.  
  476. The RELATIVE flag is used to indicate if templates specified with
  477. filenames relative to the current directory (e.g. './foo/bar' or
  478. '../../some/where/else') should be loaded.  It is also disabled by
  479. default, and will raise a 'file' error if such template names are
  480. encountered.  
  481.  
  482.     my $template = Template->new({
  483.     RELATIVE => 1,
  484.     });
  485.  
  486.     [% INCLUDE ../logs/error.log %]
  487.  
  488.  
  489.  
  490.  
  491.  
  492. =item DEFAULT
  493.  
  494. The DEFAULT option can be used to specify a default template which should 
  495. be used whenever a specified template can't be found in the INCLUDE_PATH.
  496.  
  497.     my $template = Template->new({
  498.     DEFAULT => 'notfound.html',
  499.     });
  500.  
  501. If a non-existant template is requested through the Template process()
  502. method, or by an INCLUDE, PROCESS or WRAPPER directive, then the
  503. DEFAULT template will instead be processed, if defined.  Note that the
  504. DEFAULT template is not used when templates are specified with
  505. absolute or relative filenames, or as a reference to a input file
  506. handle or text string.
  507.  
  508.  
  509.  
  510.  
  511.  
  512. =item BLOCKS
  513.  
  514. The BLOCKS option can be used to pre-define a default set of template 
  515. blocks.  These should be specified as a reference to a hash array 
  516. mapping template names to template text, subroutines or Template::Document
  517. objects.
  518.  
  519.     my $template = Template->new({
  520.     BLOCKS => {
  521.         header  => 'The Header.  [% title %]',
  522.         footer  => sub { return $some_output_text },
  523.         another => Template::Document->new({ ... }),
  524.     },
  525.     }); 
  526.  
  527.  
  528.  
  529.  
  530. =item AUTO_RESET
  531.  
  532. The AUTO_RESET option is set by default and causes the local BLOCKS
  533. cache for the Template::Context object to be reset on each call to the
  534. Template process() method.  This ensures that any BLOCKs defined
  535. within a template will only persist until that template is finished
  536. processing.  This prevents BLOCKs defined in one processing request
  537. from interfering with other independent requests subsequently
  538. processed by the same context object.
  539.  
  540. The BLOCKS item may be used to specify a default set of block definitions
  541. for the Template::Context object.  Subsequent BLOCK definitions in templates
  542. will over-ride these but they will be reinstated on each reset if AUTO_RESET
  543. is enabled (default), or if the Template::Context reset() method is called.
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553. =item RECURSION
  554.  
  555. The template processor will raise a file exception if it detects
  556. direct or indirect recursion into a template.  Setting this option to 
  557. any true value will allow templates to include each other recursively.
  558.  
  559.  
  560.  
  561. =back
  562.  
  563. =head2 Template Variables
  564.  
  565. =over 4
  566.  
  567. =item VARIABLES, PRE_DEFINE
  568.  
  569. The VARIABLES option (or PRE_DEFINE - they're equivalent) can be used
  570. to specify a hash array of template variables that should be used to
  571. pre-initialise the stash when it is created.  These items are ignored
  572. if the STASH item is defined.
  573.  
  574.     my $template = Template->new({
  575.     VARIABLES => {
  576.         title   => 'A Demo Page',
  577.         author  => 'Joe Random Hacker',
  578.         version => 3.14,
  579.     },
  580.     };
  581.  
  582. or
  583.  
  584.     my $template = Template->new({
  585.     PRE_DEFINE => {
  586.         title   => 'A Demo Page',
  587.         author  => 'Joe Random Hacker',
  588.         version => 3.14,
  589.     },
  590.     };
  591.  
  592.  
  593.  
  594.  
  595. =item CONSTANTS
  596.  
  597. The CONSTANTS option can be used to specify a hash array of template
  598. variables that are compile-time constants.  These variables are
  599. resolved once when the template is compiled, and thus don't require
  600. further resolution at runtime.  This results in significantly faster
  601. processing of the compiled templates and can be used for variables that
  602. don't change from one request to the next.
  603.  
  604.     my $template = Template->new({
  605.     CONSTANTS => {
  606.         title   => 'A Demo Page',
  607.         author  => 'Joe Random Hacker',
  608.         version => 3.14,
  609.     },
  610.     };
  611.  
  612. =item CONSTANT_NAMESPACE
  613.  
  614. Constant variables are accessed via the 'constants' namespace by
  615. default.
  616.  
  617.     [% constants.title %]
  618.  
  619. The CONSTANTS_NAMESPACE option can be set to specify an alternate
  620. namespace.
  621.  
  622.     my $template = Template->new({
  623.     CONSTANTS => {
  624.         title   => 'A Demo Page',
  625.         # ...etc...
  626.     },
  627.     CONSTANTS_NAMESPACE => 'const',
  628.     };
  629.  
  630. In this case the constants would then be accessed as:
  631.  
  632.     [% const.title %]
  633.  
  634. =item NAMESPACE
  635.  
  636. The constant folding mechanism described above is an example of a
  637. namespace handler.  Namespace handlers can be defined to provide
  638. alternate parsing mechanisms for variables in different namespaces.
  639.  
  640. Under the hood, the Template module converts a constructor configuration
  641. such as:
  642.  
  643.     my $template = Template->new({
  644.     CONSTANTS => {
  645.         title   => 'A Demo Page',
  646.         # ...etc...
  647.     },
  648.     CONSTANTS_NAMESPACE => 'const',
  649.     };
  650.  
  651. into one like:
  652.  
  653.     my $template = Template->new({
  654.     NAMESPACE => {
  655.         const => Template:::Namespace::Constants->new({
  656.         title   => 'A Demo Page',
  657.         # ...etc...
  658.         }),
  659.     },
  660.     };
  661.  
  662. You can use this mechanism to define multiple constant namespaces, or
  663. to install custom handlers of your own.  
  664.  
  665.     my $template = Template->new({
  666.     NAMESPACE => {
  667.         site => Template:::Namespace::Constants->new({
  668.         title   => "Wardley's Widgets",
  669.         version => 2.718,
  670.         }),
  671.         author => Template:::Namespace::Constants->new({
  672.         name  => 'Andy Wardley',
  673.         email => 'abw@andywardley.com',
  674.         }),
  675.         voodoo => My::Namespace::Handler->new( ... ),
  676.     },
  677.     };
  678.  
  679. Now you have 2 constant namespaces, for example:
  680.  
  681.     [% site.title %]
  682.     [% author.name %]
  683.  
  684. as well as your own custom namespace handler installed for the 'voodoo'
  685. namespace.
  686.  
  687.     [% voodoo.magic %]
  688.  
  689. See L<Template::Namespace::Constants|Template::Namespace::Constants>
  690. for an example of what a namespace handler looks like on the inside.
  691.  
  692.  
  693.  
  694.  
  695.  
  696. =back
  697.  
  698. =head2 Template Processing Options
  699.  
  700.  
  701. The following options are used to specify any additional templates
  702. that should be processed before, after, around or instead of the
  703. template passed as the first argument to the Template process()
  704. method.  These options can be perform various useful tasks such as
  705. adding standard headers or footers to all pages, wrapping page output
  706. in other templates, pre-defining variables or performing
  707. initialisation or cleanup tasks, automatically generating page summary
  708. information, navigation elements, and so on.
  709.  
  710. The task of processing the template is delegated internally to the
  711. Template::Service module which, unsurprisingly, also has a process()
  712. method.  Any templates defined by the PRE_PROCESS option are processed
  713. first and any output generated is added to the output buffer.  Then
  714. the main template is processed, or if one or more PROCESS templates
  715. are defined then they are instead processed in turn.  In this case,
  716. one of the PROCESS templates is responsible for processing the main
  717. template, by a directive such as:
  718.  
  719.     [% PROCESS $template %]
  720.  
  721. The output of processing the main template or the PROCESS template(s)
  722. is then wrapped in any WRAPPER templates, if defined.  WRAPPER
  723. templates don't need to worry about explicitly processing the template
  724. because it will have been done for them already.  Instead WRAPPER
  725. templates access the content they are wrapping via the 'content'
  726. variable.
  727.  
  728.     wrapper before
  729.     [% content %]
  730.     wrapper after
  731.  
  732. This output generated from processing the main template, and/or any
  733. PROCESS or WRAPPER templates is added to the output buffer.  Finally,
  734. any POST_PROCESS templates are processed and their output is also
  735. added to the output buffer which is then returned.
  736.  
  737. If the main template throws an exception during processing then any
  738. relevant template(s) defined via the ERROR option will be processed
  739. instead.  If defined and successfully processed, the output from the
  740. error template will be added to the output buffer in place of the
  741. template that generated the error and processing will continue,
  742. applying any WRAPPER and POST_PROCESS templates.  If no relevant ERROR
  743. option is defined, or if the error occurs in one of the PRE_PROCESS,
  744. WRAPPER or POST_PROCESS templates, then the process will terminate
  745. immediately and the error will be returned.
  746.  
  747.  
  748.  
  749. =over 4
  750.  
  751.  
  752.  
  753. =item PRE_PROCESS, POST_PROCESS
  754.  
  755. These values may be set to contain the name(s) of template files
  756. (relative to INCLUDE_PATH) which should be processed immediately
  757. before and/or after each template.  These do not get added to 
  758. templates processed into a document via directives such as INCLUDE, 
  759. PROCESS, WRAPPER etc.
  760.  
  761.     my $template = Template->new({
  762.     PRE_PROCESS  => 'header',
  763.     POST_PROCESS => 'footer',
  764.     };
  765.  
  766. Multiple templates may be specified as a reference to a list.  Each is 
  767. processed in the order defined.
  768.  
  769.     my $template = Template->new({
  770.     PRE_PROCESS  => [ 'config', 'header' ],
  771.     POST_PROCESS => 'footer',
  772.     };
  773.  
  774. Alternately, multiple template may be specified as a single string, 
  775. delimited by ':'.  This delimiter string can be changed via the 
  776. DELIMITER option.
  777.  
  778.     my $template = Template->new({
  779.     PRE_PROCESS  => 'config:header',
  780.     POST_PROCESS => 'footer',
  781.     };
  782.  
  783. The PRE_PROCESS and POST_PROCESS templates are evaluated in the same
  784. variable context as the main document and may define or update
  785. variables for subsequent use.
  786.  
  787. config:
  788.  
  789.     [% # set some site-wide variables
  790.        bgcolor = '#ffffff'
  791.        version = 2.718
  792.     %]
  793.  
  794. header:
  795.  
  796.     [% DEFAULT title = 'My Funky Web Site' %]
  797.     <html>
  798.     <head>
  799.     <title>[% title %]</title>
  800.     </head>
  801.     <body bgcolor="[% bgcolor %]">
  802.  
  803. footer:
  804.  
  805.     <hr>
  806.     Version [% version %]
  807.     </body>
  808.     </html>
  809.  
  810. The Template::Document object representing the main template being processed
  811. is available within PRE_PROCESS and POST_PROCESS templates as the 'template'
  812. variable.  Metadata items defined via the META directive may be accessed 
  813. accordingly.
  814.  
  815.     $template->process('mydoc.html', $vars);
  816.  
  817. mydoc.html:
  818.  
  819.     [% META title = 'My Document Title' %]
  820.     blah blah blah
  821.     ...
  822.  
  823. header:
  824.  
  825.     <html>
  826.     <head>
  827.     <title>[% template.title %]</title></head>
  828.     <body bgcolor="[% bgcolor %]">
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843. =item PROCESS
  844.  
  845. The PROCESS option may be set to contain the name(s) of template files
  846. (relative to INCLUDE_PATH) which should be processed instead of the 
  847. main template passed to the Template process() method.  This can 
  848. be used to apply consistent wrappers around all templates, similar to 
  849. the use of PRE_PROCESS and POST_PROCESS templates.
  850.  
  851.     my $template = Template->new({
  852.     PROCESS  => 'content',
  853.     };
  854.  
  855.     # processes 'content' instead of 'foo.html'
  856.     $template->process('foo.html');
  857.  
  858. A reference to the original template is available in the 'template'
  859. variable.  Metadata items can be inspected and the template can be
  860. processed by specifying it as a variable reference (i.e. prefixed by
  861. '$') to an INCLUDE, PROCESS or WRAPPER directive.
  862.  
  863. content:
  864.  
  865.     <html>
  866.     <head>
  867.     <title>[% template.title %]</title>
  868.     </head>
  869.     
  870.     <body>
  871.     [% PROCESS $template %]
  872.     <hr>
  873.     © Copyright [% template.copyright %]
  874.     </body>
  875.     </html>
  876.  
  877. foo.html:
  878.  
  879.     [% META 
  880.        title     = 'The Foo Page'
  881.        author    = 'Fred Foo'
  882.        copyright = '2000 Fred Foo'
  883.     %]
  884.     <h1>[% template.title %]</h1>
  885.     Welcome to the Foo Page, blah blah blah
  886.  
  887. output:    
  888.  
  889.     <html>
  890.     <head>
  891.     <title>The Foo Page</title>
  892.     </head>
  893.  
  894.     <body>
  895.     <h1>The Foo Page</h1>
  896.     Welcome to the Foo Page, blah blah blah
  897.     <hr>
  898.     © Copyright 2000 Fred Foo
  899.     </body>
  900.     </html>
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908. =item WRAPPER
  909.  
  910. The WRAPPER option can be used to specify one or more templates which
  911. should be used to wrap around the output of the main page template.
  912. The main template is processed first (or any PROCESS template(s)) and
  913. the output generated is then passed as the 'content' variable to the
  914. WRAPPER template(s) as they are processed.
  915.  
  916.     my $template = Template->new({
  917.     WRAPPER => 'wrapper',
  918.     };
  919.  
  920.     # process 'foo' then wrap in 'wrapper'
  921.     $template->process('foo', { message => 'Hello World!' });
  922.  
  923. wrapper:
  924.  
  925.     <wrapper>
  926.     [% content %]
  927.     </wrapper>
  928.  
  929. foo:
  930.  
  931.     This is the foo file!
  932.     Message: [% message %]
  933.  
  934. The output generated from this example is:
  935.  
  936.     <wrapper>
  937.     This is the foo file!
  938.     Message: Hello World!
  939.     </wrapper>
  940.  
  941. You can specify more than one WRAPPER template by setting the value to
  942. be a reference to a list of templates.  The WRAPPER templates will be
  943. processed in reverse order with the output of each being passed to the
  944. next (or previous, depending on how you look at it) as the 'content'
  945. variable.  It sounds complicated, but the end result is that it just
  946. "Does The Right Thing" to make wrapper templates nest in the order you
  947. specify.
  948.  
  949.     my $template = Template->new({
  950.     WRAPPER => [ 'outer', 'inner' ],
  951.     };
  952.  
  953.     # process 'foo' then wrap in 'inner', then in 'outer'
  954.     $template->process('foo', { message => 'Hello World!' });
  955.  
  956. outer:
  957.  
  958.     <outer>
  959.     [% content %]
  960.     </outer>
  961.  
  962. inner:
  963.  
  964.     <inner>
  965.     [% content %]
  966.     </inner>
  967.  
  968. The output generated is then:
  969.  
  970.     <outer>
  971.     <inner>
  972.     This is the foo file!
  973.     Message: Hello World!
  974.     </inner>
  975.     </outer>
  976.  
  977. One side-effect of the "inside-out" processing of the WRAPPER
  978. configuration item (and also the WRAPPER directive) is that any
  979. variables set in the template being wrapped will be visible to the
  980. template doing the wrapping, but not the other way around.
  981.  
  982. You can use this to good effect in allowing page templates to set
  983. pre-defined values which are then used in the wrapper templates.  For
  984. example, our main page template 'foo' might look like this:
  985.  
  986. foo:
  987.  
  988.     [% page = {
  989.            title    = 'Foo Page'
  990.            subtitle = 'Everything There is to Know About Foo'
  991.            author   = 'Frank Oliver Octagon'
  992.        }
  993.     %]
  994.  
  995.     <p>
  996.     Welcome to the page that tells you everything about foo
  997.     blah blah blah...
  998.     </p>
  999.  
  1000. The 'foo' template is processed before the wrapper template meaning
  1001. that the 'page' data structure will be defined for use in the wrapper
  1002. template.
  1003.  
  1004. wrapper:
  1005.  
  1006.     <html>
  1007.       <head>
  1008.         <title>[% page.title %]</title>
  1009.       </head>
  1010.       <body>
  1011.         <h1>[% page.title %]</h1>
  1012.         <h2>[% page.subtitle %]</h1>
  1013.         <h3>by [% page.author %]</h3>
  1014.  
  1015.         [% content %]
  1016.       </body>
  1017.     </html>
  1018.  
  1019. It achieves the same effect as defining META items which are then 
  1020. accessed via the 'template' variable (which you are still free to 
  1021. use within WRAPPER templates), but gives you more flexibility in 
  1022. the type and complexity of data that you can define.
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028. =item ERROR
  1029.  
  1030. The ERROR (or ERRORS if you prefer) configuration item can be used to
  1031. name a single template or specify a hash array mapping exception types
  1032. to templates which should be used for error handling.  If an uncaught
  1033. exception is raised from within a template then the appropriate error
  1034. template will instead be processed.
  1035.  
  1036. If specified as a single value then that template will be processed 
  1037. for all uncaught exceptions. 
  1038.  
  1039.     my $template = Template->new({
  1040.     ERROR => 'error.html'
  1041.     });
  1042.  
  1043. If the ERROR item is a hash reference the keys are assumed to be
  1044. exception types and the relevant template for a given exception will
  1045. be selected.  A 'default' template may be provided for the general
  1046. case.  Note that 'ERROR' can be pluralised to 'ERRORS' if you find
  1047. it more appropriate in this case.
  1048.  
  1049.     my $template = Template->new({
  1050.     ERRORS => {
  1051.         user     => 'user/index.html',
  1052.         dbi      => 'error/database',
  1053.         default  => 'error/default',
  1054.     },
  1055.     });
  1056.  
  1057. In this example, any 'user' exceptions thrown will cause the
  1058. 'user/index.html' template to be processed, 'dbi' errors are handled
  1059. by 'error/database' and all others by the 'error/default' template.
  1060. Any PRE_PROCESS and/or POST_PROCESS templates will also be applied
  1061. to these error templates.
  1062.  
  1063. Note that exception types are hierarchical and a 'foo' handler will
  1064. catch all 'foo.*' errors (e.g. foo.bar, foo.bar.baz) if a more
  1065. specific handler isn't defined.  Be sure to quote any exception types
  1066. that contain periods to prevent Perl concatenating them into a single
  1067. string (i.e. C<user.passwd> is parsed as 'user'.'passwd').
  1068.  
  1069.     my $template = Template->new({
  1070.     ERROR => {
  1071.         'user.login'  => 'user/login.html',
  1072.         'user.passwd' => 'user/badpasswd.html',
  1073.         'user'        => 'user/index.html',
  1074.         'default'     => 'error/default',
  1075.     },
  1076.     });
  1077.  
  1078. In this example, any template processed by the $template object, or
  1079. other templates or code called from within, can raise a 'user.login'
  1080. exception and have the service redirect to the 'user/login.html'
  1081. template.  Similarly, a 'user.passwd' exception has a specific 
  1082. handling template, 'user/badpasswd.html', while all other 'user' or
  1083. 'user.*' exceptions cause a redirection to the 'user/index.html' page.
  1084. All other exception types are handled by 'error/default'.
  1085.  
  1086.  
  1087. Exceptions can be raised in a template using the THROW directive,
  1088.  
  1089.     [% THROW user.login 'no user id: please login' %]
  1090.  
  1091. or by calling the throw() method on the current Template::Context object,
  1092.  
  1093.     $context->throw('user.passwd', 'Incorrect Password');
  1094.     $context->throw('Incorrect Password');    # type 'undef'
  1095.  
  1096. or from Perl code by calling die() with a Template::Exception object,
  1097.  
  1098.     die (Template::Exception->new('user.denied', 'Invalid User ID'));
  1099.  
  1100. or by simply calling die() with an error string.  This is
  1101. automagically caught and converted to an  exception of 'undef'
  1102. type which can then be handled in the usual way.
  1103.  
  1104.     die "I'm sorry Dave, I can't do that";
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111. =back
  1112.  
  1113. =head2 Template Runtime Options
  1114.  
  1115. =over 4
  1116.  
  1117.  
  1118.  
  1119.  
  1120. =item EVAL_PERL
  1121.  
  1122. This flag is used to indicate if PERL and/or RAWPERL blocks should be
  1123. evaluated.  By default, it is disabled and any PERL or RAWPERL blocks
  1124. encountered will raise exceptions of type 'perl' with the message
  1125. 'EVAL_PERL not set'.  Note however that any RAWPERL blocks should
  1126. always contain valid Perl code, regardless of the EVAL_PERL flag.  The
  1127. parser will fail to compile templates that contain invalid Perl code
  1128. in RAWPERL blocks and will throw a 'file' exception.
  1129.  
  1130. When using compiled templates (see 
  1131. L<COMPILE_EXT|Template::Manual::Config/Caching_and_Compiling_Options> and 
  1132. L<COMPILE_DIR|Template::Manual::Config/Caching_and_Compiling_Options>),
  1133. the EVAL_PERL has an affect when the template is compiled, and again
  1134. when the templates is subsequently processed, possibly in a different
  1135. context to the one that compiled it.
  1136.  
  1137. If the EVAL_PERL is set when a template is compiled, then all PERL and
  1138. RAWPERL blocks will be included in the compiled template.  If the 
  1139. EVAL_PERL option isn't set, then Perl code will be generated which 
  1140. B<always> throws a 'perl' exception with the message 'EVAL_PERL not
  1141. set' B<whenever> the compiled template code is run.
  1142.  
  1143. Thus, you must have EVAL_PERL set if you want your compiled templates
  1144. to include PERL and RAWPERL blocks.
  1145.  
  1146. At some point in the future, using a different invocation of the
  1147. Template Toolkit, you may come to process such a pre-compiled
  1148. template.  Assuming the EVAL_PERL option was set at the time the
  1149. template was compiled, then the output of any RAWPERL blocks will be
  1150. included in the compiled template and will get executed when the
  1151. template is processed.  This will happen regardless of the runtime
  1152. EVAL_PERL status.
  1153.  
  1154. Regular PERL blocks are a little more cautious, however.  If the 
  1155. EVAL_PERL flag isn't set for the I<current> context, that is, the 
  1156. one which is trying to process it, then it will throw the familiar 'perl'
  1157. exception with the message, 'EVAL_PERL not set'.
  1158.  
  1159. Thus you can compile templates to include PERL blocks, but optionally
  1160. disable them when you process them later.  Note however that it is 
  1161. possible for a PERL block to contain a Perl "BEGIN { # some code }"
  1162. block which will always get run regardless of the runtime EVAL_PERL
  1163. status.  Thus, if you set EVAL_PERL when compiling templates, it is
  1164. assumed that you trust the templates to Do The Right Thing.  Otherwise
  1165. you must accept the fact that there's no bulletproof way to prevent 
  1166. any included code from trampling around in the living room of the 
  1167. runtime environment, making a real nuisance of itself if it really
  1168. wants to.  If you don't like the idea of such uninvited guests causing
  1169. a bother, then you can accept the default and keep EVAL_PERL disabled.
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177. =item  OUTPUT
  1178.  
  1179. Default output location or handler.  This may be specified as one of:
  1180. a file name (relative to OUTPUT_PATH, if defined, or the current
  1181. working directory if not specified absolutely); a file handle
  1182. (e.g. GLOB or IO::Handle) opened for writing; a reference to a text
  1183. string to which the output is appended (the string isn't cleared); a
  1184. reference to a subroutine which is called, passing the output text as
  1185. an argument; as a reference to an array, onto which the content will be
  1186. push()ed; or as a reference to any object that supports the print()
  1187. method.  This latter option includes the Apache::Request object which
  1188. is passed as the argument to Apache/mod_perl handlers.
  1189.  
  1190. example 1 (file name):
  1191.  
  1192.     my $template = Template->new({
  1193.     OUTPUT => "/tmp/foo",
  1194.     });
  1195.  
  1196. example 2 (text string):
  1197.  
  1198.     my $output = '';
  1199.  
  1200.     my $template = Template->new({
  1201.     OUTPUT => \$output,
  1202.     });
  1203.  
  1204. example 3 (file handle):
  1205.  
  1206.     open (TOUT, "> $file") || die "$file: $!\n";
  1207.  
  1208.     my $template = Template->new({
  1209.     OUTPUT => \*TOUT,
  1210.     });
  1211.  
  1212. example 4 (subroutine):
  1213.  
  1214.     sub output { my $out = shift; print "OUTPUT: $out" }
  1215.  
  1216.     my $template = Template->new({
  1217.     OUTPUT => \&output,
  1218.     });
  1219.  
  1220. example 5 (array reference):
  1221.  
  1222.     my $template = Template->new({
  1223.     OUTPUT => \@output,
  1224.     })
  1225.  
  1226. example 6 (Apache/mod_perl handler):
  1227.  
  1228.     sub handler {
  1229.     my $r = shift;
  1230.  
  1231.     my $t = Template->new({
  1232.         OUTPUT => $r,
  1233.     });
  1234.     ...
  1235.     }
  1236.  
  1237. The default OUTPUT location be overridden by passing a third parameter
  1238. to the Template process() method.  This can be specified as any of the 
  1239. above argument types.
  1240.  
  1241.     $t->process($file, $vars, "/tmp/foo");
  1242.     $t->process($file, $vars, "bar");
  1243.     $t->process($file, $vars, \*MYGLOB);
  1244.     $t->process($file, $vars, \@output); 
  1245.     $t->process($file, $vars, $r);  # Apache::Request
  1246.     ...
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255. =item  OUTPUT_PATH
  1256.  
  1257. The OUTPUT_PATH allows a directory to be specified into which output
  1258. files should be written.  An output file can be specified by the 
  1259. OUTPUT option, or passed by name as the third parameter to the 
  1260. Template process() method.
  1261.  
  1262.     my $template = Template->new({
  1263.     INCLUDE_PATH => "/tmp/src",
  1264.     OUTPUT_PATH  => "/tmp/dest",
  1265.     });
  1266.  
  1267.     my $vars = {
  1268.     ...
  1269.     };
  1270.  
  1271.     foreach my $file ('foo.html', 'bar.html') {
  1272.     $template->process($file, $vars, $file)
  1273.         || die $template->error();    
  1274.     }
  1275.  
  1276. This example will read the input files '/tmp/src/foo.html' and 
  1277. '/tmp/src/bar.html' and write the processed output to '/tmp/dest/foo.html'
  1278. and '/tmp/dest/bar.html', respectively.
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287. =item DEBUG
  1288.  
  1289. The DEBUG option can be used to enable debugging within the various
  1290. different modules that comprise the Template Toolkit.  The
  1291. L<Template::Constants|Template::Constants> module defines a set of
  1292. DEBUG_XXXX constants which can be combined using the logical OR
  1293. operator, '|'.
  1294.  
  1295.     use Template::Constants qw( :debug );
  1296.  
  1297.     my $template = Template->new({
  1298.     DEBUG => DEBUG_PARSER | DEBUG_PROVIDER,
  1299.     });
  1300.  
  1301. For convenience, you can also provide a string containing a list
  1302. of lower case debug options, separated by any non-word characters.
  1303.  
  1304.     my $template = Template->new({
  1305.     DEBUG => 'parser, provider',
  1306.     });
  1307.  
  1308. The following DEBUG_XXXX flags can be used:
  1309.  
  1310. =over 4
  1311.  
  1312. =item DEBUG_SERVICE
  1313.  
  1314. Enables general debugging messages for the
  1315. L<Template::Service|Template::Service> module.
  1316.  
  1317. =item DEBUG_CONTEXT
  1318.  
  1319. Enables general debugging messages for the
  1320. L<Template::Context|Template::Context> module.
  1321.  
  1322. =item DEBUG_PROVIDER
  1323.  
  1324. Enables general debugging messages for the
  1325. L<Template::Provider|Template::Provider> module.
  1326.  
  1327. =item DEBUG_PLUGINS
  1328.  
  1329. Enables general debugging messages for the
  1330. L<Template::Plugins|Template::Plugins> module.
  1331.  
  1332. =item DEBUG_FILTERS
  1333.  
  1334. Enables general debugging messages for the
  1335. L<Template::Filters|Template::Filters> module.
  1336.  
  1337. =item DEBUG_PARSER
  1338.  
  1339. This flag causes the L<Template::Parser|Template::Parser> to generate
  1340. debugging messages that show the Perl code generated by parsing and
  1341. compiling each template.
  1342.  
  1343. =item DEBUG_UNDEF
  1344.  
  1345. This option causes the Template Toolkit to throw an 'undef' error
  1346. whenever it encounters an undefined variable value.
  1347.  
  1348. =item DEBUG_DIRS
  1349.  
  1350. This option causes the Template Toolkit to generate comments
  1351. indicating the source file, line and original text of each directive
  1352. in the template.  These comments are embedded in the template output
  1353. using the format defined in the DEBUG_FORMAT configuration item, or a
  1354. simple default format if unspecified.
  1355.  
  1356. For example, the following template fragment:
  1357.  
  1358.     
  1359.     Hello World
  1360.  
  1361. would generate this output:
  1362.  
  1363.     ## input text line 1 :  ##
  1364.     Hello 
  1365.     ## input text line 2 : World ##
  1366.     World
  1367.  
  1368. =item DEBUG_ALL
  1369.  
  1370. Enables all debugging messages.
  1371.  
  1372. =item DEBUG_CALLER
  1373.  
  1374. This option causes all debug messages that aren't newline terminated
  1375. to have the file name and line number of the caller appended to them.
  1376.  
  1377.  
  1378. =back
  1379.  
  1380. =item DEBUG_FORMAT
  1381.  
  1382. The DEBUG_FORMAT option can be used to specify a format string for the
  1383. debugging messages generated via the DEBUG_DIRS option described
  1384. above.  Any occurances of C<$file>, C<$line> or C<$text> will be
  1385. replaced with the current file name, line or directive text,
  1386. respectively.  Notice how the format is single quoted to prevent Perl
  1387. from interpolating those tokens as variables.
  1388.  
  1389.     my $template = Template->new({
  1390.     DEBUG => 'dirs',
  1391.     DEBUG_FORMAT => '<!-- $file line $line : [% $text %] -->',
  1392.     });
  1393.  
  1394. The following template fragment:
  1395.  
  1396.     [% foo = 'World' %]
  1397.     Hello [% foo %]
  1398.  
  1399. would then generate this output:
  1400.  
  1401.     <!-- input text line 2 : [% foo = 'World' %] -->
  1402.     Hello <!-- input text line 3 : [% foo %] -->World
  1403.  
  1404. The DEBUG directive can also be used to set a debug format within
  1405. a template.
  1406.  
  1407.     [% DEBUG format '<!-- $file line $line : [% $text %] -->' %]
  1408.  
  1409.  
  1410. =back
  1411.  
  1412. =head2 Caching and Compiling Options
  1413.  
  1414. =over 4
  1415.  
  1416.  
  1417.  
  1418. =item CACHE_SIZE
  1419.  
  1420. The Template::Provider module caches compiled templates to avoid the need
  1421. to re-parse template files or blocks each time they are used.  The CACHE_SIZE
  1422. option is used to limit the number of compiled templates that the module
  1423. should cache.
  1424.  
  1425. By default, the CACHE_SIZE is undefined and all compiled templates are
  1426. cached.  When set to any positive value, the cache will be limited to
  1427. storing no more than that number of compiled templates.  When a new
  1428. template is loaded and compiled and the cache is full (i.e. the number
  1429. of entries == CACHE_SIZE), the least recently used compiled template
  1430. is discarded to make room for the new one.
  1431.  
  1432. The CACHE_SIZE can be set to 0 to disable caching altogether.
  1433.  
  1434.     my $template = Template->new({
  1435.     CACHE_SIZE => 64,   # only cache 64 compiled templates
  1436.     });
  1437.  
  1438.     my $template = Template->new({
  1439.     CACHE_SIZE => 0,   # don't cache any compiled templates
  1440.     });
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447. =item COMPILE_EXT
  1448.  
  1449. From version 2 onwards, the Template Toolkit has the ability to
  1450. compile templates to Perl code and save them to disk for subsequent
  1451. use (i.e. cache persistence).  The COMPILE_EXT option may be
  1452. provided to specify a filename extension for compiled template files.
  1453. It is undefined by default and no attempt will be made to read or write 
  1454. any compiled template files.
  1455.  
  1456.     my $template = Template->new({
  1457.     COMPILE_EXT => '.ttc',
  1458.     });
  1459.  
  1460. If COMPILE_EXT is defined (and COMPILE_DIR isn't, see below) then compiled
  1461. template files with the COMPILE_EXT extension will be written to the same
  1462. directory from which the source template files were loaded.
  1463.  
  1464. Compiling and subsequent reuse of templates happens automatically
  1465. whenever the COMPILE_EXT or COMPILE_DIR options are set.  The Template
  1466. Toolkit will automatically reload and reuse compiled files when it 
  1467. finds them on disk.  If the corresponding source file has been modified
  1468. since the compiled version as written, then it will load and re-compile
  1469. the source and write a new compiled version to disk.  
  1470.  
  1471. This form of cache persistence offers significant benefits in terms of 
  1472. time and resources required to reload templates.  Compiled templates can
  1473. be reloaded by a simple call to Perl's require(), leaving Perl to handle
  1474. all the parsing and compilation.  This is a Good Thing.
  1475.  
  1476. =item COMPILE_DIR
  1477.  
  1478. The COMPILE_DIR option is used to specify an alternate directory root
  1479. under which compiled template files should be saved.  
  1480.  
  1481.     my $template = Template->new({
  1482.     COMPILE_DIR => '/tmp/ttc',
  1483.     });
  1484.  
  1485. The COMPILE_EXT option may also be specified to have a consistent file
  1486. extension added to these files.  
  1487.  
  1488.     my $template1 = Template->new({
  1489.     COMPILE_DIR => '/tmp/ttc',
  1490.     COMPILE_EXT => '.ttc1',
  1491.     });
  1492.  
  1493.     my $template2 = Template->new({
  1494.     COMPILE_DIR => '/tmp/ttc',
  1495.     COMPILE_EXT => '.ttc2',
  1496.     });
  1497.  
  1498.  
  1499. When COMPILE_EXT is undefined, the compiled template files have the
  1500. same name as the original template files, but reside in a different
  1501. directory tree.
  1502.  
  1503. Each directory in the INCLUDE_PATH is replicated in full beneath the 
  1504. COMPILE_DIR directory.  This example:
  1505.  
  1506.     my $template = Template->new({
  1507.     COMPILE_DIR  => '/tmp/ttc',
  1508.     INCLUDE_PATH => '/home/abw/templates:/usr/share/templates',
  1509.     });
  1510.  
  1511. would create the following directory structure:
  1512.  
  1513.     /tmp/ttc/home/abw/templates/
  1514.     /tmp/ttc/usr/share/templates/
  1515.  
  1516. Files loaded from different INCLUDE_PATH directories will have their
  1517. compiled forms save in the relevant COMPILE_DIR directory.
  1518.  
  1519. On Win32 platforms a filename may by prefixed by a drive letter and
  1520. colon.  e.g.
  1521.  
  1522.     C:/My Templates/header
  1523.  
  1524. The colon will be silently stripped from the filename when it is added
  1525. to the COMPILE_DIR value(s) to prevent illegal filename being generated.
  1526. Any colon in COMPILE_DIR elements will be left intact.  For example:
  1527.  
  1528.     # Win32 only
  1529.     my $template = Template->new({
  1530.     DELIMITER    => ';',
  1531.     COMPILE_DIR  => 'C:/TT2/Cache',
  1532.     INCLUDE_PATH => 'C:/TT2/Templates;D:/My Templates',
  1533.     });
  1534.  
  1535. This would create the following cache directories:
  1536.  
  1537.     C:/TT2/Cache/C/TT2/Templates
  1538.     C:/TT2/Cache/D/My Templates
  1539.  
  1540.  
  1541. =back
  1542.  
  1543. =head2 Plugins and Filters
  1544.  
  1545. =over 4
  1546.  
  1547.  
  1548.  
  1549. =item PLUGINS
  1550.  
  1551. The PLUGINS options can be used to provide a reference to a hash array
  1552. that maps plugin names to Perl module names.  A number of standard
  1553. plugins are defined (e.g. 'table', 'cgi', 'dbi', etc.) which map to
  1554. their corresponding Template::Plugin::* counterparts.  These can be
  1555. redefined by values in the PLUGINS hash.
  1556.  
  1557.     my $template = Template->new({
  1558.     PLUGINS => {
  1559.         cgi => 'MyOrg::Template::Plugin::CGI',
  1560.             foo => 'MyOrg::Template::Plugin::Foo',
  1561.         bar => 'MyOrg::Template::Plugin::Bar',
  1562.     },
  1563.     });
  1564.  
  1565. The USE directive is used to create plugin objects and does so by
  1566. calling the plugin() method on the current Template::Context object.
  1567. If the plugin name is defined in the PLUGINS hash then the
  1568. corresponding Perl module is loaded via require().  The context then
  1569. calls the load() class method which should return the class name 
  1570. (default and general case) or a prototype object against which the 
  1571. new() method can be called to instantiate individual plugin objects.
  1572.  
  1573. If the plugin name is not defined in the PLUGINS hash then the PLUGIN_BASE
  1574. and/or LOAD_PERL options come into effect.
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580. =item PLUGIN_BASE
  1581.  
  1582. If a plugin is not defined in the PLUGINS hash then the PLUGIN_BASE is used
  1583. to attempt to construct a correct Perl module name which can be successfully 
  1584. loaded.  
  1585.  
  1586. The PLUGIN_BASE can be specified as a single value or as a reference
  1587. to an array of multiple values.  The default PLUGIN_BASE value,
  1588. 'Template::Plugin', is always added the the end of the PLUGIN_BASE
  1589. list (a single value is first converted to a list).  Each value should
  1590. contain a Perl package name to which the requested plugin name is
  1591. appended.
  1592.  
  1593. example 1:
  1594.  
  1595.     my $template = Template->new({
  1596.     PLUGIN_BASE => 'MyOrg::Template::Plugin',
  1597.     });
  1598.  
  1599.     [% USE Foo %]    # => MyOrg::Template::Plugin::Foo
  1600.                        or        Template::Plugin::Foo 
  1601.  
  1602. example 2:
  1603.  
  1604.     my $template = Template->new({
  1605.     PLUGIN_BASE => [   'MyOrg::Template::Plugin',
  1606.              'YourOrg::Template::Plugin'  ],
  1607.     });
  1608.  
  1609.     [% USE Foo %]    # =>   MyOrg::Template::Plugin::Foo
  1610.                        or YourOrg::Template::Plugin::Foo 
  1611.                        or          Template::Plugin::Foo 
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618. =item LOAD_PERL
  1619.  
  1620. If a plugin cannot be loaded using the PLUGINS or PLUGIN_BASE
  1621. approaches then the provider can make a final attempt to load the
  1622. module without prepending any prefix to the module path.  This allows
  1623. regular Perl modules (i.e. those that don't reside in the
  1624. Template::Plugin or some other such namespace) to be loaded and used
  1625. as plugins.
  1626.  
  1627. By default, the LOAD_PERL option is set to 0 and no attempt will be made
  1628. to load any Perl modules that aren't named explicitly in the PLUGINS
  1629. hash or reside in a package as named by one of the PLUGIN_BASE
  1630. components.  
  1631.  
  1632. Plugins loaded using the PLUGINS or PLUGIN_BASE receive a reference to
  1633. the current context object as the first argument to the new()
  1634. constructor.  Modules loaded using LOAD_PERL are assumed to not
  1635. conform to the plugin interface.  They must provide a new() class
  1636. method for instantiating objects but it will not receive a reference
  1637. to the context as the first argument.  Plugin modules should provide a
  1638. load() class method (or inherit the default one from the
  1639. Template::Plugin base class) which is called the first time the plugin
  1640. is loaded.  Regular Perl modules need not.  In all other respects,
  1641. regular Perl objects and Template Toolkit plugins are identical.
  1642.  
  1643. If a particular Perl module does not conform to the common, but not
  1644. unilateral, new() constructor convention then a simple plugin wrapper
  1645. can be written to interface to it.
  1646.  
  1647.  
  1648.  
  1649.  
  1650. =item FILTERS
  1651.  
  1652. The FILTERS option can be used to specify custom filters which can
  1653. then be used with the FILTER directive like any other.  These are
  1654. added to the standard filters which are available by default.  Filters
  1655. specified via this option will mask any standard filters of the same
  1656. name.
  1657.  
  1658. The FILTERS option should be specified as a reference to a hash array
  1659. in which each key represents the name of a filter.  The corresponding
  1660. value should contain a reference to an array containing a subroutine
  1661. reference and a flag which indicates if the filter is static (0) or
  1662. dynamic (1).  A filter may also be specified as a solitary subroutine
  1663. reference and is assumed to be static.
  1664.  
  1665.     $template = Template->new({
  1666.         FILTERS => {
  1667.             'sfilt1' =>   \&static_filter,      # static
  1668.             'sfilt2' => [ \&static_filter, 0 ], # same as above
  1669.             'dfilt1' => [ \&dyanamic_filter_factory, 1 ],
  1670.         },
  1671.     });
  1672.  
  1673. Additional filters can be specified at any time by calling the 
  1674. define_filter() method on the current Template::Context object.
  1675. The method accepts a filter name, a reference to a filter 
  1676. subroutine and an optional flag to indicate if the filter is 
  1677. dynamic.
  1678.  
  1679.     my $context = $template->context();
  1680.     $context->define_filter('new_html', \&new_html);
  1681.     $context->define_filter('new_repeat', \&new_repeat, 1);
  1682.  
  1683. Static filters are those where a single subroutine reference is used
  1684. for all invocations of a particular filter.  Filters that don't accept
  1685. any configuration parameters (e.g. 'html') can be implemented
  1686. statically.  The subroutine reference is simply returned when that
  1687. particular filter is requested.  The subroutine is called to filter
  1688. the output of a template block which is passed as the only argument.
  1689. The subroutine should return the modified text.
  1690.  
  1691.     sub static_filter {
  1692.         my $text = shift;
  1693.         # do something to modify $text...
  1694.         return $text;
  1695.     }
  1696.  
  1697. The following template fragment:
  1698.  
  1699.     [% FILTER sfilt1 %]
  1700.     Blah blah blah.
  1701.     [% END %]
  1702.  
  1703. is approximately equivalent to:
  1704.  
  1705.     &static_filter("\nBlah blah blah.\n");
  1706.  
  1707. Filters that can accept parameters (e.g. 'truncate') should be
  1708. implemented dynamically.  In this case, the subroutine is taken to be
  1709. a filter 'factory' that is called to create a unique filter subroutine
  1710. each time one is requested.  A reference to the current
  1711. Template::Context object is passed as the first parameter, followed by
  1712. any additional parameters specified.  The subroutine should return
  1713. another subroutine reference (usually a closure) which implements the
  1714. filter.
  1715.  
  1716.     sub dynamic_filter_factory {
  1717.         my ($context, @args) = @_;
  1718.  
  1719.         return sub {
  1720.             my $text = shift;
  1721.             # do something to modify $text...
  1722.             return $text;           
  1723.         }
  1724.     }
  1725.  
  1726. The following template fragment:
  1727.  
  1728.     [% FILTER dfilt1(123, 456) %] 
  1729.     Blah blah blah
  1730.     [% END %]              
  1731.  
  1732. is approximately equivalent to:
  1733.  
  1734.     my $filter = &dynamic_filter_factory($context, 123, 456);
  1735.     &$filter("\nBlah blah blah.\n");
  1736.  
  1737. See the FILTER directive for further examples.
  1738.  
  1739.  
  1740. =back
  1741.  
  1742. =head2 Compatibility, Customisation and Extension
  1743.  
  1744. =over 4
  1745.  
  1746.  
  1747.  
  1748. =item V1DOLLAR
  1749.  
  1750. In version 1 of the Template Toolkit, an optional leading '$' could be placed
  1751. on any template variable and would be silently ignored.
  1752.  
  1753.     # VERSION 1
  1754.     [% $foo %]       ===  [% foo %]
  1755.     [% $hash.$key %] ===  [% hash.key %]
  1756.  
  1757. To interpolate a variable value the '${' ... '}' construct was used.
  1758. Typically, one would do this to index into a hash array when the key
  1759. value was stored in a variable.
  1760.  
  1761. example:
  1762.  
  1763.     my $vars = {
  1764.     users => {
  1765.         aba => { name => 'Alan Aardvark', ... },
  1766.         abw => { name => 'Andy Wardley', ... },
  1767.             ...
  1768.     },
  1769.     uid => 'aba',
  1770.         ...
  1771.     };
  1772.  
  1773.     $template->process('user/home.html', $vars)
  1774.     || die $template->error(), "\n";
  1775.  
  1776. 'user/home.html':
  1777.  
  1778.     [% user = users.${uid} %]     # users.aba
  1779.     Name: [% user.name %]         # Alan Aardvark
  1780.  
  1781. This was inconsistent with double quoted strings and also the
  1782. INTERPOLATE mode, where a leading '$' in text was enough to indicate a
  1783. variable for interpolation, and the additional curly braces were used
  1784. to delimit variable names where necessary.  Note that this use is
  1785. consistent with UNIX and Perl conventions, among others.
  1786.  
  1787.     # double quoted string interpolation
  1788.     [% name = "$title ${user.name}" %]
  1789.  
  1790.     # INTERPOLATE = 1
  1791.     <img src="$images/help.gif"></a>
  1792.     <img src="$images/${icon.next}.gif">
  1793.  
  1794. For version 2, these inconsistencies have been removed and the syntax
  1795. clarified.  A leading '$' on a variable is now used exclusively to
  1796. indicate that the variable name should be interpolated
  1797. (e.g. subsituted for its value) before being used.  The earlier example
  1798. from version 1:
  1799.  
  1800.     # VERSION 1
  1801.     [% user = users.${uid} %]
  1802.     Name: [% user.name %]
  1803.  
  1804. can now be simplified in version 2 as:
  1805.  
  1806.     # VERSION 2
  1807.     [% user = users.$uid %]
  1808.     Name: [% user.name %]
  1809.  
  1810. The leading dollar is no longer ignored and has the same effect of
  1811. interpolation as '${' ... '}' in version 1.  The curly braces may
  1812. still be used to explicitly scope the interpolated variable name
  1813. where necessary.
  1814.  
  1815. e.g.
  1816.  
  1817.     [% user = users.${me.id} %]
  1818.     Name: [% user.name %]
  1819.  
  1820. The rule applies for all variables, both within directives and in
  1821. plain text if processed with the INTERPOLATE option.  This means that
  1822. you should no longer (if you ever did) add a leading '$' to a variable
  1823. inside a directive, unless you explicitly want it to be interpolated.
  1824.  
  1825. One obvious side-effect is that any version 1 templates with variables
  1826. using a leading '$' will no longer be processed as expected.  Given
  1827. the following variable definitions,
  1828.  
  1829.     [% foo = 'bar'
  1830.        bar = 'baz'
  1831.     %]
  1832.  
  1833. version 1 would interpret the following as:
  1834.  
  1835.     # VERSION 1
  1836.     [% $foo %] => [% GET foo %] => bar
  1837.  
  1838. whereas version 2 interprets it as:
  1839.  
  1840.     # VERSION 2
  1841.     [% $foo %] => [% GET $foo %] => [% GET bar %] => baz
  1842.  
  1843. In version 1, the '$' is ignored and the value for the variable 'foo' is 
  1844. retrieved and printed.  In version 2, the variable '$foo' is first interpolated
  1845. to give the variable name 'bar' whose value is then retrieved and printed.
  1846.  
  1847. The use of the optional '$' has never been strongly recommended, but
  1848. to assist in backwards compatibility with any version 1 templates that
  1849. may rely on this "feature", the V1DOLLAR option can be set to 1
  1850. (default: 0) to revert the behaviour and have leading '$' characters
  1851. ignored.
  1852.  
  1853.     my $template = Template->new({
  1854.     V1DOLLAR => 1,
  1855.     });
  1856.  
  1857.  
  1858.  
  1859.  
  1860. =item LOAD_TEMPLATES
  1861.  
  1862. The LOAD_TEMPLATE option can be used to provide a reference to a list
  1863. of Template::Provider objects or sub-classes thereof which will take
  1864. responsibility for loading and compiling templates.
  1865.  
  1866.     my $template = Template->new({
  1867.     LOAD_TEMPLATES => [
  1868.             MyOrg::Template::Provider->new({ ... }),
  1869.             Template::Provider->new({ ... }),
  1870.     ],
  1871.     });
  1872.  
  1873. When a PROCESS, INCLUDE or WRAPPER directive is encountered, the named
  1874. template may refer to a locally defined BLOCK or a file relative to
  1875. the INCLUDE_PATH (or an absolute or relative path if the appropriate
  1876. ABSOLUTE or RELATIVE options are set).  If a BLOCK definition can't be
  1877. found (see the Template::Context template() method for a discussion of
  1878. BLOCK locality) then each of the LOAD_TEMPLATES provider objects is
  1879. queried in turn via the fetch() method to see if it can supply the
  1880. required template.  Each provider can return a compiled template, an
  1881. error, or decline to service the request in which case the
  1882. responsibility is passed to the next provider.  If none of the
  1883. providers can service the request then a 'not found' error is
  1884. returned.  The same basic provider mechanism is also used for the 
  1885. INSERT directive but it bypasses any BLOCK definitions and doesn't
  1886. attempt is to parse or process the contents of the template file.
  1887.  
  1888. This is an implementation of the 'Chain of Responsibility'
  1889. design pattern as described in 
  1890. "Design Patterns", Erich Gamma, Richard Helm, Ralph Johnson, John 
  1891. Vlissides), Addision-Wesley, ISBN 0-201-63361-2, page 223
  1892. .
  1893.  
  1894. If LOAD_TEMPLATES is undefined, a single default provider will be
  1895. instantiated using the current configuration parameters.  For example,
  1896. the Template::Provider INCLUDE_PATH option can be specified in the Template configuration and will be correctly passed to the provider's
  1897. constructor method.
  1898.  
  1899.     my $template = Template->new({
  1900.     INCLUDE_PATH => '/here:/there',
  1901.     });
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907. =item LOAD_PLUGINS
  1908.  
  1909. The LOAD_PLUGINS options can be used to specify a list of provider
  1910. objects (i.e. they implement the fetch() method) which are responsible
  1911. for loading and instantiating template plugin objects.  The
  1912. Template::Content plugin() method queries each provider in turn in a
  1913. "Chain of Responsibility" as per the template() and filter() methods.
  1914.  
  1915.     my $template = Template->new({
  1916.     LOAD_PLUGINS => [
  1917.             MyOrg::Template::Plugins->new({ ... }),
  1918.             Template::Plugins->new({ ... }),
  1919.     ],
  1920.     });
  1921.  
  1922. By default, a single Template::Plugins object is created using the 
  1923. current configuration hash.  Configuration items destined for the 
  1924. Template::Plugins constructor may be added to the Template 
  1925. constructor.
  1926.  
  1927.     my $template = Template->new({
  1928.     PLUGIN_BASE => 'MyOrg::Template::Plugins',
  1929.     LOAD_PERL   => 1,
  1930.     });
  1931.  
  1932.  
  1933.  
  1934.  
  1935.  
  1936. =item LOAD_FILTERS
  1937.  
  1938. The LOAD_FILTERS option can be used to specify a list of provider
  1939. objects (i.e. they implement the fetch() method) which are responsible
  1940. for returning and/or creating filter subroutines.  The
  1941. Template::Context filter() method queries each provider in turn in a
  1942. "Chain of Responsibility" as per the template() and plugin() methods.
  1943.  
  1944.     my $template = Template->new({
  1945.     LOAD_FILTERS => [
  1946.             MyTemplate::Filters->new(),
  1947.             Template::Filters->new(),
  1948.     ],
  1949.     });
  1950.  
  1951. By default, a single Template::Filters object is created for the
  1952. LOAD_FILTERS list.
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958. =item TOLERANT
  1959.  
  1960. The TOLERANT flag is used by the various Template Toolkit provider
  1961. modules (Template::Provider, Template::Plugins, Template::Filters) to
  1962. control their behaviour when errors are encountered.  By default, any
  1963. errors are reported as such, with the request for the particular
  1964. resource (template, plugin, filter) being denied and an exception
  1965. raised.  When the TOLERANT flag is set to any true values, errors will
  1966. be silently ignored and the provider will instead return
  1967. STATUS_DECLINED.  This allows a subsequent provider to take
  1968. responsibility for providing the resource, rather than failing the
  1969. request outright.  If all providers decline to service the request,
  1970. either through tolerated failure or a genuine disinclination to
  1971. comply, then a 'E<lt>resourceE<gt> not found' exception is raised.
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978. =item SERVICE
  1979.  
  1980. A reference to a Template::Service object, or sub-class thereof, to which
  1981. the Template module should delegate.  If unspecified, a Template::Service
  1982. object is automatically created using the current configuration hash.
  1983.  
  1984.     my $template = Template->new({
  1985.     SERVICE => MyOrg::Template::Service->new({ ... }),
  1986.     });
  1987.  
  1988.  
  1989.  
  1990.  
  1991.  
  1992. =item CONTEXT
  1993.  
  1994. A reference to a Template::Context object which is used to define a 
  1995. specific environment in which template are processed.  A Template::Context
  1996. object is passed as the only parameter to the Perl subroutines that 
  1997. represent "compiled" template documents.  Template subroutines make 
  1998. callbacks into the context object to access Template Toolkit functionality,
  1999. for example, to to INCLUDE or PROCESS another template (include() and 
  2000. process() methods, respectively), to USE a plugin (plugin()) or 
  2001. instantiate a filter (filter()) or to access the stash (stash()) which 
  2002. manages variable definitions via the get() and set() methods.
  2003.  
  2004.     my $template = Template->new({
  2005.     CONTEXT => MyOrg::Template::Context->new({ ... }),
  2006.     });
  2007.  
  2008.  
  2009.  
  2010. =item STASH
  2011.  
  2012. A reference to a Template::Stash object or sub-class which will take
  2013. responsibility for managing template variables.  
  2014.  
  2015.     my $stash = MyOrg::Template::Stash->new({ ... });
  2016.     my $template = Template->new({
  2017.     STASH => $stash,
  2018.     });
  2019.  
  2020. If unspecified, a default stash object is created using the VARIABLES
  2021. configuration item to initialise the stash variables.  These may also
  2022. be specified as the PRE_DEFINE option for backwards compatibility with 
  2023. version 1.
  2024.  
  2025.     my $template = Template->new({
  2026.     VARIABLES => {
  2027.         id    => 'abw',
  2028.         name  => 'Andy Wardley',
  2029.     },
  2030.     };
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036. =item PARSER
  2037.  
  2038. The Template::Parser module implements a parser object for compiling
  2039. templates into Perl code which can then be executed.  A default object
  2040. of this class is created automatically and then used by the
  2041. Template::Provider whenever a template is loaded and requires 
  2042. compilation.  The PARSER option can be used to provide a reference to 
  2043. an alternate parser object.
  2044.  
  2045.     my $template = Template->new({
  2046.     PARSER => MyOrg::Template::Parser->new({ ... }),
  2047.     });
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053. =item GRAMMAR
  2054.  
  2055. The GRAMMAR configuration item can be used to specify an alternate
  2056. grammar for the parser.  This allows a modified or entirely new
  2057. template language to be constructed and used by the Template Toolkit.
  2058.  
  2059. Source templates are compiled to Perl code by the Template::Parser
  2060. using the Template::Grammar (by default) to define the language
  2061. structure and semantics.  Compiled templates are thus inherently
  2062. "compatible" with each other and there is nothing to prevent any
  2063. number of different template languages being compiled and used within
  2064. the same Template Toolkit processing environment (other than the usual
  2065. time and memory constraints).
  2066.  
  2067. The Template::Grammar file is constructed from a YACC like grammar
  2068. (using Parse::YAPP) and a skeleton module template.  These files are
  2069. provided, along with a small script to rebuild the grammar, in the
  2070. 'parser' sub-directory of the distribution.  You don't have to know or
  2071. worry about these unless you want to hack on the template language or
  2072. define your own variant.  There is a README file in the same directory
  2073. which provides some small guidance but it is assumed that you know
  2074. what you're doing if you venture herein.  If you grok LALR parsers,
  2075. then you should find it comfortably familiar.
  2076.  
  2077. By default, an instance of the default Template::Grammar will be
  2078. created and used automatically if a GRAMMAR item isn't specified.
  2079.  
  2080.     use MyOrg::Template::Grammar;
  2081.  
  2082.     my $template = Template->new({ 
  2083.            GRAMMAR = MyOrg::Template::Grammar->new();
  2084.     });
  2085.  
  2086.  
  2087.  
  2088. =back
  2089.  
  2090. =head1 AUTHOR
  2091.  
  2092. Andy Wardley E<lt>abw@andywardley.comE<gt>
  2093.  
  2094. L<http://www.andywardley.com/|http://www.andywardley.com/>
  2095.  
  2096.  
  2097.  
  2098.  
  2099. =head1 VERSION
  2100.  
  2101. Template Toolkit version 2.13, released on 30 January 2004.
  2102.  
  2103. =head1 COPYRIGHT
  2104.  
  2105.   Copyright (C) 1996-2004 Andy Wardley.  All Rights Reserved.
  2106.   Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
  2107.  
  2108. This module is free software; you can redistribute it and/or
  2109. modify it under the same terms as Perl itself.
  2110.  
  2111.  
  2112.  
  2113. =cut
  2114.  
  2115. # Local Variables:
  2116. # mode: perl
  2117. # perl-indent-level: 4
  2118. # indent-tabs-mode: nil
  2119. # End:
  2120. #
  2121. # vim: expandtab shiftwidth=4:
  2122.