Tenjin.pm

filter: Statementstmt 81.3% 96 / 118 Branchbran 56.2% 27 / 48 Conditioncond 60.7% 17 / 28 MC/DCmcdc 41.1% 7 / 17 Subroutinesub 94.1% 16 / 17 Podpod 100% 11 / 11 totaltotal 72.8% 174 / 239 SCAR 42.0
CC
37
Cov
72%
read_template_file
16.8
find_template_file
13.1
render
9.0
CRAP 66.5
« Tenjin/Util.pm ↑ Summary Tenjin/Context.pm »
1 package Tenjin;
2  
3 # ABSTRACT: Fast templating engine with support for embedded Perl.
4  
5 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 ▶use Tenjin::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Tenjin::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Tenjin::Preprocessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 8 our $VERSION = "1.000000";
14 8 $VERSION = eval $VERSION;
15  
16 8 our $USE_STRICT = 0;
17 8 our $ENCODING = 'UTF-8';
18 8 our $BYPASS_TAINT = 1; # unset if you like taint mode
19 8 our $TEMPLATE_CLASS = 'Tenjin::Template';
20 8 our $CONTEXT_CLASS = 'Tenjin::Context';
21 8 our $PREPROCESSOR_CLASS = 'Tenjin::Preprocessor';
22 8 our $TIMESTAMP_INTERVAL = 10;
23  
24 =head1 NAME
25  
26 Tenjin - Fast templating engine with support for embedded Perl.
27  
28 =head1 SYNOPSIS
29  
30 use Tenjin;
31  
32 $Tenjin::USE_STRICT = 1; # use strict in the embedded Perl inside
33 # your templates. Recommended, but not used
34 # by default.
35  
36 $Tenjin::ENCODING = "UTF-8"; # set the encoding of your template files
37 # to UTF-8. This is the default encoding used
38 # so there's no need to do this if your
39 # templates really are UTF-8.
40  
41 my $engine = Tenjin->new(\%options);
42 my $context = { title => 'Tenjin Example', items => [qw/AAA BBB CCC/] };
43 my $filename = 'file.html';
44 my $output = $engine->render($filename, $context);
45 print $output;
46  
47 =head1 DESCRIPTION
48  
49 Tenjin is a very fast and full-featured templating engine, implemented in
50 several programming languages, among them Perl.
51  
52 The Perl version of Tenjin supports embedded Perl code, nestable layout template,
53 inclusion of other templates inside a template, capturing parts of or the entire
54 template output, file and memory caching, template arguments and preprocessing.
55  
56 The original version of Tenjin is developed by Makoto Kuwata. This CPAN
57 version is developed by Ido Perlmuter and differs from the original in a
58 few key aspects:
59  
60 =over
61  
62 =item * Code is entirely revised, packages are separated into modules, with
63 a smaller number of packages than the original version. In particular, the
64 Tenjin::Engine module no longer exists, and is now instead just the Tenjin
65 module (i.e. this one).
66  
67 =item * Support for rendering templates from non-file sources (such as
68 a database) is added.
69  
70 =item * Ability to set the encoding of your templates is added (Tenjin will decode
71 template files according to this encoding; by default, Tenjin will decode
72  
73 =item * HTML is encoded and decoded using the L<HTML::Entities> module,
74 instead of internally.
75  
76 =item * The C<pltenjin> script is not provided, at least for now.
77  
78 =back
79  
80 To make it clear, the CPAN version of Tenjin might find itself diverting
81 a bit in the future from the original Tenjin's roadmap. Although my aim
82 is to be as compatible as possible (and this version is always updated
83 with features and changes from the original), I cannot guarantee it (but I'll
84 do my best). Please note that version 0.05 (and above) of this module is
85 NOT backwards compatible with previous versions.
86  
87 =head2 A NOTE ABOUT ENCODING
88  
89 When Tenjin opens template files, it will automatically decode their contents
90 according to the selected encoding (UTF-8 by default), so make sure your template
91 files are properly encoded. Tenjin also writes cache files of compiled template
92 structure. These will be automatically encoded according to the selected encoding.
93  
94 When it comes to UTF-8, it might interest you to know how Tenjin behaves:
95  
96 =over
97  
98 =item 1. "UTF-8" is the default encoding used. If for some reason, either before
99 running C<< Tenjin->new() >> or during, you provide an alternate spelling (such
100 as "utf8" or "UTF8"), Tenjin will convert it to UTF-8.
101  
102 =item 2. When reading files, Tenjin uses "<:encoding(UTF-8)", while when writing
103 files, Tenjin uses ">:utf8", as recommended by L<this article|https://secure.wikimedia.org/wikibooks/en/w/index.php?title=Perl_Programming/Unicode_UTF-8&oldid=2020796>.
104  
105 =back
106  
107 =head1 METHODS
108  
109 =head2 new( \%options )
110  
111 This creates a new instant of Tenjin. C<\%options> is a hash-ref
112 containing Tenjin's configuration options:
113  
114 =over
115  
116 =item * B<path> - Array-ref of filesystem paths where templates will be searched
117  
118 =item * B<prefix> - A string that will be automatically prepended to template names
119 when searching for them in the path. Empty by default.
120  
121 =item * B<postfix> - The default extension to be automtically appended to template names
122 when searching for them in the path. Don't forget to include the
123 dot, such as '.html'. Empty by default.
124  
125 =item * B<cache> - If set to 1 (the default), compiled templates will be cached on the
126 filesystem (this means the template's code will be cached, not the completed rendered
127 output).
128  
129 =item * B<preprocess> - Enable template preprocessing (turned off by default). Only
130 use if you're actually using any preprocessed Perl code in your templates.
131  
132 =item * B<layout> - Name of a layout template that can be optionally used. If set,
133 templates will be automatically inserted into the layout template,
134 in the location where you use C<[== $_content ==]>.
135  
136 =item * B<strict> - Another way to make Tenjin use strict on embedded Perl code (turned
137 off by default).
138  
139 =item * B<encoding> - Another way to set the encoding of your template files (set to "UTF-8"
140 by default).
141  
142 =back
143  
144 =cut
145  
146 sub new {
147 7 ▶ my ($class, $options) = @_;
Subroutine new: called CC=8 SCAR=21.4
Pod documented
148  
149 7 my $self = {};
150 7 foreach (qw[prefix postfix layout path cache preprocess templateclass strict encoding]) {
151 63 $self->{$_} = delete $options->{$_};
152 }
153 7 ▶ $self->{cache} = 1 unless defined $self->{cache};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"cache"} 6 1 7
154 7 $self->{init_opts_for_template} = $options;
155 7 $self->{templates} = {};
156 7 ▶ $self->{prefix} = '' unless $self->{prefix};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"prefix"} 7 0 7
157 7 ▶ $self->{postfix} = '' unless $self->{postfix};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"postfix"} 7 0 7
158  
159 $Tenjin::ENCODING = $self->{encoding}
160 7 ▶ if $self->{encoding};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"encoding"} 0 7 7
161  
162 # if encoding is utf8, make sure it's spelled UTF-8 and not otherwise
163 7 ▶ $Tenjin::ENCODING = 'UTF-8'
Branch: 1 branch
BranchTrueFalseTotal
if $Tenjin::ENCODING =~ /^utf-?8$/i 7 0 7
164 if $Tenjin::ENCODING =~ m/^utf-?8$/i;
165  
166 $Tenjin::USE_STRICT = $self->{strict}
167 7 ▶ if defined $self->{strict};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"strict"} 0 7 7
168  
169 7 return bless $self, $class;
170 }
171  
172 =head2 render( $tmpl_name, [\%_context, $use_layout] )
173  
174 Renders a template whose name is identified by C<$tmpl_name>. Remember that a prefix
175 and a postfix might be added if they where set when creating the Tenjin instance.
176  
177 C<$_context> is a hash-ref containing the variables that will be available for usage inside
178 the templates. So, for example, if your C<\%_context> is C<< { message => 'Hi there' } >>, then you can use C<$message> inside your templates.
179  
180 C<$use_layout> is a flag denoting whether or not to render this template into a layout
181 template (when doing so, the template will be rendered, then the rendered output will be
182 added to the context hash-ref as '_content', and finally the layout template will be rendered with the revised context and returned.
183  
184 If C<$use_layout> is 1 (which is the default in case it is undefined),
185 then Tenjin will use the layout template that was set when creating the
186 Tenjin instance (via the 'layout' configuration option). If you want to use a different layout template (or if you haven't defined a layout
187 template when creating the Tenjin instance), then you must add the layout template's name
188 to the context as '_layout'. You can also just pass the layout template's name as C<$use_layout>, but C<< $_context->{_layout} >> has precedence.
189  
190 If C<$use_layout> is 0, then a layout template will not be used,
191 even if C<< $_context->{_layout} >> is defined.
192  
193 Note that you can nest layout templates as much as you like, but the only
194 way to do so is by setting the layout template for each template in the
195 nesting chain with C<< $_context->{_layout} >>.
196  
197 Please note that by default file templates are cached on disk (with a '.cache') extension.
198 Tenjin automatically deprecates these cache files every 10 seconds. If you
199 find this value is too low, you can override the C<$Tenjin::TIMESTAMP_INTERVAL>
200 variable with your preferred value.
201  
202 =cut
203  
204 sub render {
205 17 ▶ my ($self, $template_name, $_context, $use_layout) = @_;
Subroutine render: called CC=9 SCAR=22.0
Pod documented
206  
207 17 ▶ $_context ||= {};
Condition100%2/2
$_context ||= {}
l!l
125
MC/DC100%1/1
$_context ||= {}
$_context
Truth table100%2/2
A
A= $_context
Aresult
11
00
208 17 $_context->{'_engine'} = $self;
209  
210 # use a layout template by default
211 17 ▶ $use_layout = 1 unless defined $use_layout;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $use_layout 14 3 17
212  
213 # start rendering the template, and if use_layout is true
214 # then render the layout template with the original output, and
215 # keep doing so if the layout template in itself is nested
216 # inside other layout templates until there are no layouts left
217 17 my $output;
218 17 ▶ while ($template_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($template_name) 23 15 38
219 # get the template
220 23 my $template = $self->get_template($template_name, $_context); # pass $_context only for preprocessing
221  
222 # render the template
223 23 $output = $template->render($_context);
224  
225 # should we nest into a layout template?
226 # check if $use_layout is 0, and if so bolt
227 # check if $_context->{_layout} is defined, and if so use it
228 # if not, and $use_layout is the name of a template, use it
229 # if $use_layout is just 1, then use $self->{layout}
230 # if no layout has been found, loop will finish
231 22 ▶ last if defined $use_layout && $use_layout eq '0';
Branch: 1 branch
BranchTrueFalseTotal
if defined $use_layout and $use_layout eq 0 1 21 22
Condition100%3/3
defined $use_layout and $use_layout eq 0
!ll&&!rl&&r
6151
MC/DC100%2/2
defined $use_layout and $use_layout eq 0
defined $use_layout $use_layout eq 0
Truth table100%3/3
A and B
A= defined $use_layoutB= $use_layout eq 0
ABresult
0X0
100
111
232 21 ▶ $template_name = delete $_context->{_layout} || $use_layout;
Condition100%3/3
delete $_context->{'_layout'} || $use_layout
l!l&&r!l&&!r
4125
MC/DC100%2/2
delete $_context->{'_layout'} || $use_layout
delete $_context->{'_layout'} $use_layout
Truth table100%3/3
A || B
A= delete $_context->{'_layout'}B= $use_layout
ABresult
1X1
011
000
233 21 undef $use_layout; # undef so we don't nest infinitely
234 21 ▶ $template_name = $self->{layout} if $template_name && $template_name eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if $template_name and $template_name eq 1 11 10 21
Condition100%3/3
$template_name and $template_name eq 1
!ll&&!rl&&r
5511
MC/DC100%2/2
$template_name and $template_name eq 1
$template_name $template_name eq 1
Truth table100%3/3
A and B
A= $template_nameB= $template_name eq 1
ABresult
0X0
100
111
235  
236 21 $_context->{_content} = $output;
237 }
238  
239 # return the output
240 16 return $output;
241 }
242  
243 =head2 register_template( $template_name, $template )
244  
245 Receives the name of a template and its L<Tenjin::Template> object
246 and stores it in memory for usage by the engine. This is useful if you
247 need to use templates that are not stored on the file system, for example
248 from a database.
249  
250 Note, however, that you need to pass a template object who's already been
251 converted and compiled into Perl code, so if you have a template with a
252 certain name and certain text, these are the steps you will need to perform:
253  
254 # create a Tenjin instance
255 my $tenjin = Tenjin->new(\%options);
256  
257 # create an empty template object
258 my $template = Tenjin::Template->new();
259  
260 # compile template content into Perl code
261 $template->convert($tmpl_content);
262 $template->compile();
263  
264 # register the template with the Tenjin instance
265 $tenjin->register_template($tmpl_name, $template);
266  
267 =cut
268  
269 sub register_template {
270 18 ▶ my ($self, $template_name, $template) = @_;
Subroutine register_template: called CC=1 SCAR=0.0
Pod documented
271  
272 18 $template->{timestamp} = time;
273 18 $self->{templates}->{$template_name} = $template;
274 }
275  
276 =head1 INTERNAL METHODS
277  
278 =head2 get_template( $template_name, $_context )
279  
280 Receives the name of a template and the context object and tries to find
281 that template in the engine's memory. If it's not there, it will try to find
282 it in the file system (the cache file might be loaded, if present). Returns
283 the template's L<Tenjin::Template> object.
284  
285 =cut
286  
287 sub get_template {
288 23 ▶ my ($self, $template_name, $_context) = @_;
Subroutine get_template: called CC=5 SCAR=16.3
Pod documented
289  
290 ## get cached template
291 23 my $template = $self->{templates}->{$template_name};
292  
293 ## check whether template file is updated or not
294 23 ▶ undef $template if ($template && $template->{filename} && $template->{timestamp} + $TIMESTAMP_INTERVAL <= time);
Branch: 1 branch
BranchTrueFalseTotal
if $template and $template->{"filename"} and $template->{"timestamp"} + $Tenjin::TIMESTAMP_INTERVAL <= time 0 23 23
Condition66%4/6
$template and $template->{"filename"} and $template->{"timestamp"} + $Tenjin::TIMESTAMP_INTERVAL <= time
!ll&&!rl&&r
1850
$template and $template->{"filename"}
!ll&&!rl&&r
1805
MC/DC0%0/3
$template and $template->{"filename"} and $template->{"timestamp"} + $Tenjin::TIMESTAMP_INTERVAL <= time
$template $template->{"filename"} $template->{"timestamp"} + $Tenjin::TIMESTAMP_INTERVAL <= time
Truth table50%2/4
A and B and C
A= $templateB= $template->{"filename"}C= $template->{"timestamp"} + $Tenjin::TIMESTAMP_INTERVAL <= time
ABCresult
0XX0
10X0
1100
1111
295  
296 ## load and register template
297 23 ▶ unless ($template) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($template) 18 5 23
298 18 my $filename = $self->to_filename($template_name);
299 18 my $filepath = $self->find_template_file($filename);
300 18 $template = $self->create_template($filepath, $template_name, $_context); # $_context is passed only for preprocessor
301 18 $self->register_template($template_name, $template);
302 }
303  
304 23 return $template;
305 }
306  
307 =head2 to_filename( $template_name )
308  
309 Receives a template name and returns the proper file name to be searched
310 in the file system, which will only be different than C<$template_name>
311 if it begins with ':', in which case the prefix and postfix configuration
312 options will be appended and prepended to the template name (minus the ':'),
313 respectively.
314  
315 =cut
316  
317 sub to_filename {
318 18 ▶ my ($self, $template_name) = @_;
Subroutine to_filename: called CC=2 SCAR=7.6
Pod documented
319  
320 18 ▶ if (substr($template_name, 0, 1) eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($template_name, 0, 1) eq ":") 0 18 18
321 0 return $self->{prefix} . substr($template_name, 1) . $self->{postfix};
322 }
323  
324 18 return $template_name;
325 }
326  
327 =head2 find_template_file( $filename )
328  
329 Receives a template filename and searches for it in the path defined in
330 the configuration options (or, if a path was not set, in the current
331 working directory). Returns the absolute path to the file.
332  
333 =cut
334  
335 sub find_template_file {
336 18 ▶ my ($self, $filename) = @_;
Subroutine find_template_file: called CC=7 SCAR=25.7
Pod documented
337  
338 18 my $path = $self->{path};
339 18 ▶ if ($path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path) { } 18 0 18
340 18 ▶ my $sep = $^O eq 'MSWin32' ? '\\\\' : '/';
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 18 18
341 18 foreach my $dirname (@$path) {
342 18 my $filepath = $dirname . $sep . $filename;
343 18 ▶ return $filepath if -f $filepath;
Branch: 1 branch
BranchTrueFalseTotal
if -f $filepath 18 0 18
344 }
345 } else {
346 0 ▶ return $filename if -f $filename;
Branch: 1 branch
BranchTrueFalseTotal
if -f $filename 0 0 0
347 }
348 0 ▶ my $s = $path ? ("['" . join("','", @$path) . "']") : '[]';
Branch: 1 branch
BranchTrueFalseTotal
$path ? : 0 0 0
349 0 croak "[Tenjin] $filename not found in path (path is $s).";
350 }
351  
352 =head2 read_template_file( $template, $filename, $_context )
353  
354 Receives a template object and its absolute file path and reads that file.
355 If preprocessing is on, preprocessing will take place using the provided
356 context object.
357  
358 =cut
359  
360 sub read_template_file {
361 18 ▶ my ($self, $template, $filename, $_context) = @_;
Subroutine read_template_file: called CC=5 SCAR=28.2
Pod documented
362  
363 18 ▶ if ($self->{preprocess}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"preprocess"}) 0 18 18
364 0 ▶ if (! defined($_context) || ! $_context->{_engine}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_context and $_context->{"_engine"}) 0 0 0
Condition0%0/3
defined $_context and $_context->{"_engine"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_context and $_context->{"_engine"}
defined $_context $_context->{"_engine"}
Truth table0%0/3
A and B
A= defined $_contextB= $_context->{"_engine"}
ABresult
0X0
100
111
365 0 ▶ $_context ||= {};
Condition0%0/2
$_context ||= {}
l!l
00
MC/DC0%0/1
$_context ||= {}
$_context
Truth table0%0/2
A
A= $_context
Aresult
11
00
366 0 $_context->{'_engine'} = $self;
367 }
368 0 my $pp = $Tenjin::PREPROCESSOR_CLASS->new();
369 0 $pp->convert($template->_read_file($filename));
370 0 return $pp->render($_context);
371 }
372  
373 18 return $template->_read_file($filename, 1);
374 }
375  
376 =head2 cachename( $filename )
377  
378 Receives a template filename and returns its standard cache filename (which
379 will simply be C<$filename> with '.cache' appended to it.
380  
381 =cut
382  
383 sub cachename {
384 18 ▶ my ($self, $filename) = @_;
Subroutine cachename: called CC=1 SCAR=0.0
Pod documented
385  
386 18 return $filename . '.cache';
387 }
388  
389 =head2 store_cachefile( $cachename, $template )
390  
391 Receives the name of a template cache file and the corresponding template
392 object, and creates the cache file on disk.
393  
394 =cut
395  
396 sub store_cachefile {
397 16 ▶ my ($self, $cachename, $template) = @_;
Subroutine store_cachefile: called CC=2 SCAR=7.9
Pod documented
398  
399 16 my $cache = $template->{script};
400 16 ▶ if (defined $template->{args}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $template->{"args"}) 0 16 16
401 0 my $args = $template->{args};
402 0 $cache = "\#\@ARGS " . join(',', @$args) . "\n" . $cache;
403 }
404 16 $template->_write_file($cachename, $cache, 1);
405 }
406  
407 =head2 load_cachefile( $cachename, $template )
408  
409 Receives the name of a template cache file and the corresponding template
410 object, reads the cache file and stores it in the template object (as 'script').
411  
412 =cut
413  
414 sub load_cachefile {
415 0 ▶ my ($self, $cachename, $template) = @_;
Subroutine load_cachefile: not called CC=2 SCAR=17.9
Pod documented
416  
417 0 my $cache = $template->_read_file($cachename, 1);
418 0 ▶ if ($cache =~ s/\A\#\@ARGS (.*)\r?\n//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache =~ s/\A\#\@ARGS (.*)\r?\n//) 0 0 0
419 0 my $argstr = $1;
420 0 $argstr =~ s/\A\s+|\s+\Z//g;
421 0 my @args = split(',', $argstr);
422 0 $template->{args} = \@args;
423 }
424 0 $template->{script} = $cache;
425 }
426  
427 =head2 create_template( $filename, $_context )
428  
429 Receives an absolute path to a template file and the context object, reads
430 the file, processes it (which may involve loading the template's cache file
431 or creating the template's cache file), compiles it and returns the template
432 object.
433  
434 =cut
435  
436 sub create_template {
437 18 ▶ my ($self, $filename, $template_name, $_context) = @_;
Subroutine create_template: called CC=5 SCAR=17.6
Pod documented
438  
439 18 my $cachename = $self->cachename($filename);
440  
441 18 ▶ my $class = $self->{templateclass} || $Tenjin::TEMPLATE_CLASS;
Condition33%1/3
$self->{'templateclass'} || $Tenjin::TEMPLATE_CLASS
l!l&&r!l&&!r
0180
MC/DC0%0/2
$self->{'templateclass'} || $Tenjin::TEMPLATE_CLASS
$self->{'templateclass'} $Tenjin::TEMPLATE_CLASS
Truth table33%1/3
A || B
A= $self->{'templateclass'}B= $Tenjin::TEMPLATE_CLASS
ABresult
1X1
011
000
442 18 my $template = $class->new(undef, $template_name, $self->{init_opts_for_template});
443  
444 18 ▶ if (! $self->{cache}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->{'cache'}) { } 2 16 18
elsif (not -f $cachename or (stat $cachename)[9] < (stat $filename)[9]) { } 16 0 16
445 2 $template->convert($self->read_template_file($template, $filename, $_context), $filename);
446 ▶ } elsif (! -f $cachename || (stat $cachename)[9] < (stat $filename)[9]) {
Condition33%1/3
not -f $cachename or (stat $cachename)[9] < (stat $filename)[9]
l!l&&r!l&&!r
1600
MC/DC0%0/2
not -f $cachename or (stat $cachename)[9] < (stat $filename)[9]
not -f $cachename (stat $cachename)[9] < (stat $filename)[9]
Truth table33%1/3
not(A) or B
A= not -f $cachenameB= (stat $cachename)[9] < (stat $filename)[9]
ABresult
1X1
011
000
447 16 $template->convert($self->read_template_file($template, $filename, $_context), $filename);
448 16 $self->store_cachefile($cachename, $template);
449 } else {
450 0 $template->{filename} = $filename;
451 0 $self->load_cachefile($cachename, $template);
452 }
453 18 $template->compile();
454  
455 18 return $template;
456 }
457  
458 8 1;
459  
460 =head1 SEE ALSO
461  
462 The original Tenjin website is located at L<http://www.kuwata-lab.com/tenjin/>. In there check out
463 L<http://www.kuwata-lab.com/tenjin/pltenjin-users-guide.html> for detailed usage guide,
464 L<http://www.kuwata-lab.com/tenjin/pltenjin-examples.html> for examples, and
465 L<http://www.kuwata-lab.com/tenjin/pltenjin-faq.html> for frequently asked questions.
466  
467 Note that the Perl version of Tenjin is referred to as plTenjin on the Tenjin website,
468 and that, as opposed to this module, the website suggests using a .plhtml extension
469 for the templates instead of .html (this is entirely your choice).
470  
471 L<Tenjin::Template>, L<Catalyst::View::Tenjin>, L<Dancer::Template::Tenjin>.
472  
473 =head1 CHANGES
474  
475 Version 0.05 of this module broke backwards compatibility with previous versions.
476 In particular, the Tenjin::Engine module does not exist any more and is
477 instead integrated into this one. Templates are also rendered entirely
478 different (as per changes in the original tenjin) which provides much
479 faster rendering.
480  
481 Upon upgrading to versions 0.05 and above, you MUST perform the following changes
482 for your applications (or, if you're using Catalyst, you must also upgrade
483 L<Catalyst::View::Tenjin>):
484  
485 =over
486  
487 =item * C<use Tenjin> as your normally would, but to get an instance
488 of Tenjin you must call C<< Tenjin->new() >> instead of the old method
489 of calling C<< Tenjin::Engine->new() >>.
490  
491 =item * Remove all your templates cache files (they are the '.cache' files
492 in your template directories), they are not compatible with the new
493 templates structure and WILL cause your application to fail if present.
494  
495 =back
496  
497 Version 0.06 (this version) restored the layout template feature which was
498 accidentally missing in version 0.05, and the ability to call the utility
499 methods of L<Tenjin::Util> natively inside templates. You will want to
500 remove your templates' .cache files when upgrading to 0.6 too.
501  
502 =head1 AUTHOR
503  
504 Ido Perlmuter E<lt>ido at ido50.netE<gt>
505  
506 Forked from plTenjin 0.0.2 by Makoto Kuwata (L<http://www.kuwata-lab.com/tenjin/>).
507  
508 =head1 ACKNOWLEDGEMENTS
509  
510 I would like to thank the following people for their contributions:
511  
512 =over
513  
514 =item * Makoto Kuwata
515  
516 The original developer of Tenjin.
517  
518 =item * John Beppu E<lt>beppu at cpan.orgE<gt>
519  
520 For introducing me to Tenjin and helping me understand the way it's designed.
521  
522 =item * Pedro Melo E<lt>melo at cpan.orgE<gt>
523  
524 For helping me understand the logic behind some of the original Tenjin aspects
525 and helping me fix bugs and create tests.
526  
527 =back
528  
529 =head1 BUGS
530  
531 Please report any bugs or feature requests on the L<GitHub project page|https://github.com/ido50/Tenjin/issues>.
532  
533 =head1 SUPPORT
534  
535 You can find documentation for this module with the perldoc command.
536  
537 perldoc Tenjin
538  
539 You can also read the documentation online on L<metacpan|https://metacpan.org/pod/Tenjin>.
540  
541 =head1 LICENSE AND COPYRIGHT
542  
543 Tenjin is licensed under the MIT license.
544  
545 Copyright (c) 2007-2016 the aforementioned authors.
546  
547 Permission is hereby granted, free of charge, to any person obtaining
548 a copy of this software and associated documentation files (the
549 "Software"), to deal in the Software without restriction, including
550 without limitation the rights to use, copy, modify, merge, publish,
551 distribute, sublicense, and/or sell copies of the Software, and to
552 permit persons to whom the Software is furnished to do so, subject to
553 the following conditions:
554  
555 The above copyright notice and this permission notice shall be
556 included in all copies or substantial portions of the Software.
557  
558 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
559 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
560 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
561 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
562 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
563 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
564 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
565  
566 See http://dev.perl.org/licenses/ for more information.
567  
568 =cut
« Tenjin/Util.pm ↑ Summary Tenjin/Context.pm »