<?php
define("ABS_PATH", $_SERVER['DOCUMENT_ROOT']);
include(ABS_PATH . "/head_nav.php");
include(ABS_PATH . "/middle.php");
?>
          <div class="section">
            <div class="toc-wrapper">
              <span class="toc-title">Contents:</span>
              <ul class="toc">
                  <li class=""><a href="#SYNOPSIS">SYNOPSIS</a></li>
                  <li class=""><a href="#DESCRIPTION">DESCRIPTION</a></li>
                  <li class=""><a href="#METHODS">METHODS</a></li>
                  <li class="sub"><a href="#method_new">new(\%config)</a></li>
                  <li class="sub"><a href="#method_process">process($context)</a></li>
                  <li class="sub"><a href="#method_block">block()</a></li>
                  <li class="sub"><a href="#method_blocks">blocks()</a></li>
                  <li class="sub"><a href="#method_variables">variables()</a></li>
                  <li class="sub"><a href="#section_AUTOLOAD">AUTOLOAD</a></li>
                  <li class=""><a href="#CLASS_METHODS">CLASS METHODS</a></li>
                  <li class="sub"><a href="#method_as_perl">as_perl($content)</a></li>
                  <li class="sub"><a href="#method_write_perl_file">write_perl_file(\%config)</a></li>
                  <li class=""><a href="#INTERNAL_FUNCTIONS">INTERNAL FUNCTIONS</a></li>
                  <li class="sub"><a href="#method_catch_warnings">catch_warnings()</a></li>
                  <li class="sub"><a href="#method_is_utf8">is_utf8()</a></li>
                  <li class=""><a href="#AUTHOR">AUTHOR</a></li>
                  <li class=""><a href="#COPYRIGHT">COPYRIGHT</a></li>
                  <li class=""><a href="#SEE_ALSO">SEE ALSO</a></li>
              </ul>
            </div>
          </div>
          
                <div class="pod">
            <div class="section">
              <div class="head">
                <h1 id="SYNOPSIS">SYNOPSIS</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <pre>use Template::Document;

$doc = Template::Document-&gt;new({
    BLOCK =&gt; sub { # some perl code; return $some_text },
    DEFBLOCKS =&gt; {
        header =&gt; sub { # more perl code; return $some_text },
        footer =&gt; sub { # blah blah blah; return $some_text },
    },
    METADATA =&gt; {
        author  =&gt; 'Andy Wardley',
        version =&gt; 3.14,
    }
}) || die $Template::Document::ERROR;

print $doc-&gt;process($context);</pre>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="DESCRIPTION">DESCRIPTION</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <p>
                      This module defines an object class whose instances represent compiled
                      template documents. The <a href="../../modules/Template/Parser.php">Template::Parser</a> module creates a
                      <code>Template::Document</code> instance to encapsulate a template as it
                      is compiled into Perl code.
                    </p>
                    <p>
                      The constructor method, <a href="#method_new">new()</a>, expects a
                      reference to a hash array containing the <code>BLOCK</code>,
                      <code>DEFBLOCKS</code> and <code>METADATA</code> items.
                    </p>
                    <p>
                      The <code>BLOCK</code> item should contain a reference to a Perl
                      subroutine or a textual representation of Perl code, as generated by the
                      <a href="../../modules/Template/Parser.php">Template::Parser</a>
                      module. This is then evaluated into a subroutine reference using
                      <code>eval()</code>.
                    </p>
                    <p>
                      The <code>DEFLOCKS</code> item should reference a hash array containing
                      further named <code>BLOCK</code>s which may be defined in the template.
                      The keys represent <code>BLOCK</code> names and the values should be
                      subroutine references or text strings of Perl code as per the main
                      <code>BLOCK</code> item.
                    </p>
                    <p>
                      The <code>METADATA</code> item should reference a hash array of metadata
                      items relevant to the document.
                    </p>
                    <p>
                      The <a href="#method_process">process()</a> method can then be called on
                      the instantiated <code>Template::Document</code> object, passing a
                      reference to a <a href="../../modules/Template/Context.php">Template::Context</a> object as the first parameter. This will
                      install any locally defined blocks (<code>DEFBLOCKS</code>) in the
                      <code>BLOCKS</code> cache in the context (via a call to <a href="../../modules/Template/Context.php#method_visit">visit()</a>) so that
                      they may be subsequently resolved by the context. The main
                      <code>BLOCK</code> subroutine is then executed, passing the context
                      reference on as a parameter. The text returned from the template
                      subroutine is then returned by the <a
                      href="#method_process">process()</a> method, after calling the context <a
                      href="../../modules/Template/Context.php#method_leave">leave()</a>
                      method to permit cleanup and de-registration of named <code>BLOCKS</code>
                      previously installed.
                    </p>
                    <p>
                      An <code>AUTOLOAD</code> method provides access to the
                      <code>METADATA</code> items for the document. The <a href="../../modules/Template/Service.php">Template::Service</a> module installs
                      a reference to the main <code>Template::Document</code> object in the
                      stash as the <code>template</code> variable. This allows metadata items
                      to be accessed from within templates, including <code>PRE_PROCESS</code>
                      templates.
                    </p>
                    <p>
                      header:
                    </p>
                    <pre>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;<span class="tt">[% template.title %]</span>
&lt;/head&gt;
...</pre>
                    <p>
                      <code>Template::Document</code> objects are usually created by the <a
                      href="../../modules/Template/Parser.php">Template::Parser</a> but can
                      be manually instantiated or sub-classed to provide custom template
                      components.
                    </p>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="METHODS">METHODS</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <div class="subsection">
                  <div class="head">
                    <h2 id="method_new" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">new(\%config)</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Constructor method which accept a reference to a hash array containing
                          the structure as shown in this example:
                        </p>
                        <pre>$doc = Template::Document-&gt;new({
    BLOCK =&gt; sub { # some perl code; return $some_text },
    DEFBLOCKS =&gt; {
        header =&gt; sub { # more perl code; return $some_text },
        footer =&gt; sub { # blah blah blah; return $some_text },
    },
    METADATA =&gt; {
        author  =&gt; 'Andy Wardley',
        version =&gt; 3.14,
    }
}) || die $Template::Document::ERROR;</pre>
                        <p>
                          <code>BLOCK</code> and <code>DEFBLOCKS</code> items may be expressed as
                          references to Perl subroutines or as text strings containing Perl
                          subroutine definitions, as is generated by the <a href="../../modules/Template/Parser.php">Template::Parser</a> module. These are
                          evaluated into subroutine references using <code>eval()</code>.
                        </p>
                        <p>
                          Returns a new <code>Template::Document</code> object or
                          <code>undef</code> on error. The <a href="../../modules/Template/Base.php#method_error">error()</a> class method can be called, or the
                          <code>$ERROR</code> package variable inspected to retrieve the relevant
                          error message.
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_process" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">process($context)</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Main processing routine for the compiled template document. A reference
                          to a <a href="../../modules/Template/Context.php">Template::Context</a> object should be passed as the first
                          parameter. The method installs any locally defined blocks via a call to
                          the context <a href="../../modules/Template/Context.php#method_visit">visit()</a> method, processes its own template,
                          (passing the context reference as a parameter) and then calls <a
                          href="../../modules/Template/Context.php#method_leave">leave()</a> in
                          the context to allow cleanup.
                        </p>
                        <pre>print $doc-&gt;process($context);</pre>
                        <p>
                          Returns a text string representing the generated output for the template.
                          Errors are thrown via <code>die()</code>.
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_block" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">block()</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Returns a reference to the main <code>BLOCK</code> subroutine.
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_blocks" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">blocks()</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Returns a reference to the hash array of named <code>DEFBLOCKS</code>
                          subroutines.
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_variables" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">variables()</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Returns a reference to a hash of variables used in the template. This
                          requires the <a href="../../manual/Config.php#section_TRACE_VARS">TRACE_VARS</a> option to be enabled.
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="section_AUTOLOAD" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">AUTOLOAD</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          An autoload method returns <code>METADATA</code> items.
                        </p>
                        <pre>print $doc-&gt;author();</pre>
                  </div>
                </div>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="CLASS_METHODS">CLASS METHODS</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <p>
                      These methods are used internally.
                    </p>
                    <div class="subsection">
                  <div class="head">
                    <h2 id="method_as_perl" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">as_perl($content)</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          This method generate a Perl representation of the template.
                        </p>
                        <pre>my $perl = Template::Document-&gt;as_perl({
    BLOCK     =&gt; $main_block,
    DEFBLOCKS =&gt; {
        foo   =&gt; $foo_block,
        bar   =&gt; $bar_block,
    },
    METADATA  =&gt; {
        name  =&gt; 'my_template',
    }
});</pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_write_perl_file" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">write_perl_file(\%config)</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          This method is used to write compiled Perl templates to disk. If the
                          <code>COMPILE_EXT</code> option (to indicate a file extension for saving
                          compiled templates) then the <a href="../../modules/Template/Parser.php">Template::Parser</a> module calls this subroutine before calling the
                          <a href="#method_new">new()</a> constructor. At this stage, the parser
                          has a representation of the template as text strings containing Perl
                          code. We can write that to a file, enclosed in a small wrapper which will
                          allow us to susequently <code>require()</code> the file and have Perl
                          parse and compile it into a <code>Template::Document</code>. Thus we have
                          persistence of compiled templates.
                        </p>
                  </div>
                </div>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="INTERNAL_FUNCTIONS">INTERNAL FUNCTIONS</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <div class="subsection">
                  <div class="head">
                    <h2 id="method_catch_warnings" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">catch_warnings()</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          This is a simple handler used to catch any errors that arise when the
                          compiled Perl template is first evaluated (that is, evaluated by Perl to
                          create a template subroutine at compile, rather than the template being
                          processed at runtime).
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_is_utf8" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">is_utf8()</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          This is mapped to <code>utf8::is_utf8</code> for versions of Perl that
                          have it (&gt; 5.008) or to <code>Encode::is_utf8</code> for Perl 5.008.
                          Earlier versions of Perl are not supported.
                        </p>
                  </div>
                </div>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="AUTHOR">AUTHOR</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <p>
                      Andy Wardley &lt;abw@wardley.org&gt; <a
                      href="https://wardley.org/">https://wardley.org/</a>
                    </p>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="COPYRIGHT">COPYRIGHT</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <p>
                      Copyright (C) 1996-2012 Andy Wardley. All Rights Reserved.
                    </p>
                    <p>
                      This module is free software; you can redistribute it and/or modify it
                      under the same terms as Perl itself.
                    </p>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="SEE_ALSO">SEE ALSO</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <p>
                      <a href="../../modules/Template.php">Template</a>, <a href="../../modules/Template/Parser.php">Template::Parser</a>
                    </p>
              </div>
            </div>
            
            </div>
<?php include(ABS_PATH . "/footer.php"); ?>
