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 WARNING: THIS MODULE IS EXPERIMENTAL AND SUBJECT TO CHANGE WITHOUT
21 NOTICE
22
23 YOU HAVE BEEN WARNED!
24
25 Template::Tiny is a reimplementation of a partial subset of the
26 Template Toolkit in as few lines of code as possible.
27
28 It is intended for use in light-usage, low-memory, or low-cpu
29 templating situations, where you may need to upgrade to the full
30 feature set in the future, or if you want the familiarity of TT-style
31 templates.
32
33 It is intended to have fully-compatible template and stash usage, with
34 a limited by similar Perl API.
35
36 Unlike Template Toolkit, Template::Tiny will process templates without
37 a compile phase (but despite this is still quicker, owing to heavy use
38 of the Perl regular expression engine.
39
40 SUPPORTED USAGE
41 Only the default "[% %]" tag style is supported.
42
43 Both the [%+ +%] style explicit whitespace and the [%- -%] style
44 explicit chomp are support, although the [%+ +%] version is unneeded as
45 Template::Tiny does not support default-enabled PRE_CHOMP or
46 POST_CHOMP.
47
48 Variable expressions in the form foo.bar.baz are supported.
49
50 Appropriate simple behaviours for ARRAY reference, HASH reference and
51 objects are supported, but not "VMethods" such as array lengths.
52
53 IF, ELSE and UNLESS conditions are supported, but only with simple
54 foo.bar.baz conditions.
55
56 Support for looping is available, in the most simple [% FOREACH item IN
57 list %] form.
58
59 All four IF/ELSE/UNLESS/FOREACH control structures are able to be
60 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 this 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
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 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Tiny>
117
118 For other issues, or commercial enhancement or support, contact the
119 author.
120
122 Adam Kennedy <adamk@cpan.org>
123
125 Config::Simple
126
128 Copyright 2009 - 2010 Adam Kennedy.
129
130 This program is free software; you can redistribute it and/or modify it
131 under the same terms as Perl itself.
132
133 The full text of the license can be found in the LICENSE file included
134 with this module.
135
136
137
138perl v5.12.0 2010-02-22 Template::Tiny(3)