NAME

Top Close Open

Template::TT3::Template - object representing a template

PARSING METHODS

Top Close Open

tree()

Top Close Open

Returns a Template::TT3::Type::Tree object representing the element tree of the parsed template. This is a thin wrapper around the block element returned by the block() method. The tree is cached internally

block()

Top Close Open

Returns a Template::TT3::Element::Block object representing the main block of a parsed template. This is generated by calling the parse() method. The block is cached internally once parsed.

parse()

Top Close Open

This method parses the tokens returned by the tokens() method and returns a Template::TT3::Element::Block object representing the template expressions.

tokens()

Top Close Open

This returns a Template::TT3::Tokens object representing the list of tokens scanned from the template source. The tokens are generated by the scan() method and cached internally.

scan()

Top Close Open

ERROR HANDLING METHODS

Top Close Open

catch($handler, $method, @args)

Top Close Open

This method can be used to call another method with a try...catch wrapper around it. Any errors caught are forwarded to the $handler method.

The tree() , block() , scan() and various other public methods are implemented as thin wrappers around internal _tree() , _block() , _scan() , etc., methods. They use the catch() method something like this:

sub tree {
    my $self = shift;
    return $self->catch( decorate_error => _tree => @_ );
}

This calls the _tree() method, passing all the arguments @_ that were passed to the tree() method. If an error is thrown then the decorate_error() method is called.

decorate_error($exception)

Top Close Open

This method is called (typically by the catch() method) to decorate an exception object passed to it. It adds the template name to the exception and, if the error has a element token attached to, an extract of the template source where the error occurred. This allows the exception object to report a more useful error message.

INTERNAL METHODS

Top Close Open

The following methods are the internal implementations of their corresponding public methods (of the same name, but without the leading underscore). The public methods are wrappers around these internal methods that add some extra functionality for the purpose of better error reporting.

There's nothing to stop you from calling these methods directly but if you do then you won't get the template name and source extract added to the error message. If you're writing an internal method that will end up being wrapped in its own public method then you can and should call these methods directly. Otherwise you'll be invoking the catch handler twice (or more) for each error thrown.

_tree()

Top Close Open

_block()

Top Close Open

_parse()

Top Close Open

_tokens()

Top Close Open

_scan()

Top Close Open

1;


http://tt3.template-toolkit.org/docs/Template/TT3/Template.pm last modified 2009-12-22 11:01:10