use Template::TT3::Types; my $text = Template::TT3::Types->create( text => 'Hello World' ); print "text is ", $text->length(), " characters long\n"; my $list = Template::TT3::Types->create( list => [ 'Hello', 'World' ] ); print "list has ", $list->size(), " items\n"; my $hash = Template::TT3::Types->create( hash => { Hello => 'World' } ); print "hash has ", $hash->size(), " pairs\n";
This module is a subclass of Template::TT3::Factory for locating, loading and instantiating data type modules.
It searches for type modules in the following places:
Template::TT3::Type Template::Type TemplateX::TT3::Type TemplateX::Type
For example, creating a list
type returns a
Template::TT3::Type::List
object.
my $list = Template::TT3::Types->create( list => \@data );
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 $types = Template::TT3::Types->new( type_path => [ 'My::Type', 'Template::TT3::Type' ], ); # ...or a reference to a hash array my $types = Template::TT3::Types->new({ type_path => [ 'My::Type', 'Template::TT3::Type' ], });
A reference to a hash array explicitly mapping internal type names to external Perl modules. This can be used to override and/or augment the type modules that the factory would normally be able to locate automatically.
my $types = Template::TT3::Types->new( types => { foo => 'Some::Other::Type::Foo', bar => 'Yet::Another::Type::Bar' }, );
A reference to a list of module namespaces that the factory should search to locate type modules. The default path is defined by the $PATH package variable.
my $types = Template::TT3::Types->new( type_path => [ 'My::Type', 'Template::TT3::Type' ], );
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 data type 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 data type object as most factory modules do. TT uses this module to load virtual method tables for types (via the vtable() and vtables() methods) but not for creating instances of the data type objects. See create() for a method that does.
Method for inspecting or modifying the data types that the factory module manages. This is created as an alias to the items() method in Badger::Factory .
Constructor method which creates a new instance variable of a particular type.
my $text = $types->create( text => 'Hello World' ); my $list = $types->create( list => [10, 20] ); my $hash = $types->create( hash => { x=>10, y=>20 } );
Returns a reference to a hash array mapping virtual method names to their implementations for the data type specified as an argument.
Returns a reference to a hash array containing virtual method tables (see vtable() ) for the types specified as argument(s). Types can be specified as a list of names:
my $vtables = $types->vtables('text', 'list', 'hash');
Or as a reference to a list of names;
my $vtables = $types->vtables(['text', 'list', 'hash']);
Or as a single text string containing whitespace-delimited names:
my $vtables = $types->vtables('text list hash');
This replaces the default method inherited from the Badger::Factory base class. Instead of automatically creating an object when the type() 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 type
.
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::Type . See Template::TT3::Type::Text , Template::TT3::Type::List and Template::TT3::Type::Hash for examples.