NAME

Top Close Open

Template::TT3::Variables - factory module for loading variable modules

SYNOPSIS

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

my $types = Template::TT3::Variables->constructors(
    undef => 'missing',                 # map data types
    text  => {                          # add virtual methods
        foo => sub { ... },
        bar => sub { ... },
    },
    'Wiz::Bang' => {                    # define object maps
        '*'   => 0,                     # don't call methods by default
        'foo' => 1,                     # do call foo() method
        'bar' => sub { ... },           # virtual method
    }
);

DESCRIPTION

Top Close Open

This module is a subclass of Template::TT3::Factory for locating and loading template variable modules. Variable objects are subclasses of Template::TT3::Variable which acts as small, lightweight wrappers around data values. They implement the additional behaviours that make TT variables different from basic Perl variables.

It searches for variable modules in the following places:

Template::TT3::Variable
Template::Variable
TemplateX::TT3::Variable
TemplateX::Variable

For example, the text variable type is mapped to the Template::TT3::Varaible::Text object.

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 $variables = Template::TT3::Variables->new(
        variable_path => [
            'My::Variable', 'Template::TT3::Variable'
        ],
    );

    # ...or a reference to a hash array

    my $variables = Template::TT3::Variables->new({
        variable_path => [
            'My::Variable', 'Template::TT3::Variable'
        ],
    });

variables

Top Close Open

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

my $variables = Template::TT3::Variables->new(
    variables => {
        foo => 'Some::Other::Variable::Foo',
        bar => 'Yet::Another::Variable::Bar'
    },
);

variable_path / path

Top Close Open

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

my $variables = Template::TT3::Variables->new(
    variable_path => [
        'My::Variable', 'Template::TT3::Variable'
    ],
);

variable_names / names

Top Close Open

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

my $variables = Template::TT3::Variables->new(
    variable_names => {
        FOO => 'foo',
        bar => 'foo',
    },
);

METHODS

Top Close Open

The following methods are implemented or automatically added by the Template::TT3::Class::Factory metaprogramming module in addition to those inherited from the Template::TT3::Factory , Template::TT3::Base , Badger::Factory and Badger::Base base classes.

variable($type)

Top Close Open

Locates and loads a variable module and returns the class name. This is created as an alias to the item() method in Badger::Factory .

Note that the method doesn't automatically create a new variable object as most factory modules do. TT uses this module to define constructor functions (via the constructors() method) which create objectm but not for creating instances of the variable objects directly.

variables()

Top Close Open

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

constructors(\%types)

Top Close Open

Returns a reference to a hash array containing constructor functions for the variables types specified as argument(s), along with any builtin() variable types.

    # default set of constructors
    my $ctors = Template::TT3::Variables->constructors;

    # customised set
    my $ctors = Template::TT3::Variables->constructors(
        undef => 'missing',                 # map data types
        text  => {                          # add virtual methods
            foo => sub { ... },             # to inbuilt data types
            bar => sub { ... },
        },
        'Wiz::Bang' => {                    # define custom object maps
            '*'   => 0,                     # don't call methods by default
            'foo' => 1,                     # do call foo() method
            'bar' => sub { ... },           # virtual method
        }
    );

INTERNAL METHODS

Top Close Open

builtin()

Top Close Open

This method loads all the builtin variable types and returns a reference to a hash array mapping their internal names (e.g. text, list, etc) to their external module names (e.g. Template::TT3::Variable::Text , Template::TT3::Variable::List , etc).

found($type,$module)

Top Close Open

This replaces the default method inherited from the Badger::Factory base class. Instead of automatically creating an object when the variable() method is called, it instead returns the class name of the module implementing it.

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. In this case it is defined as variable.

$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::Variable
Template::Variable
TemplateX::TT3::Variable
TemplateX::Variable

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::Variable . See Template::TT3::Variable::Text , Template::TT3::Variable::List and Template::TT3::Variable::Hash for examples.

DESCRIPTION

Top Close Open

http://tt3.template-toolkit.org/docs/Template/TT3/Variables.pm last modified 2009-12-21 15:02:41