Template::Context - object class representing a runtime context in which templates are rendered.
use Template::Context; $context = Template::Context->new(\%cfg); $error = $context->process($template); # cleanup $context->old(); $context->localise(\%vars); $context->delocalise(); $context->output($text); $context->error($text); $context->redirect($what, $where); $context->throw($type, $info); $context->catch($type, $handler); ($plugin, $error) = $context->use_plugin($name, \@params); ($filter, $error) = $context->use_filter($name, \@params, $alias);
The Template::Context module defines an object which represents a runtime context in which a template is rendered. The context reference is passed down through the processing engine, allowing template directives and user code to generate output, retrieve and update variable values, render other template documents, and so on.
The context defines the variables that exist for the template to access and what values they have (a task delegated to a Template::Stash object). The localise() and delocalise() methods are provided to handle localisation of the stash.
The context also maintains a reference to a cache of previously compiled templates and has the facility to load, parse and compile new template documents as they are requested. These templates can then be accessed from within other templates via the "INCLUDE template_name" directive or may be rendered by a direct call from a template processing engine. The Template::Cache manages the template documents for the context and delegates the parsing of new templates to a Template::Parser object. A cache may be shared among multiple context objects allowing common templates documents to be compile only once and rendered many times in different contexts.
In addition, the context provides facilities for loading plugins and filters.
The context object provides template output and error handling methods which can output/delegate to a user-supplied file handle, text string or sub-routine. These handlers are defined using the redirect() method.
Andy Wardley <cre.canon.co.uk>
$Revision: 1.34 $
Copyright (C) 1996-1999 Andy Wardley. All Rights Reserved. Copyright (C) 1998-1999 Canon Research Centre Europe Ltd.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.