NAME

Top Close Open

Template::TT3::Types - factory module for loading data types

SYNOPSIS

Top Close Open
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";    

DESCRIPTION

Top Close Open

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 );

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 $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'
        ],
    });

types

Top Close Open

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'
    },
);

type_path / path

Top Close Open

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'
    ],
);

type_names / names

Top Close Open

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

my $types = Template::TT3::Types->new(
    type_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.

type($type)

Top Close Open

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.

types()

Top Close Open

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 .

create($type,@data)

Top Close Open

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 } );

vtable($type)

Top Close Open

Returns a reference to a hash array mapping virtual method names to their implementations for the data type specified as an argument.

vtables($types)

Top Close Open

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');

INTERNAL METHODS

Top Close Open

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 type() 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 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::Type
Template::Type
TemplateX::TT3::Type
TemplateX::Type

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


http://tt3.template-toolkit.org/docs/Template/TT3/Types.pm last modified 2009-12-21 14:26:56