%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/doc/perl-Template-Toolkit-2.24/old/modules/Template/
Upload File :
Create Path :
Current File : //usr/share/doc/perl-Template-Toolkit-2.24/old/modules/Template/Context.html


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
<html>
  <head>
    <title>Template::Context</title>
    <link rel="stylesheet" type="text/css" href="../../css/blue.css" title="Clear Blue">
    <link rel="alternate stylesheet" type="text/css" href="../../css/orange.css" title="Clear Orange">
    <link rel="alternate stylesheet" type="text/css" href="../../css/green.css" title="Clear Green">
    <link rel="alternate stylesheet" type="text/css" href="../../css/purple.css" title="Clear Purple">
    <link rel="alternate stylesheet" type="text/css" href="../../css/grey.css" title="Clear Grey">
    <!--[if IE 6]>
    <link rel="stylesheet" type="text/css" href="../../css/ie6.css" />
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/css/print.css" media="print">
    <script type="text/javascript" src="../../js/tt2.js"></script>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <meta name="author" content="Andy Wardley">
  </head>
  <body id="body"> 
    <div id="layout">
        <div id="header">
          <a href="../../index.html" id="logo" alt="" title="Click for the Home Page"><span class="alt">TT2 Home Page</span></a>
          <ul id="trail">
            <li><a href="../../modules/index.html">Modules</a></li>
            <li><a href="../../modules/Template/index.html">Template::*</a></li>
            <li class="last"><a href="../../modules/Template/Context.html">Context.pm</a></li>
          </ul>
          <div class="controls">
            <a href="#" class="menu show" onclick="widescreen_off(); return false" title="Show Menu">
              <span class="about">Click to view the menu.  It's very nice.</span>
            </a>
            <a href="#" class="menu hide" onclick="widescreen_on();  return false" title="Hide Menu">
              <span class="about">Click to hide the menu and go all widescreen!</span>
            </a>
          
          <div class="pager">
            <a href="../../modules/Template/Constants.html" title="Template::Constants" class="go back">Back<span class="about"><h4>Template::Constants</h4>Defines constants for the Template Toolkit</span></a>
            <a href="../../modules/Template/index.html" title="Template::* Modules" class="go up">Up<span class="about"><h4>Template::* Modules</h4></span></a>
            <a href="../../modules/Template/Directive.html" title="Template::Directive" class="go next">Next<span class="about"><h4>Template::Directive</h4>Perl code generator for template directives</span></a>
          </div>
          </div>
          <h1 class="headline">Template::Context</h1>
          <h2 class="subhead">Runtime context in which templates are processed</h1>
        
        </div>
        <div id="page">
          <div id="sidebar">
            <a href="../../index.html" id="logo"></a>
            <div id="menu">
              <ul class="menu">
                <li class="l0 first"><a href="../../manual/index.html">Manual</a></li>
                <li class="l0"><a href="../../modules/index.html" class="warm">Modules</a></li>
                <li class="l1"><a href="../../modules/Template.html">Template.pm</a></li>
                <li class="l1"><a href="../../modules/Template/index.html" class="warm">Template::*</a></li>
                <li class="l2"><a href="../../modules/Template/Base.html">Base.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Config.html">Config.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Constants.html">Constants.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Context.html" class="warm">Context.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Directive.html">Directive.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Document.html">Document.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Exception.html">Exception.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Filters.html">Filters.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Grammar.html">Grammar.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Iterator.html">Iterator.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Namespace/index.html">Namespace::*</a></li>
                <li class="l2"><a href="../../modules/Template/Parser.html">Parser.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Plugin.html">Plugin.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Plugin/index.html">Plugin::*</a></li>
                <li class="l2"><a href="../../modules/Template/Plugins.html">Plugins.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Provider.html">Provider.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Service.html">Service.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Stash.html">Stash.pm</a></li>
                <li class="l2"><a href="../../modules/Template/Stash/index.html">Stash::*</a></li>
                <li class="l2"><a href="../../modules/Template/Test.html">Test.pm</a></li>
                <li class="l2"><a href="../../modules/Template/VMethods.html">VMethods.pm</a></li>
                <li class="l2"><a href="../../modules/Template/View.html">View.pm</a></li>
                <li class="l0"><a href="../../tools/index.html">Tools</a></li>
                <li class="l0 last"><a href="../../tutorial/index.html">Tutorial</a></li>
              </ul>
              <div class="foot"></div>
            </div>
          </div>
          <div id="content">
          <div class="section">
            <div class="head">
              <h1 id="contents" onclick="switch_section(this)" title="Click title to show/hide section content.">Contents</h1>
              <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
            </div>
            <div class="body">
              <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(\%params) </a></li>
                  <li class="subsub"><a href="#section_VARIABLES">VARIABLES</a></li>
                  <li class="subsub"><a href="#section_BLOCKS">BLOCKS</a></li>
                  <li class="subsub"><a href="#section_TRIM">TRIM</a></li>
                  <li class="subsub"><a href="#section_EVAL_PERL">EVAL_PERL</a></li>
                  <li class="subsub"><a href="#section_RECURSION">RECURSION</a></li>
                  <li class="subsub"><a href="#section_LOAD_TEMPLATES">LOAD_TEMPLATES</a></li>
                  <li class="subsub"><a href="#section_LOAD_PLUGINS">LOAD_PLUGINS</a></li>
                  <li class="subsub"><a href="#section_LOAD_FILTERS">LOAD_FILTERS</a></li>
                  <li class="subsub"><a href="#section_STASH">STASH</a></li>
                  <li class="subsub"><a href="#section_DEBUG">DEBUG</a></li>
                  <li class="sub"><a href="#method_template">template($name) </a></li>
                  <li class="sub"><a href="#method_plugin">plugin($name, \@args)</a></li>
                  <li class="sub"><a href="#method_filter">filter($name, \@args, $alias)</a></li>
                  <li class="sub"><a href="#method_process">process($template, \%vars)</a></li>
                  <li class="sub"><a href="#method_include">include($template, \%vars)</a></li>
                  <li class="sub"><a href="#method_throw">throw($error_type, $error_message, \$output)</a></li>
                  <li class="sub"><a href="#method_catch">catch($exception, \$output)</a></li>
                  <li class="sub"><a href="#method_define_block">define_block($name, $block)</a></li>
                  <li class="sub"><a href="#method_define_filter">define_filter($name, \&amp;filter, $is_dynamic)</a></li>
                  <li class="sub"><a href="#method_localise">localise(\%vars)</a></li>
                  <li class="sub"><a href="#method_delocalise">delocalise()</a></li>
                  <li class="sub"><a href="#method_visit">visit(\%blocks)</a></li>
                  <li class="sub"><a href="#method_leave">leave()</a></li>
                  <li class="sub"><a href="#method_reset">reset()</a></li>
                  <li class="sub"><a href="#section_AUTOLOAD">AUTOLOAD</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" onclick="switch_section(this)" title="Click title to show/hide section content.">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::Context;

# constructor
$context = Template::Context-&gt;new(\%config)
    || die $Template::Context::ERROR;

# fetch (load and compile) a template
$template = $context-&gt;template($template_name);

# fetch (load and instantiate) a plugin object
$plugin = $context-&gt;plugin($name, \@args);

# fetch (return or create) a filter subroutine
$filter = $context-&gt;filter($name, \@args, $alias);

# process/include a template, errors are thrown via die()
$output = $context-&gt;process($template, \%vars);
$output = $context-&gt;include($template, \%vars);

# raise an exception via die()
$context-&gt;throw($error_type, $error_message, \$output_buffer);

# catch an exception, clean it up and fix output buffer
$exception = $context-&gt;catch($exception, \$output_buffer);

# save/restore the stash to effect variable localisation
$new_stash = $context-&gt;localise(\%vars);
$old_stash = $context-&gt;delocalise();

# add new BLOCK or FILTER definitions
$context-&gt;define_block($name, $block);
$context-&gt;define_filter($name, \&amp;filtersub, $is_dynamic);

# reset context, clearing any imported BLOCK definitions
$context-&gt;reset();

# methods for accessing internal items
$stash     = $context-&gt;stash();
$tflag     = $context-&gt;trim();
$epflag    = $context-&gt;eval_perl();
$providers = $context-&gt;templates();
$providers = $context-&gt;plugins();
$providers = $context-&gt;filters();
...</pre>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="DESCRIPTION" onclick="switch_section(this)" title="Click title to show/hide section content.">DESCRIPTION</h1>
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
              </div>
              <div class="body">
                <p>
                      The <code>Template::Context</code> module defines an object class for
                      representing a runtime context in which templates are processed. It
                      provides an interface to the fundamental operations of the Template
                      Toolkit processing engine through which compiled templates (i.e. Perl
                      code constructed from the template source) can process templates, load
                      plugins and filters, raise exceptions and so on.
                    </p>
                    <p>
                      A default <code>Template::Context</code> object is created by the <a
                      href="../../modules/Template.html">Template</a> module. Any
                      <code>Template::Context</code> options may be passed to the <a href="../../modules/Template.html">Template</a> <a href="../../modules/Template.html#method_new">new()</a> constructor method and
                      will be forwarded to the <code>Template::Context</code> constructor.
                    </p>
                    <pre>use Template;

my $template = Template-&gt;new({
    TRIM      =&gt; 1,
    EVAL_PERL =&gt; 1,
    BLOCKS    =&gt; {
        header =&gt; 'This is the header',
        footer =&gt; 'This is the footer',
    },
});</pre>
                    <p>
                      Similarly, the <code>Template::Context</code> constructor will forward
                      all configuration parameters onto other default objects (e.g. <a
                      href="../../modules/Template/Provider.html">Template::Provider</a>, <a
                      href="../../modules/Template/Plugins.html">Template::Plugins</a>, <a
                      href="../../modules/Template/Filters.html">Template::Filters</a>,
                      etc.) that it may need to instantiate.
                    </p>
                    <pre>$context = Template::Context-&gt;new({
    INCLUDE_PATH =&gt; '/home/abw/templates', # provider option
    TAG_STYLE    =&gt; 'html',                # parser option
});</pre>
                    <p>
                      A <code>Template::Context</code> object (or subclass) can be explicitly
                      instantiated and passed to the <a href="../../modules/Template.html">Template</a> <a href="../../modules/Template.html#method_new">new()</a> constructor method as the <code>CONTEXT</code>
                      configuration item.
                    </p>
                    <pre>use Template;
use Template::Context;

my $context  = Template::Context-&gt;new({ TRIM =&gt; 1 });
my $template = Template-&gt;new({ CONTEXT =&gt; $context });</pre>
                    <p>
                      The <a href="../../modules/Template.html">Template</a> module uses the
                      <a href="../../modules/Template/Config.html">Template::Config</a> <a
                      href="../../modules/Template/Config.html#method_context">context()</a>
                      factory method to create a default context object when required. The
                      <code>$Template::Config::CONTEXT</code> package variable may be set to
                      specify an alternate context module. This will be loaded automatically
                      and its <a href="#method_new">new()</a> constructor method called by the
                      <a href="../../modules/Template/Config.html#method_context">context()</a> factory method when a default context
                      object is required.
                    </p>
                    <pre>use Template;

$Template::Config::CONTEXT = 'MyOrg::Template::Context';

my $template = Template-&gt;new({
    EVAL_PERL   =&gt; 1,
    EXTRA_MAGIC =&gt; 'red hot',  # your extra config items
    ...
});</pre>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="METHODS" onclick="switch_section(this)" title="Click title to show/hide section content.">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(\%params) </h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          The <code>new()</code> constructor method is called to instantiate a
                          <code>Template::Context</code> object. Configuration parameters may be
                          specified as a HASH reference or as a list of <code>name =&gt;
                          value</code> pairs.
                        </p>
                        <pre>my $context = Template::Context-&gt;new({
    INCLUDE_PATH =&gt; 'header',
    POST_PROCESS =&gt; 'footer',
});

my $context = Template::Context-&gt;new( EVAL_PERL =&gt; 1 );</pre>
                        <p>
                          The <code>new()</code> method returns a <code>Template::Context</code>
                          object or <code>undef</code> on error. In the latter case, a relevant
                          error message can be retrieved by the <a href="../../modules/Template/Base.html#method_error">error()</a> class method or
                          directly from the <code>$Template::Context::ERROR</code> package
                          variable.
                        </p>
                        <pre>my $context = Template::Context-&gt;new(\%config)
    || die Template::Context-&gt;error();

my $context = Template::Context-&gt;new(\%config)
    || die $Template::Context::ERROR;</pre>
                        <p>
                          The following configuration items may be specified. Please see <a
                          href="../../manual/Config.html">Template::Manual::Config</a> for further details.
                        </p>
                        <h3 class="method" id="section_VARIABLES">VARIABLES</h3>
                        <p>
                          The <a href="../../manual/Config.html#section_VARIABLES">VARIABLES</a> option can be used to specify a hash
                          array of template variables.
                        </p>
                        <pre>my $context = Template::Context-&gt;new({
    VARIABLES =&gt; {
        title   =&gt; 'A Demo Page',
        author  =&gt; 'Joe Random Hacker',
        version =&gt; 3.14,
    },
};</pre>
                        
                        <h3 class="method" id="section_BLOCKS">BLOCKS</h3>
                        <p>
                          The <a href="../../manual/Config.html#section_BLOCKS">BLOCKS</a> option can be used to pre-define a default
                          set of template blocks.
                        </p>
                        <pre>my $context = Template::Context-&gt;new({
    BLOCKS =&gt; {
        header  =&gt; 'The Header.  [% title %]',
        footer  =&gt; sub { return $some_output_text },
        another =&gt; Template::Document-&gt;new({ ... }),
    },
}); </pre>
                        
                        <h3 class="method" id="section_TRIM">TRIM</h3>
                        <p>
                          The <a href="../../manual/Config.html#section_TRIM">TRIM</a> option can be set to have any leading and
                          trailing whitespace automatically removed from the output of all template
                          files and <code>BLOCK</code>s.
                        </p>
                        <p>
                          example:
                        </p>
                        <pre>[% BLOCK foo %]

Line 1 of foo

[% END %]

before 
[% INCLUDE foo %]
after</pre>
                        <p>
                          output:
                        </p>
                        <pre>before
Line 1 of foo
after</pre>
                        
                        <h3 class="method" id="section_EVAL_PERL">EVAL_PERL</h3>
                        <p>
                          The <a href="../../manual/Config.html#section_EVAL_PERL">EVAL_PERL</a> is used to indicate if
                          <code>PERL</code> and/or <code>RAWPERL</code> blocks should be evaluated.
                          It is disabled by default.
                        </p>
                        
                        <h3 class="method" id="section_RECURSION">RECURSION</h3>
                        <p>
                          The <a href="../../manual/Config.html#section_RECURSION">RECURSION</a> can be set to allow templates to
                          recursively process themselves, either directly (e.g. template
                          <code>foo</code> calls <code>INCLUDE foo</code>) or indirectly (e.g.
                          <code>foo</code> calls <code>INCLUDE bar</code> which calls <code>INCLUDE
                          foo</code>).
                        </p>
                        
                        <h3 class="method" id="section_LOAD_TEMPLATES">LOAD_TEMPLATES</h3>
                        <p>
                          The <a href="../../manual/Config.html#section_LOAD_TEMPLATES">LOAD_TEMPLATES</a> option can be used to
                          provide a reference to a list of <a href="../../modules/Template/Provider.html">Template::Provider</a> objects or
                          sub-classes thereof which will take responsibility for loading and
                          compiling templates.
                        </p>
                        <pre>my $context = Template::Context-&gt;new({
    LOAD_TEMPLATES =&gt; [
        MyOrg::Template::Provider-&gt;new({ ... }),
        Template::Provider-&gt;new({ ... }),
    ],
});</pre>
                        
                        <h3 class="method" id="section_LOAD_PLUGINS">LOAD_PLUGINS</h3>
                        <p>
                          The <a href="../../manual/Config.html#section_LOAD_PLUGINS">LOAD_PLUGINS</a> options can be used to specify
                          a list of provider objects responsible for loading and instantiating
                          template plugin objects.
                        </p>
                        <pre>my $context = Template::Context-&gt;new({
    LOAD_PLUGINS =&gt; [
        MyOrg::Template::Plugins-&gt;new({ ... }),
        Template::Plugins-&gt;new({ ... }),
    ],
});</pre>
                        
                        <h3 class="method" id="section_LOAD_FILTERS">LOAD_FILTERS</h3>
                        <p>
                          The <a href="../../manual/Config.html#section_LOAD_FILTERS">LOAD_FILTERS</a> option can be used to specify
                          a list of provider objects for returning and/or creating filter
                          subroutines.
                        </p>
                        <pre>my $context = Template::Context-&gt;new({
    LOAD_FILTERS =&gt; [
        MyTemplate::Filters-&gt;new(),
        Template::Filters-&gt;new(),
    ],
});</pre>
                        
                        <h3 class="method" id="section_STASH">STASH</h3>
                        <p>
                          The <a href="../../manual/Config.html#section_STASH">STASH</a> option can be used to specify a <a href="../../modules/Template/Stash.html">Template::Stash</a> object or sub-class
                          which will take responsibility for managing template variables.
                        </p>
                        <pre>my $stash = MyOrg::Template::Stash-&gt;new({ ... });
my $context = Template::Context-&gt;new({
    STASH =&gt; $stash,
});</pre>
                        
                        <h3 class="method" id="section_DEBUG">DEBUG</h3>
                        <p>
                          The <a href="../../manual/Config.html#section_DEBUG">DEBUG</a> option can be used to enable various
                          debugging features of the <a href="../../modules/Template/Context.html">Template::Context</a> module.
                        </p>
                        <pre>use Template::Constants qw( :debug );

my $template = Template-&gt;new({
    DEBUG =&gt; DEBUG_CONTEXT | DEBUG_DIRS,
});</pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_template" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">template($name) </h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Returns a compiled template by querying each of the <a
                          href="#section_LOAD_TEMPLATES">LOAD_TEMPLATES</a> providers (instances of
                          <a href="../../modules/Template/Provider.html">Template::Provider</a>,
                          or sub-class) in turn.
                        </p>
                        <pre>$template = $context-&gt;template('header');</pre>
                        <p>
                          On error, a <a href="../../modules/Template/Exception.html">Template::Exception</a> object of type '<code>file</code>' is thrown
                          via <code>die()</code>. This can be caught by enclosing the call to
                          <code>template()</code> in an <code>eval</code> block and examining
                          <code>$@</code>.
                        </p>
                        <pre>eval { $template = $context-&gt;template('header') };
if ($@) {
    print "failed to fetch template: $@\n";
}</pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_plugin" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">plugin($name, \@args)</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Instantiates a plugin object by querying each of the <a
                          href="#section_LOAD_PLUGINS">LOAD_PLUGINS</a> providers. The default <a
                          href="#section_LOAD_PLUGINS">LOAD_PLUGINS</a> provider is a <a href="../../modules/Template/Plugins.html">Template::Plugins</a> object which
                          attempts to load plugin modules, according the various configuration
                          items such as <a href="../../modules/Template/Plugins.html#section_PLUGIN_BASE">PLUGIN_BASE</a>, <a href="../../modules/Template/Plugins.html#section_LOAD_PERL">LOAD_PERL</a>,
                          etc., and then instantiate an object via <a href="../../modules/Template/Plugin.html#method_new">new()</a>. A reference to a
                          list of constructor arguments may be passed as the second parameter.
                          These are forwarded to the plugin constructor.
                        </p>
                        <p>
                          Returns a reference to a plugin (which is generally an object, but
                          doesn't have to be). Errors are thrown as <a href="../../modules/Template/Exception.html">Template::Exception</a> objects
                          with the type set to '<code>plugin</code>'.
                        </p>
                        <pre>$plugin = $context-&gt;plugin('DBI', 'dbi:msql:mydbname');</pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_filter" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">filter($name, \@args, $alias)</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Instantiates a filter subroutine by querying the <a
                          href="#section_LOAD_FILTERS">LOAD_FILTERS</a> providers. The default <a
                          href="#section_LOAD_FILTERS">LOAD_FILTERS</a> provider is a <a href="../../modules/Template/Filters.html">Template::Filters</a> object.
                        </p>
                        <p>
                          Additional arguments may be passed by list reference along with an
                          optional alias under which the filter will be cached for subsequent use.
                          The filter is cached under its own <code>$name</code> if
                          <code>$alias</code> is undefined. Subsequent calls to
                          <code>filter($name)</code> will return the cached entry, if defined.
                          Specifying arguments bypasses the caching mechanism and always creates a
                          new filter. Errors are thrown as <a href="../../modules/Template/Exception.html">Template::Exception</a> objects
                          with the type set to '<code>filter</code>'.
                        </p>
                        <pre># static filter (no args)
$filter = $context-&gt;filter('html');

# dynamic filter (args) aliased to 'padright'
$filter = $context-&gt;filter('format', '%60s', 'padright');

# retrieve previous filter via 'padright' alias
$filter = $context-&gt;filter('padright');</pre>
                  </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($template, \%vars)</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Processes a template named or referenced by the first parameter and
                          returns the output generated. An optional reference to a hash array may
                          be passed as the second parameter, containing variable definitions which
                          will be set before the template is processed. The template is processed
                          in the current context, with no localisation of variables performed.
                          Errors are thrown as <a href="../../modules/Template/Exception.html">Template::Exception</a> objects via <code>die()</code>.
                        </p>
                        <pre>$output = $context-&gt;process('header', { title =&gt; 'Hello World' });</pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_include" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">include($template, \%vars)</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Similar to <a href="#method_process">process()</a>, but using localised
                          variables. Changes made to any variables will only persist until the
                          <code>include()</code> method completes.
                        </p>
                        <pre>$output = $context-&gt;include('header', { title =&gt; 'Hello World' });</pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_throw" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">throw($error_type, $error_message, \$output)</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Raises an exception in the form of a <a href="../../modules/Template/Exception.html">Template::Exception</a> object by
                          calling <code>die()</code>. This method may be passed a reference to an
                          existing <a href="../../modules/Template/Exception.html">Template::Exception</a> object; a single value containing an error
                          message which is used to instantiate a <a href="../../modules/Template/Exception.html">Template::Exception</a> of type
                          '<code>undef</code>'; or a pair of values representing the exception
                          <code>type</code> and <code>info</code> from which a <a href="../../modules/Template/Exception.html">Template::Exception</a> object is
                          instantiated. e.g.
                        </p>
                        <pre>$context-&gt;throw($exception);
$context-&gt;throw("I'm sorry Dave, I can't do that");
$context-&gt;throw('denied', "I'm sorry Dave, I can't do that");</pre>
                        <p>
                          The optional third parameter may be a reference to the current output
                          buffer. This is then stored in the exception object when created,
                          allowing the catcher to examine and use the output up to the point at
                          which the exception was raised.
                        </p>
                        <pre>$output .= 'blah blah blah';
$output .= 'more rhubarb';
$context-&gt;throw('yack', 'Too much yacking', \$output);</pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_catch" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">catch($exception, \$output)</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Catches an exception thrown, either as a reference to a <a href="../../modules/Template/Exception.html">Template::Exception</a> object or
                          some other value. In the latter case, the error string is promoted to a
                          <a href="../../modules/Template/Exception.html">Template::Exception</a> object of '<code>undef</code>' type. This
                          method also accepts a reference to the current output buffer which is
                          passed to the <a href="../../modules/Template/Exception.html">Template::Exception</a> constructor, or is appended to the output
                          buffer stored in an existing <a href="../../modules/Template/Exception.html">Template::Exception</a> object, if
                          unique (i.e. not the same reference). By this process, the correct state
                          of the output buffer can be reconstructed for simple or nested throws.
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_define_block" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">define_block($name, $block)</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Adds a new block definition to the internal <a
                          href="#section_BLOCKS">BLOCKS</a> cache. The first argument should
                          contain the name of the block and the second a reference to a <a
                          href="../../modules/Template/Document.html">Template::Document</a>
                          object or template sub-routine, or template text which is automatically
                          compiled into a template sub-routine.
                        </p>
                        <p>
                          Returns a true value (the sub-routine or <a href="../../modules/Template/Document.html">Template::Document</a> reference) on
                          success or undef on failure. The relevant error message can be retrieved
                          by calling the <a href="../../modules/Template/Base.html#method_error">error()</a> method.
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_define_filter" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">define_filter($name, \&amp;filter, $is_dynamic)</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Adds a new filter definition by calling the <a href="../../modules/Template/Filters.html#method_store">store()</a> method on
                          each of the <a href="#section_LOAD_FILTERS">LOAD_FILTERS</a> providers
                          until accepted (in the usual case, this is accepted straight away by the
                          one and only <a href="../../modules/Template/Filters.html">Template::Filters</a> provider). The first argument should contain
                          the name of the filter and the second a reference to a filter subroutine.
                          The optional third argument can be set to any true value to indicate that
                          the subroutine is a dynamic filter factory.
                        </p>
                        <p>
                          Returns a true value or throws a '<code>filter</code>' exception on
                          error.
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_localise" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">localise(\%vars)</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Clones the stash to create a context with localised variables. Returns a
                          reference to the newly cloned stash object which is also stored
                          internally.
                        </p>
                        <pre>$stash = $context-&gt;localise();</pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_delocalise" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">delocalise()</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Restore the stash to its state prior to localisation.
                        </p>
                        <pre>$stash = $context-&gt;delocalise();</pre>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_visit" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">visit(\%blocks)</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 called by <a href="../../modules/Template/Document.html">Template::Document</a> objects immediately before they process their
                          content. It is called to register any local <code>BLOCK</code>
                          definitions with the context object so that they may be subsequently
                          delivered on request.
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_leave" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">leave()</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Compliment to the <a href="#method_visit">visit()</a> method. Called by
                          <a href="../../modules/Template/Document.html">Template::Document</a>
                          objects immediately after they process their content.
                        </p>
                  </div>
                </div>    <div class="subsection">
                  <div class="head">
                    <h2 id="method_reset" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">reset()</h2>
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
                  </div>
                  <div class="body">
                    <p>
                          Clears the local <a href="#section_BLOCKS">BLOCKS</a> cache of any
                          <code>BLOCK</code> definitions. Any initial set of <a
                          href="#section_BLOCKS">BLOCKS</a> specified as a configuration item to
                          the constructor will be reinstated.
                        </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 <code>AUTOLOAD</code> method provides access to context configuration
                          items.
                        </p>
                        <pre>$stash     = $context-&gt;stash();
$tflag     = $context-&gt;trim();
$epflag    = $context-&gt;eval_perl();
...</pre>
                  </div>
                </div>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="AUTHOR" onclick="switch_section(this)" title="Click title to show/hide section content.">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="http://wardley.org/">http://wardley.org/</a>
                    </p>
              </div>
            </div>
            <div class="section">
              <div class="head">
                <h1 id="COPYRIGHT" onclick="switch_section(this)" title="Click title to show/hide section content.">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-2007 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" onclick="switch_section(this)" title="Click title to show/hide section content.">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.html">Template</a>, <a href="../../modules/Template/Document.html">Template::Document</a>, <a href="../../modules/Template/Exception.html">Template::Exception</a>, <a
                      href="../../modules/Template/Filters.html">Template::Filters</a>, <a
                      href="../../modules/Template/Plugins.html">Template::Plugins</a>, <a
                      href="../../modules/Template/Provider.html">Template::Provider</a>, <a
                      href="../../modules/Template/Service.html">Template::Service</a>, <a
                      href="../../modules/Template/Stash.html">Template::Stash</a>
                    </p>
              </div>
            </div>
            
            </div></div>
          <br class="clear" />
          <div class="pageinfo">
            /modules/Template/Context.html last modified 10:57:46 31-May-2007
          </div>
        </div>
        
        <div id="footer">
          <a href="http://opensource.org/" class="osi"></a>
          <div class="controls">
          <div class="pager">
            <a href="../../modules/Template/Constants.html" title="Template::Constants" class="go back">Back<span class="about"><h4>Template::Constants</h4></span></a>
            <a href="../../modules/Template/index.html" title="Template::* Modules" class="go up">Up<span class="about"><h4>Template::* Modules</h4></span></a>
            <a href="../../modules/Template/Directive.html" title="Template::Directive" class="go next">Next<span class="about"><h4>Template::Directive</h4></span></a>
          </div>
          </div>
          <div class="copyright">
            Copyright &copy; 1996-2007 <a href="http://wardley.org/">Andy Wardley</a>.  All Rights Reserved.
          </div>
          <div class="licence">
            The <a href="http://template-toolkit.org/">Template Toolkit</a> is <a href="http://opensource.org/">Open Source</a> software.
            You can redistribute and/or modify it under the terms of the <a href="http://www.opensource.org/licenses/gpl-license.php">GNU Public Licence</a>
            or the <a href="http://www.opensource.org/licenses/artistic-license.php">Perl Artistic Licence</a>.
          </div>
        </div>
        <div id="palette">
          <ul>
            <li class="first"><a href="#" class="blue" onclick="set_style('Clear Blue')"></a></li>
            <li><a href="#" class="orange" onclick="set_style('Clear Orange')"></a></li>
            <li><a href="#" class="green" onclick="set_style('Clear Green')"></a></li>
            <li><a href="#" class="purple" onclick="set_style('Clear Purple')"></a></li>
            <li><a href="#" class="grey" onclick="set_style('Clear Grey')"></a></li>
          </ul>
        </div>
    </div>  </body>
</html>

Zerion Mini Shell 1.0