Template::Config
Author: Andy Wardley

TT2 Home Page

- Modules
- Template::*
- Config.pm

Click to view the menu. It's very nice. Click to hide the menu and go all widescreen!
Back

#### Template::Base

Base class module implementing common functionality Up

#### Template::* Modules

Next

#### Template::Constants

Defines constants for the Template Toolkit

# Template::Config

## Factory module for instantiating other TT2 modules

# Contents

Top

# SYNOPSIS

Top

    use Template::Config;

# DESCRIPTION

Top

This module implements various methods for loading and instantiating other modules that comprise the Template Toolkit. It provides a consistent way to create toolkit components and allows custom modules to be used in place of the regular ones.

Package variables such as `$STASH`, `$SERVICE`, `$CONTEXT`, etc., contain the default module/package name for each component (Template::Stash, Template::Service and Template::Context, respectively) and are used by the various factory methods (stash(), service() and context()) to load the appropriate module. Changing these package variables will cause subsequent calls to the relevant factory method to load and instantiate an object from the new class.

# PUBLIC METHODS

Top

## load($module)

Top

Load a module using Perl's require(). Any occurences of '`::`' in the module name are be converted to '`/`', and '`.pm`' is appended. Returns 1 on success or undef on error. Use `$class->error()` to examine the error string.

## preload()

Top

This method preloads all the other `Template::*` modules that are likely to be used. It is called automatically by the Template module when running under mod_perl (`$ENV{MOD_PERL}` is set).

## parser(\%config)

Top

Instantiate a new parser object of the class whose name is denoted by the package variable `$PARSER` (default: Template::Parser). Returns a reference to a newly instantiated parser object or undef on error.

## provider(\%config)

Top

Instantiate a new template provider object (default: Template::Provider). Returns an object reference or undef on error, as above.

## plugins(\%config)

Top

Instantiate a new plugins provider object (default: Template::Plugins). Returns an object reference or undef on error, as above.

## filters(\%config)

Top

Instantiate a new filter provider object (default: Template::Filters). Returns an object reference or undef on error, as above.

## stash(\%vars)

Top

Instantiate a new stash object (Template::Stash or Template::Stash::XS depending on the default set at installation time) using the contents of the optional hash array passed by parameter as initial variable definitions. Returns an object reference or undef on error, as above.

## context(\%config)

Top

Instantiate a new template context object (default: Template::Context). Returns an object reference or undef on error, as above.

## service(\%config)

Top

Instantiate a new template service object (default: Template::Service). Returns an object reference or undef on error, as above.

## instdir($dir)

Top

Returns the root directory of the Template Toolkit installation under which optional components are installed. Any relative directory specified as an argument will be appended to the returned directory.

    # e.g. returns '/usr/local/tt2'
    my $ttroot = Template::Config->instdir()
        || die "$Template::Config::ERROR\n";

    # e.g. returns '/usr/local/tt2/templates'
    my $template = Template::Config->instdir('templates')
        || die "$Template::Config::ERROR\n";

Returns `undef` and sets `$Template::Config::ERROR` appropriately if the optional components of the Template Toolkit have not been installed.

# AUTHOR

Top

Andy Wardley <abw@wardley.org> http://wardley.org/

# COPYRIGHT

Top

Copyright (C) 1996-2007 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

Template

/modules/Template/Config.html last modified 10:57:45 31-May-2007