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 } );
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.
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' ], });
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' }, );
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' ], );
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.
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.
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 .
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 } );
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).
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.
This module defines the following package variables. These are declarations that are used by the Badger::Factory base class.
This is the name of the item that the factory module returns. In this case it
is defined as variable
.
Andy Wardley http://wardley.org/
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.
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.