NAME

Top Close Open

Template::TT3::Providers - factory module for loading template providers

SYNOPSIS

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

# class methods
$provider = Template::TT3::Providers->provider;          # default provider (cwd)
$provider = Template::TT3::Providers->provider('file');  # specific provider

# object methods
$providers = Template::TT3::Providers->new;
$provider  = $providers->provider;
$provider  = $providers->provider('file');

# object with configuration options
$providers = Template::TT3::Providers->new( 
    path => ['My::Provider', 'Your::Provider'],
);
$provider  = $providers->provider;
$provider  = $providers->provider('file');

DESCRIPTION

Top Close Open

This module is a subclass of Template::TT3::Factory for locating, loading and instantiating template provider modules. Provider modules are responsible for loading templates from a filesystem, database, remote service, or by some other mechanism.

It searches for provider modules in the following places:

Template::TT3::Provider
Template::Provider
TemplateX::TT3::Provider
TemplateX::Provider

For example, requesting a file provider returns a Template::TT3::Provider::File object.

my $provider = Template::TT3::Providers->provider('file');

The default provider type is Cwd, returned as a Template::TT3::Provider::Cwd object. This loads templates from the local filesystem, using the current working directory as the default location.

my $provider = $providers->provider;
my $provider = $providers->provider('cwd');         # same thing
my $provider = $providers->provider('default');     # same thing

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 $providers = Template::TT3::Providers->new(
        provider_path => [
            'My::Provider', 'Template::TT3::Provider'
        ],
    );

    # ...or a reference to a hash array

    my $providers = Template::TT3::Providers->new({
        provider_path => [
            'My::Provider', 'Template::TT3::Provider'
        ],
    });

providers

Top Close Open

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

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

provider_path / path

Top Close Open

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

my $providers = Template::TT3::Providers->new(
    provider_path => [
        'My::Provider', 'Template::TT3::Provider'
    ],
);

provider_names / names

Top Close Open

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

my $providers = Template::TT3::Providers->new(
    provider_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.

provider($type)

Top Close Open

Locates, loads and instantiates a provider module. This is created as an alias to the item() method in Badger::Factory .

providers()

Top Close Open

Method for inspecting or modifying the providers 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 providers objects can be created. In this case it is defined as provider.

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

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::Provider . See Template::TT3::Provider::File and Template::TT3::Provider::Cwd for examples of specific provider modules.


http://tt3.template-toolkit.org/docs/Template/TT3/Providers.pm last modified 2009-12-23 19:03:14