1Template::Tiny(3) User Contributed Perl Documentation Template::Tiny(3)
2
3
4
6 Template::Tiny - Template Toolkit reimplemented in as little code as
7 possible
8
10 my $template = Template::Tiny->new(
11 TRIM => 1,
12 );
13
14 # Print the template results to STDOUT
15 $template->process( <<'END_TEMPLATE', { foo => 'World' } );
16 Hello [% foo %]!
17 END_TEMPLATE
18
20 Template::Tiny is a reimplementation of a subset of the functionality
21 from Template Toolkit in as few lines of code as possible.
22
23 It is intended for use in light-usage, low-memory, or low-cpu
24 templating situations, where you may need to upgrade to the full
25 feature set in the future, or if you want the retain the familiarity of
26 TT-style templates.
27
28 For the subset of functionality it implements, it has fully-compatible
29 template and stash API. All templates used with Template::Tiny should
30 be able to be transparently upgraded to full Template Toolkit.
31
32 Unlike Template Toolkit, Template::Tiny will process templates without
33 a compile phase (but despite this is still quicker, owing to heavy use
34 of the Perl regular expression engine.
35
36 SUPPORTED USAGE
37 Only the default "[% %]" tag style is supported.
38
39 Both the "[%+ +%]" style explicit whitespace and the "[%- -%]" style
40 explicit chomp are support, although the "[%+ +%]" version is unneeded
41 in practice as Template::Tiny does not support default-enabled
42 "PRE_CHOMP" or "POST_CHOMP".
43
44 Variable expressions in the form "[% foo.bar.baz %]" are supported.
45
46 Appropriate simple behaviours for "ARRAY" references, "HASH" references
47 and objects are supported. "VMethods" such as [% array.length %] are
48 not supported at this time.
49
50 "IF", "ELSE" and "UNLESS" conditional blocks are supported, but only
51 with simple "[% foo.bar.baz %]" conditions.
52
53 Support for looping (or rather iteration) is available in simple "[%
54 FOREACH item IN list %]" form is supported. Other loop structures are
55 not supported. Because support for arbitrary or infinite looping is not
56 available, Template::Tiny templates are not turing complete. This is
57 intentional.
58
59 All of the four supported control structures
60 "IF"/"ELSE"/"UNLESS"/"FOREACH" can be nested to arbitrary depth.
61
62 The treatment of "_private" hash and method keys is compatible with
63 Template Toolkit, returning null or false rather than the actual
64 content of the hash key or method.
65
66 Anything beyond the above is currently out of scope.
67
69 new
70 my $template = Template::Tiny->new(
71 TRIM => 1,
72 );
73
74 The "new" constructor is provided for compatibility with Template
75 Toolkit.
76
77 The only parameter it currently supports is "TRIM" (which removes
78 leading and trailing whitespace from processed templates).
79
80 Additional parameters can be provided without error, but will be
81 ignored.
82
83 process
84 # DEPRECATED: Return template results (emits a warning)
85 my $text = $template->process( \$input, $vars );
86
87 # Print template results to STDOUT
88 $template->process( \$input, $vars );
89
90 # Generate template results into a variable
91 my $output = '';
92 $template->process( \$input, $vars, \$output );
93
94 The "process" method is called to process a template.
95
96 The first parameter is a reference to a text string containing the
97 template text. A reference to a hash may be passed as the second
98 parameter containing definitions of template variables.
99
100 If a third parameter is provided, it must be a scalar reference to be
101 populated with the output of the template.
102
103 For a limited amount of time, the old deprecated interface will
104 continue to be supported. If "process" is called without a third
105 parameter, and in scalar or list contest, the template results will be
106 returned to the caller.
107
108 If "process" is called without a third parameter, and in void context,
109 the template results will be "print()"ed to the currently selected file
110 handle (probably "STDOUT") for compatibility with Template.
111
113 Bugs should be reported via the CPAN bug tracker at
114
115 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Tiny>
116
117 For other issues, or commercial enhancement or support, contact the
118 author.
119
121 Adam Kennedy <adamk@cpan.org>
122
124 Config::Tiny, CSS::Tiny, YAML::Tiny
125
127 Copyright 2009 - 2011 Adam Kennedy.
128
129 This program is free software; you can redistribute it and/or modify it
130 under the same terms as Perl itself.
131
132 The full text of the license can be found in the LICENSE file included
133 with this module.
134
135
136
137perl v5.30.0 2019-07-26 Template::Tiny(3)