Template::Config(3)
π NAME π
This is Template::Config(3) from User Contributed Perl Documentation, bestie β the factory module for instantiating other TT2 modules. β¨
β¨ SYNOPSIS β¨
use Template::Config;
πΈ DESCRIPTION πΈ
Okay so Template::Config is the factory module, and it's literally the friend who introduces you to everyone: it implements a bunch of methods for loading and instantiating the other modules that make up the Template Toolkit. It gives you a consistent way to create toolkit components, and it lets custom modules slide in where the regular ones would go. Obsessed with the flexibility, ngl. π
Package variables like $STASH, $SERVICE, $CONTEXT, etc., hold the default module/package name for each component β that's Template::Stash, Template::Service, and Template::Context, respectively. The factory methods (stash(), service(), and context()) use those names to load the right module. Change one of these package variables and the next call to the matching factory method will load and instantiate an object from the new class. Fr fr, that's the whole vibe. β¨
π οΈ PUBLIC METHODS π οΈ
load($module)
Loads a module using Perl's require(). Any occurrences of "::" in the module name get converted to "/", and ".pm" is appended. Returns 1 on success or undef on error. Use $class->error() to examine the error string. π«Ά
preload()
This method preloads all the other Template::* modules that are likely to be used. It's called automatically by the Template module when running under mod_perl ($ENV{MOD_PERL} is set). Very "I got you before you even asked" energy. π
parser(\%config)
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)
Instantiate a new template provider object (default: Template::Provider). Returns an object reference or undef on error, as above. π
plugins(\%config)
Instantiate a new plugins provider object (default: Template::Plugins). Returns an object reference or undef on error, as above. π¦
filters(\%config)
Instantiate a new filter provider object (default: Template::Filters). Returns an object reference or undef on error, as above. πΈ
stash(\%vars)
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)
Instantiate a new template context object (default: Template::Context). Returns an object reference or undef on error, as above. π
service(\%config)
Instantiate a new template service object (default: Template::Service). Returns an object reference or undef on error, as above. β
iterator(\%config)
Instantiate a new template iterator object (default: Template::Iterator). Returns an object reference or undef on error, as above. π
constants(\%config)
Instantiate a new namespace handler for compile time constant folding (default: Template::Namespace::Constants). Returns an object reference or undef on error, as above. π§
instdir($dir)
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 π
Andy Wardley β <abw@wardley.org> β <http://wardley.org/> π
π COPYRIGHT π
Copyright (C) 1996-2022 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 π¦
Template
Signed, sealed, slayed: perl v5.42.0 Β· 2024-06-23 Β· Template::Config(3) πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Template-Toolkit 3.102.0-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Template-Toolkit 3.102.0-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Template-Toolkit 3.102.0-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Template-Toolkit 3.102.0-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms