Shell File Manager
<!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">
<link rel="alternate stylesheet" type="text/css" href="../../css/print.css" title="Print">
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="../../css/ie6.css" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="../../css/ie7.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"><a href="../../tutorial/index.html">Tutorial</a></li>
<li class="l0 last"><a href="../../faq/index.html">FAQ</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_VIEWS">VIEWS</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_insert">insert($template)</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, \&filter, $is_dynamic)</a></li>
<li class="sub"><a href="#method_define_vmethod">define_vmethod($type, $name, $code)</a></li>
<li class="sub"><a href="#method_define_view">define_view($name, \%params)</a></li>
<li class="sub"><a href="#method_define_views">define_views($views)</a></li>
<li class="sub"><a href="#method_stash">stash()</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_view">view()</a></li>
<li class="sub"><a href="#method_reset">reset()</a></li>
<li class="sub"><a href="#method_debugging">debugging($flag, @args)</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->new(\%config)
|| die $Template::Context::ERROR;
# fetch (load and compile) a template
$template = $context->template($template_name);
# fetch (load and instantiate) a plugin object
$plugin = $context->plugin($name, \@args);
# fetch (return or create) a filter subroutine
$filter = $context->filter($name, \@args, $alias);
# process/include a template, errors are thrown via die()
$output = $context->process($template, \%vars);
$output = $context->include($template, \%vars);
# raise an exception via die()
$context->throw($error_type, $error_message, \$output_buffer);
# catch an exception, clean it up and fix output buffer
$exception = $context->catch($exception, \$output_buffer);
# save/restore the stash to effect variable localisation
$new_stash = $context->localise(\%vars);
$old_stash = $context->delocalise();
# add new BLOCK or FILTER definitions
$context->define_block($name, $block);
$context->define_filter($name, \&filtersub, $is_dynamic);
# reset context, clearing any imported BLOCK definitions
$context->reset();
# methods for accessing internal items
$stash = $context->stash();
$tflag = $context->trim();
$epflag = $context->eval_perl();
$providers = $context->templates();
$providers = $context->plugins();
$providers = $context->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->new({
TRIM => 1,
EVAL_PERL => 1,
BLOCKS => {
header => 'This is the header',
footer => '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->new({
INCLUDE_PATH => '/home/abw/templates', # provider option
TAG_STYLE => '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->new({ TRIM => 1 });
my $template = Template->new({ CONTEXT => $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->new({
EVAL_PERL => 1,
EXTRA_MAGIC => '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 =>
value</code> pairs.
</p>
<pre>my $context = Template::Context->new({
INCLUDE_PATH => 'header',
POST_PROCESS => 'footer',
});
my $context = Template::Context->new( EVAL_PERL => 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->new(\%config)
|| die Template::Context->error();
my $context = Template::Context->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->new({
VARIABLES => {
title => 'A Demo Page',
author => 'Joe Random Hacker',
version => 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->new({
BLOCKS => {
header => 'The Header. <span class="tt">[% title %]</span>',
footer => sub { return $some_output_text },
another => Template::Document->new({ ... }),
},
});</pre>
<h3 class="method" id="section_VIEWS">VIEWS</h3>
<p>
The <a href="../../manual/Config.html#section_VIEWS">VIEWS</a> option can be used to pre-define one or more
<a href="../../modules/Template/View.html">Template::View</a> objects.
</p>
<pre>my $context = Template::Context->new({
VIEWS => [
bottom => { prefix => 'bottom/' },
middle => { prefix => 'middle/', base => 'bottom' },
top => { prefix => 'top/', base => 'middle' },
],
});</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><span class="tt">[% BLOCK foo %]</span>
Line 1 of foo
<span class="tt">[% END %]</span>
before
<span class="tt">[% INCLUDE foo %]</span>
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->new({
LOAD_TEMPLATES => [
MyOrg::Template::Provider->new({ ... }),
Template::Provider->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->new({
LOAD_PLUGINS => [
MyOrg::Template::Plugins->new({ ... }),
Template::Plugins->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->new({
LOAD_FILTERS => [
MyTemplate::Filters->new(),
Template::Filters->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->new({ ... });
my $context = Template::Context->new({
STASH => $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->new({
DEBUG => 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->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->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->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->filter('html');
# dynamic filter (args) aliased to 'padright'
$filter = $context->filter('format', '%60s', 'padright');
# retrieve previous filter via 'padright' alias
$filter = $context->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->process('header', { title => '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->include('header', { title => 'Hello World' });</pre>
</div>
</div> <div class="subsection">
<div class="head">
<h2 id="method_insert" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">insert($template)</h2>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
This method returns the source content of a template file without
performing any evaluation. It is used to implement the
<code>INSERT</code> directive.
</p>
</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->throw($exception);
$context->throw("I'm sorry Dave, I can't do that");
$context->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->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, \&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_define_vmethod" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">define_vmethod($type, $name, $code)</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 a wrapper around the <a href="../../modules/Template/Stash.html">Template::Stash</a> <a href="../../modules/Template/Stash.html#method_define_vmethod">define_vmethod()</a> method. It can be used to
define new virtual methods.
</p>
<pre># define a new scalar (item) virtual method
$context->define_vmethod(
item => ucfirst => sub {
my $text = shift;
return ucfirst $text;
}
)</pre>
</div>
</div> <div class="subsection">
<div class="head">
<h2 id="method_define_view" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">define_view($name, \%params)</h2>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
This method allows you to define a named <a href="../../modules/Template/View.html">view</a>.
</p>
<pre>$context->define_view(
my_view => {
prefix => 'my_templates/'
}
);</pre>
<p>
The view is then accessible as a template variable.
</p>
<pre><span class="tt">[% my_view.print(some_data) %]</span></pre>
</div>
</div> <div class="subsection">
<div class="head">
<h2 id="method_define_views" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">define_views($views)</h2>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
This method allows you to define multiple named <a href="../../modules/Template/View.html">views</a>. A reference to a hash array
or list reference should be passed as an argument.
</p>
<pre>$context->define_view({ # hash reference
my_view_one => {
prefix => 'my_templates_one/'
},
my_view_two => {
prefix => 'my_templates_two/'
}
});</pre>
<p>
If you're defining multiple views of which one or more are based on other
views in the same definition then you should pass them as a list
reference. This ensures that they get created in the right order (Perl
does not preserve the order of items defined in a hash reference so you
can't guarantee that your base class view will be defined before your
subclass view).
</p>
<pre>$context->define_view([ # list referenence
my_view_one => {
prefix => 'my_templates_one/'
},
my_view_two => {
prefix => 'my_templates_two/' ,
base => 'my_view_one',
}
]);</pre>
<p>
The views are then accessible as template variables.
</p>
<pre><span class="tt">[% my_view_one.print(some_data) %]</span>
<span class="tt">[% my_view_two.print(some_data) %]</span></pre>
<p>
See also the <a href="#section_VIEWS">VIEWS</a> option.
</p>
</div>
</div> <div class="subsection">
<div class="head">
<h2 id="method_stash" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">stash()</h2>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
This method returns the <a href="../../modules/Template/Stash.html">Template::Stash</a> object used internally to manage template
variables.
</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->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->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_view" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">view()</h2>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
This method creates a <a href="../../modules/Template/View.html">Template::View</a> object bound to the context.
</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="method_debugging" class="method" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">debugging($flag, @args)</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 control debugging output. It is used to implement
the <a href="../../manual/Directives.html#section_DEBUG">DEBUG</a> directive.
</p>
<p>
The first argument can be <code>on</code> or <code>off</code> to enable
or disable debugging respectively. The numerical values <code>0</code>
and <code>1</code> can also be used if you prefer.
</p>
<pre>$context->debugging('on');</pre>
<p>
Alternately, the first argument can be <code>format</code> to define a
new debug message format. The second argument should be the format string
which can contain any of the <code>$file</code>, <code>$line</code> or
<code>$text</code> symbols to indicate where the relevant values should
be inserted.
</p>
<pre># note single quotes to prevent interpolated of variables
$context->debugging( format => '## $file line $line: $text' );</pre>
<p>
The final use of this method is to generate debugging messages
themselves. The first argument should be <code>msg</code>, followed by a
reference to a hash array of value to insert into the debugging format
string.
</p>
<pre>$context->debugging(
msg => {
line => 20,
file => 'example.tt',
text => 'Trampoline! Trampoline!',
}
);</pre>
</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->stash();
$tflag = $context->trim();
$epflag = $context->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 <[email protected]> <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-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" 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">
<a href="http://template-toolkit.org/docs/modules/Template/Context.html">http://template-toolkit.org/docs/modules/Template/Context.html</a>
</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 © 1996-2012 <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>
Shell File Manager Version 1.1, Coded By Shell
Email: [email protected]