1Template::Config(3)   User Contributed Perl Documentation  Template::Config(3)
2
3
4

NAME

6       Template::Config - Factory module for instantiating other TT2 modules
7

SYNOPSIS

9           use Template::Config;
10

DESCRIPTION

12       This module implements various methods for loading and instantiating
13       other modules that comprise the Template Toolkit.  It provides a
14       consistent way to create toolkit components and allows custom modules
15       to be used in place of the regular ones.
16
17       Package variables such as $STASH, $SERVICE, $CONTEXT, etc., contain the
18       default module/package name for each component (Template::Stash,
19       Template::Service and Template::Context, respectively) and are used by
20       the various factory methods (stash(), service() and context()) to load
21       the appropriate module. Changing these package variables will cause
22       subsequent calls to the relevant factory method to load and instantiate
23       an object from the new class.
24

PUBLIC METHODS

26   load($module)
27       Load a module using Perl's require(). Any occurrences of '"::"' in the
28       module name are be converted to '"/"', and '".pm"' is appended. Returns
29       1 on success or undef on error.  Use "$class->error()" to examine the
30       error string.
31
32   preload()
33       This method preloads all the other "Template::*" modules that are
34       likely to be used. It is called automatically by the Template module
35       when running under mod_perl ($ENV{MOD_PERL} is set).
36
37   parser(\%config)
38       Instantiate a new parser object of the class whose name is denoted by
39       the package variable $PARSER (default: Template::Parser).  Returns a
40       reference to a newly instantiated parser object or undef on error.
41
42   provider(\%config)
43       Instantiate a new template provider object (default:
44       Template::Provider).  Returns an object reference or undef on error, as
45       above.
46
47   plugins(\%config)
48       Instantiate a new plugins provider object (default: Template::Plugins).
49       Returns an object reference or undef on error, as above.
50
51   filters(\%config)
52       Instantiate a new filter provider object (default: Template::Filters).
53       Returns an object reference or undef on error, as above.
54
55   stash(\%vars)
56       Instantiate a new stash object (Template::Stash or Template::Stash::XS
57       depending on the default set at installation time) using the contents
58       of the optional hash array passed by parameter as initial variable
59       definitions.  Returns an object reference or undef on error, as above.
60
61   context(\%config)
62       Instantiate a new template context object (default: Template::Context).
63       Returns an object reference or undef on error, as above.
64
65   service(\%config)
66       Instantiate a new template service object (default: Template::Service).
67       Returns an object reference or undef on error, as above.
68
69   iterator(\%config)
70       Instantiate a new template iterator object (default:
71       Template::Iterator).  Returns an object reference or undef on error, as
72       above.
73
74   constants(\%config)
75       Instantiate a new namespace handler for compile time constant folding
76       (default: Template::Namespace::Constants). Returns an object reference
77       or undef on error, as above.
78
79   instdir($dir)
80       Returns the root directory of the Template Toolkit installation under
81       which optional components are installed.  Any relative directory
82       specified as an argument will be appended to the returned directory.
83
84           # e.g. returns '/usr/local/tt2'
85           my $ttroot = Template::Config->instdir()
86               || die "$Template::Config::ERROR\n";
87
88           # e.g. returns '/usr/local/tt2/templates'
89           my $template = Template::Config->instdir('templates')
90               || die "$Template::Config::ERROR\n";
91
92       Returns "undef" and sets $Template::Config::ERROR appropriately if the
93       optional components of the Template Toolkit have not been installed.
94

AUTHOR

96       Andy Wardley <abw@wardley.org> <http://wardley.org/>
97
99       Copyright (C) 1996-2022 Andy Wardley.  All Rights Reserved.
100
101       This module is free software; you can redistribute it and/or modify it
102       under the same terms as Perl itself.
103

SEE ALSO

105       Template
106
107
108
109perl v5.36.0                      2023-01-20               Template::Config(3)
Impressum