NAME

Top Close Open

Template::TT3::Exceptions - factory module for loading and creating exceptions

SYNOPSIS

Top Close Open
use Template::TT3::Exceptions;

my $factory = Template::TT3::Exceptions->new;
my $error   = $factory->item( syntax => @args );

DESCRIPTION

Top Close Open

This module is a subclass of Template::TT3::Factory for locating, loading and instantiating exception modules used to represent errors.

It searches for exception modules in the following places:

Template::TT3::Exception
Template::Exception
TemplateX::TT3::Exception
TemplateX::Exception

For example, requesting a syntax exception returns a Template::TT3::Exception::Syntax object. Any other arguments specified are forwarded to the exception constructor method.

my $error = Template::TT3::Exceptions->item( syntax => @args );

CONFIGURATION OPTIONS

Top Close Open

The following configuration options are defined in addition to those inherited from the Template::TT3::Factory , Template::TT3::Base , Badger::Factory and Badger::Base base classes.

They should be specified as a list or reference to a hash array of named parameters when the factory object is created.

    # either a list of named parameters...

    my $exceptions = Template::TT3::Exceptions->new(
        exception_type_path => [
            'My::Exception', 'Template::TT3::Exception'
        ],
    );

    # ...or a reference to a hash array

    my $exceptions = Template::TT3::Exceptions->new({
        exception_type_path => [
            'My::Exception', 'Template::TT3::Exception'
        ],
    });

exception_types

Top Close Open

A reference to a hash array explicitly mapping internal exception type names to external Perl modules. This can be used to override and/or augment the exception type modules that the factory would normally be able to locate automatically.

my $exceptions = Template::TT3::Exceptions->new(
    exception_types => {
        foo => 'Some::Other::Exception::Foo',
        bar => 'Yet::Another::Exception::Bar'
    },
);

exception_type_path / path

Top Close Open

A reference to a list of module namespaces that the factory should search to locate exception_type modules. The default path is defined by the $PATH package variable.

my $exceptions = Template::TT3::Exceptions->new(
    exception_type_path => [
        'My::Exception', 'Template::TT3::Exception'
    ],
);

exception_type_names / names

Top Close Open

A reference to a hash array providing aliases for exception_type names.

my $exceptions = Template::TT3::Exceptions->new(
    exception_type_names => {
        FOO => 'foo',
        bar => 'foo',
    },
);

METHODS

Top Close Open

This module inherits all methods from the Template::TT3::Factory , Template::TT3::Base , Badger::Factory and Badger::Base base classes. The following methods are automatically provided by the Badger::Factory base class.

exception_type($type,@args) / item($type,@args)

Top Close Open

Locates, loads and instantiates an exception module. This is created as an alias to the item() method in Badger::Factory . Note that we have to use this clumsy name to avoid clashing with the exception() method inherited from Badger::Base .

exception_types()

Top Close Open

Method for inspecting or modifying the exceptions that the factory module manages. This is created as an alias to the items() method in Badger::Factory .

PACKAGE VARIABLES

Top Close Open

This module defines the following package variables. These are declarations that are used by the Badger::Factory base class.

$ITEM

Top Close Open

This is the name of the item that the factory module returns, and implicitly the name of the method by which exception objects can be created. In this case it is defined as exception_type.

$PATH

Top Close Open

This defines the module search path for the factory. In this case it is defined as a list of the following values;

Template::TT3::Exception
Template::Exception
TemplateX::TT3::Exception
TemplateX::Exception

AUTHOR

Top Close Open

Andy Wardley http://wardley.org/

COPYRIGHT

Top Close Open

Copyright (C) 1996-2009 Andy Wardley. All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO.

Top Close Open

This module inherits methods from the Template::TT3::Factory , Template::TT3::Base , Badger::Factory , and Badger::Base base classes.

It is constructed using the Template::TT3::Class::Factory class metaprogramming module.

It loads modules and instantiates object that are subclasses of Template::TT3::Exception . See Template::TT3::Exception::Syntax and Template::TT3::Exception::Undef for examples.


http://tt3.template-toolkit.org/docs/Template/TT3/Exceptions.pm last modified 2009-12-21 14:33:36