1HTML::Template::PerlIntUesrefracCeo(n3t)ributed Perl DocHuTmMeLn:t:aTteimopnlate::PerlInterface(3)
2
3
4

NAME

6       HTML::Template::PerlInterface - perl interface of HTML::Template::Pro
7

SYNOPSIS

9       This help is only on perl interface of HTML::Template::Pro.  For syntax
10       of html template files you should see "SYNOPSIS" in
11       HTML::Template::SYNTAX.
12
13       First you make a template - this is just a normal HTML file with a few
14       extra tags, the simplest being <TMPL_VAR>
15
16       For example, test.tmpl:
17
18         <html>
19         <head><title>Test Template</title>
20         <body>
21         My Home Directory is <TMPL_VAR NAME=HOME>
22         <p>
23         My Path is set to <TMPL_VAR NAME=PATH>
24         </body>
25         </html>
26
27       See HTML::Template::SYNTAX for their syntax.
28
29       Now create a small CGI program:
30
31         #!/usr/bin/perl -w
32         use HTML::Template::Pro;
33
34         # open the html template
35         my $template = HTML::Template::Pro->new(
36               filename => 'test.tmpl',
37               case_sensitive=> 1);
38
39         # fill in some parameters
40         $template->param(HOME => $ENV{HOME});
41         $template->param(PATH => $ENV{PATH});
42
43         # send the obligatory Content-Type and print the template output
44         print "Content-Type: text/html\n\n";
45
46         # print output
47         $template->output(print_to=>\*STDOUT);
48
49         # this would also work.
50         # print $template->output();
51
52         # this would also work. It is faster,
53         # but (WARNING!) not compatible with original HTML::Template.
54         # $template->output();
55
56       If all is well in the universe this should show something like this in
57       your browser when visiting the CGI:
58
59         My Home Directory is /home/some/directory
60         My Path is set to /bin;/usr/bin
61
62       For the best performance it is recommended to use case_sensitive=>1 in
63       new() and print_to=>\*STDOUT in output().
64
65       Note that (HTML::Template::Pro version 0.90+) output(), called in void
66       context, also prints to stdout using built-in htmltmplpro C library
67       calls, so the last call "$template->output();" might be, in fact, the
68       fastest way to call output().
69
70       IMPORTANT NOTE: you can safely write
71
72         my $template = HTML::Template->new( ... options ...)
73               or even
74         my $template = HTML::Template::Expr->new( ... options ...)
75
76       with HTML::Template::Pro, because in absence of original HTML::Template
77       and HTML::Template::Expr HTML::Template::Pro intercepts their calls.
78
79       You can also use all three modules and safely mix their calls
80       (benchmarking may be the only reason for it).  In case you want to mix
81       calls to HTML::Template::Expr and HTML::Template::Pro, the only proper
82       usage of their load is
83
84       use HTML::Template; use HTML::Template::Expr; use HTML::Template::Pro;
85
86       Of course, if you don't plan to mix them (in most cases) it is enough
87       to simply write
88
89       use HTML::Template::Pro;
90
91       Simply use HTML::Template::Pro, it supports all functions of
92       HTML::Template::Expr.
93

DESCRIPTION

95       HTML::Template::Pro is a fast C/perl+XS implementation of
96       HTML::Template and HTML::Template::Expr.  See HTML::Template::Pro for
97       details.
98
99       It fully supports template language of HTML::Template as described in
100       HTML::Template::SYNTAX.
101
102       Briefly,
103
104       "This module attempts to make using HTML templates simple and natural.
105       It extends standard HTML with a few new HTML-esque tags - <TMPL_VAR>,
106       <TMPL_LOOP>, <TMPL_INCLUDE>, <TMPL_IF>, <TMPL_ELSE> and <TMPL_UNLESS>.
107       The file written with HTML and these new tags is called a template.  It
108       is usually saved separate from your script - possibly even created by
109       someone else!  Using this module you fill in the values for the
110       variables, loops and branches declared in the template.  This allows
111       you to separate design - the HTML - from the data, which you generate
112       in the Perl script."
113
114       Here is described a perl interface of HTML::Template::Pro and
115       HTML::Template + HTML::Template::Expr.  See DISTINCTIONS for brief
116       summary of distinctions between HTML::Template::Pro and HTML::Template.
117

METHODS

119   new()
120       Call new() to create a new Template object:
121
122         my $template = HTML::Template->new( filename => 'file.tmpl',
123                                             option => 'value'
124                                           );
125
126       You must call new() with at least one name => value pair specifying how
127       to access the template text.  You can use "filename => 'file.tmpl'" to
128       specify a filename to be opened as the template.  Alternately you can
129       use:
130
131         my $t = HTML::Template->new( scalarref => $ref_to_template_text,
132                                      option => 'value'
133                                    );
134
135       and
136
137         my $t = HTML::Template->new( arrayref => $ref_to_array_of_lines ,
138                                      option => 'value'
139                                    );
140
141       These initialize the template from in-memory resources.  In almost
142       every case you'll want to use the filename parameter.  If you're
143       worried about all the disk access from reading a template file just use
144       mod_perl and the cache option detailed below.
145
146       You can also read the template from an already opened filehandle,
147       either traditionally as a glob or as a FileHandle:
148
149         my $t = HTML::Template->new( filehandle => *FH, option => 'value');
150
151       The four new() calling methods can also be accessed as below, if you
152       prefer.
153
154         my $t = HTML::Template->new_file('file.tmpl', option => 'value');
155
156         my $t = HTML::Template->new_scalar_ref($ref_to_template_text,
157                                               option => 'value');
158
159         my $t = HTML::Template->new_array_ref($ref_to_array_of_lines,
160                                              option => 'value');
161
162         my $t = HTML::Template->new_filehandle($fh,
163                                              option => 'value');
164
165       And as a final option, for those that might prefer it, you can call new
166       as:
167
168         my $t = HTML::Template->new(type => 'filename',
169                                     source => 'file.tmpl');
170
171       Which works for all three of the source types.
172
173       If the environment variable HTML_TEMPLATE_ROOT is set and your filename
174       doesn't begin with /, then the path will be relative to the value of
175       $HTML_TEMPLATE_ROOT.  Example - if the environment variable
176       HTML_TEMPLATE_ROOT is set to "/home/sam" and I call
177       HTML::Template->new() with filename set to "sam.tmpl", the
178       HTML::Template will try to open "/home/sam/sam.tmpl" to access the
179       template file.  You can also affect the search path for files with the
180       "path" option to new() - see below for more information.
181
182       You can modify the Template object's behavior with new().  The options
183       are available:
184
185       Error Detection Options
186           ·   die_on_bad_params - if set to 0 the module will let you call
187               $template->param(param_name => 'value') even if 'param_name'
188               doesn't exist in the template body.  Defaults to 1 in
189               HTML::Template.
190
191               HTML::Template::Pro always use die_on_bad_params => 0.  It
192               currently can't be changed, because HTML::Template::Pro can't
193               know whether a parameter is bad until it finishes output.
194
195               Note that it is wrapper-only option: it is not implemented in
196               the htmltmplpro C library.
197
198           ·   force_untaint - if set to 1 the module will not allow you to
199               set unescaped parameters with tainted values. If set to 2 you
200               will have to untaint all parameters, including ones with the
201               escape attribute.  This option makes sure you untaint
202               everything so you don't accidentally introduce e.g. cross-site-
203               scripting (CSS) vulnerabilities. Requires taint mode. Defaults
204               to 0.
205
206               In the original HTML::Template, if the "force_untaint" option
207               is set an error occurs if you try to set a value that is
208               tainted in the param() call. In HTML::Template::Pro, an error
209               occurs when output is called.
210
211               Note that the tainted value will never be printed; but, to
212               completely suppress output, one should use call to output()
213               that returns string, like print $tmpl->output(); Then output()
214               will die before it returns the string to print.
215
216               Note that it is wrapper-only perl-specific option: it is not
217               implemented in the htmltmplpro C library.
218
219           ·   strict - if set to 0 the module will allow things that look
220               like they might be TMPL_* tags to get by without dieing.
221               Example:
222
223                  <TMPL_HUH NAME=ZUH>
224
225               Would normally cause an error, but if you call new with strict
226               => 0, HTML::Template will ignore it.  Defaults to 1.
227
228               HTML::Template::Pro always implies strict => 0.
229
230       Caching Options
231           HTML::Template use many caching options such as cache,
232           shared_cache, double_cache, blind_cache, file_cache,
233           file_cache_dir, file_cache_dir_mode, double_file_cache to cache
234           preparsed html templates.
235
236           Since HTML::Template::Pro parses and outputs templates at once, it
237           silently ignores those options.
238
239       Filesystem Options
240           ·   path - you can set this variable with a list of paths to search
241               for files specified with the "filename" option to new() and for
242               files included with the <TMPL_INCLUDE> tag.  This list is only
243               consulted when the filename is relative.  The
244               HTML_TEMPLATE_ROOT environment variable is always tried first
245               if it exists.  Also, if HTML_TEMPLATE_ROOT is set then an
246               attempt will be made to prepend HTML_TEMPLATE_ROOT onto paths
247               in the path array.  In the case of a <TMPL_INCLUDE> file, the
248               path to the including file is also tried before path is
249               consulted.
250
251               Example:
252
253                  my $template = HTML::Template->new( filename => 'file.tmpl',
254                                                      path => [ '/path/to/templates',
255                                                                '/alternate/path'
256                                                              ]
257                                                     );
258
259               NOTE: the paths in the path list must be expressed as UNIX
260               paths, separated by the forward-slash character ('/').
261
262           ·   search_path_on_include - if set to a true value the module will
263               search from the top of the array of paths specified by the path
264               option on every <TMPL_INCLUDE> and use the first matching
265               template found.  The normal behavior is to look only in the
266               current directory for a template to include.  Defaults to 0.
267
268       Debugging Options
269           ·   debug - if set to 1 the module will write random debugging
270               information to STDERR.  Defaults to 0.
271
272           ·   HTML::Template use many cache debug options such as
273               stack_debug, cache_debug, shared_cache_debug, memory_debug.
274               Since HTML::Template::Pro parses and outputs templates at once,
275               it silently ignores those options.
276
277       Miscellaneous Options
278           ·   associate - this option allows you to inherit the parameter
279               values from other objects.  The only requirement for the other
280               object is that it have a "param()" method that works like
281               HTML::Template's "param()".  A good candidate would be a CGI.pm
282               query object.  Example:
283
284                 my $query = new CGI;
285                 my $template = HTML::Template->new(filename => 'template.tmpl',
286                                                    associate => $query);
287
288               Now, "$template->output()" will act as though
289
290                 $template->param('FormField', $cgi->param('FormField'));
291
292               had been specified for each key/value pair that would be
293               provided by the "$cgi->param()" method.  Parameters you set
294               directly take precedence over associated parameters.
295
296               You can specify multiple objects to associate by passing an
297               anonymous array to the associate option.  They are searched for
298               parameters in the order they appear:
299
300                 my $template = HTML::Template->new(filename => 'template.tmpl',
301                                                    associate => [$query, $other_obj]);
302
303               NOTE: If the option case_sensitive => 0, the parameter names
304               are matched in a case-insensitive manner.  If you have two
305               parameters in a CGI object like 'NAME' and 'Name' one will be
306               chosen randomly by associate.  This behavior can be changed by
307               setting option case_sensitive to 1.
308
309           ·   case_sensitive - setting this option to true causes
310               HTML::Template to treat template variable names case-
311               sensitively.  The following example would only set one
312               parameter without the "case_sensitive" option:
313
314                 my $template = HTML::Template->new(filename => 'template.tmpl',
315                                                    case_sensitive => 1);
316                 $template->param(
317                   FieldA => 'foo',
318                   fIELDa => 'bar',
319                 );
320
321               This option defaults to off to keep compatibility with
322               HTML::Template.  Nevertheless, setting case_sensitive => 1 is
323               encouraged, because it significantly improves performance.
324
325               If case_sensitive is set to 0, the perl wrapper is forced to
326               lowercase keys in every hash it will find in "param" tree,
327               which is sometimes an expensive operation. To avoid this, set
328               case_sensitive => 1.
329
330               If case conversion is necessary, there is an alternative
331               lightweight option tmpl_var_case, which is HTML::Template::Pro
332               specific.
333
334               Note that case_sensitive is wrapper-only option: it is not
335               implemented in the htmltmplpro C library.
336
337           ·   tmpl_var_case - this option is similar to case_sensitive, but
338               is implemented directly in the htmltmplpro C library.  Instead
339               of converting keys in every hash of "param" tree, it converts
340               the name of variable.
341
342               For example, in case of <tmpl_var name="CamelCaseName"> setting
343               tmpl_var_case = ASK_NAME_AS_IS | ASK_NAME_LOWERCASE |
344               ASK_NAME_UPPERCASE will cause HTML::Template::Pro to look into
345               "param" tree for 3 names: CamelCaseName, camelcasename, and
346               CAMELCASENAME.
347
348               By default, the name is asked "as is".
349
350           ·   loop_context_vars - when this parameter is set to true (it is
351               false by default) four loop context variables are made
352               available inside a loop: __first__, __last__, __inner__,
353               __odd__.  They can be used with <TMPL_IF>, <TMPL_UNLESS> and
354               <TMPL_ELSE> to control how a loop is output.
355
356               In addition to the above, a __counter__ var is also made
357               available when loop context variables are turned on.
358
359               Example:
360
361                  <TMPL_LOOP NAME="FOO">
362                     <TMPL_IF NAME="__first__">
363                       This only outputs on the first pass.
364                     </TMPL_IF>
365
366                     <TMPL_IF NAME="__odd__">
367                       This outputs every other pass, on the odd passes.
368                     </TMPL_IF>
369
370                     <TMPL_UNLESS NAME="__odd__">
371                       This outputs every other pass, on the even passes.
372                     </TMPL_UNLESS>
373
374                     <TMPL_IF NAME="__inner__">
375                       This outputs on passes that are neither first nor last.
376                     </TMPL_IF>
377
378                     This is pass number <TMPL_VAR NAME="__counter__">.
379
380                     <TMPL_IF NAME="__last__">
381                       This only outputs on the last pass.
382                     </TMPL_IF>
383                  </TMPL_LOOP>
384
385               One use of this feature is to provide a "separator" similar in
386               effect to the perl function join().  Example:
387
388                  <TMPL_LOOP FRUIT>
389                     <TMPL_IF __last__> and </TMPL_IF>
390                     <TMPL_VAR KIND><TMPL_UNLESS __last__>, <TMPL_ELSE>.</TMPL_UNLESS>
391                  </TMPL_LOOP>
392
393               Would output (in a browser) something like:
394
395                 Apples, Oranges, Brains, Toes, and Kiwi.
396
397               Given an appropriate "param()" call, of course.  NOTE: A loop
398               with only a single pass will get both __first__ and __last__
399               set to true, but not __inner__.
400
401               NOTE: in the original HTML::Template with case_sensitive = 1
402               and loop_context_vars the special loop variables are available
403               in lower-case only.  In HTML::Template::Pro they are recognized
404               regardless of case.
405
406           ·   no_includes - set this option to 1 to disallow the
407               <TMPL_INCLUDE> tag in the template file.  This can be used to
408               make opening untrusted templates slightly less dangerous.
409               Defaults to 0.
410
411           ·   max_includes - set this variable to determine the maximum depth
412               that includes can reach.  Set to 10 by default.  Including
413               files to a depth greater than this value causes an error
414               message to be displayed.  Set to 0 to disable this protection.
415
416           ·   global_vars - normally variables declared outside a loop are
417               not available inside a loop.  This option makes <TMPL_VAR>s
418               like global variables in Perl - they have unlimited scope.
419               This option also affects <TMPL_IF> and <TMPL_UNLESS>.
420
421               Example:
422
423                 This is a normal variable: <TMPL_VAR NORMAL>.<P>
424
425                 <TMPL_LOOP NAME=FROOT_LOOP>
426                    Here it is inside the loop: <TMPL_VAR NORMAL><P>
427                 </TMPL_LOOP>
428
429               Normally this wouldn't work as expected, since <TMPL_VAR
430               NORMAL>'s value outside the loop is not available inside the
431               loop.
432
433               The global_vars option also allows you to access the values of
434               an enclosing loop within an inner loop.  For example, in this
435               loop the inner loop will have access to the value of OUTER_VAR
436               in the correct iteration:
437
438                  <TMPL_LOOP OUTER_LOOP>
439                     OUTER: <TMPL_VAR OUTER_VAR>
440                       <TMPL_LOOP INNER_LOOP>
441                          INNER: <TMPL_VAR INNER_VAR>
442                          INSIDE OUT: <TMPL_VAR OUTER_VAR>
443                       </TMPL_LOOP>
444                  </TMPL_LOOP>
445
446               NOTE: "global_vars" is not "global_loops" (which does not
447               exist).  That means that loops you declare at one scope are not
448               available inside other loops even when "global_vars" is on.
449
450           ·   path_like_variable_scope - this option switches on a Shigeki
451               Morimoto extension to HTML::Template::Pro that allows access to
452               variables that are outside the current loop scope using path-
453               like expressions.
454
455               Example: {{{ <TMPL_LOOP NAME=class>
456                 <TMPL_LOOP NAME=person>
457                   <TMPL_VAR NAME="../teacher_name">  <!-- access to
458               class.teacher_name -->
459                   <TMPL_VAR NAME="name">
460                   <TMPL_VAR NAME="/top_level_value"> <!-- access to top level
461               value -->
462                   <TMPL_VAR NAME="age">
463                     <TMPL_LOOP NAME="../../school">  <!-- enter loop before
464               accessing its vars -->
465                       <TMPL_VAR NAME="school_name">  <!-- access to
466               [../../]school.school_name -->
467                     </TMPL_LOOP>
468                 </TMPL_LOOP> </TMPL_LOOP> }}}
469
470           ·   filter - this option allows you to specify a filter for your
471               template files.  A filter is a subroutine that will be called
472               after HTML::Template reads your template file but before it
473               starts parsing template tags.
474
475               In the most simple usage, you simply assign a code reference to
476               the filter parameter.  This subroutine will receive a single
477               argument - a reference to a string containing the template file
478               text.  Here is an example that accepts templates with tags that
479               look like "!!!ZAP_VAR FOO!!!" and transforms them into
480               HTML::Template tags:
481
482                  my $filter = sub {
483                    my $text_ref = shift;
484                    $$text_ref =~ s/!!!ZAP_(.*?)!!!/<TMPL_$1>/g;
485                  };
486
487                  # open zap.tmpl using the above filter
488                  my $template = HTML::Template->new(filename => 'zap.tmpl',
489                                                     filter => $filter);
490
491               More complicated usages are possible.  You can request that
492               your filter receive the template text as an array of lines
493               rather than as a single scalar.  To do that you need to specify
494               your filter using a hash-ref.  In this form you specify the
495               filter using the "sub" key and the desired argument format
496               using the "format" key.  The available formats are "scalar" and
497               "array".  Using the "array" format will incur a performance
498               penalty but may be more convenient in some situations.
499
500                  my $template = HTML::Template->new(filename => 'zap.tmpl',
501                                                     filter => { sub => $filter,
502                                                                 format => 'array' });
503
504               You may also have multiple filters.  This allows simple filters
505               to be combined for more elaborate functionality.  To do this
506               you specify an array of filters.  The filters are applied in
507               the order they are specified.
508
509                  my $template = HTML::Template->new(filename => 'zap.tmpl',
510                                                     filter => [
511                                                          { sub => \&decompress,
512                                                            format => 'scalar' },
513                                                          { sub => \&remove_spaces,
514                                                            format => 'array' }
515                                                       ]);
516
517               The specified filters will be called for any TMPL_INCLUDEed
518               files just as they are for the main template file.
519
520           ·   default_escape - Set this parameter to "HTML", "URL" or "JS"
521               and HTML::Template will apply the specified escaping to all
522               variables unless they declare a different escape in the
523               template.
524
525   param()
526       "param()" can be called in a number of ways
527
528       1) To return a list of parameters in the template :
529          ( this features is distinct in HTML::Template::Pro:
530          it returns a list of parameters _SET_ after new() )
531
532          my @parameter_names = $self->param();
533
534       2) To return the value set to a param :
535
536          my $value = $self->param('PARAM');
537
538       3) To set the value of a parameter :
539
540             # For simple TMPL_VARs:
541             $self->param(PARAM => 'value');
542
543             # with a subroutine reference that gets called to get the value
544             # of the scalar.  The sub will receive the template object as a
545             # parameter.
546             $self->param(PARAM => sub { return 'value' });
547
548             # And TMPL_LOOPs:
549             $self->param(LOOP_PARAM =>
550                          [
551                           { PARAM => VALUE_FOR_FIRST_PASS, ... },
552                           { PARAM => VALUE_FOR_SECOND_PASS, ... }
553                           ...
554                          ]
555                         );
556
557       4) To set the value of a a number of parameters :
558
559            # For simple TMPL_VARs:
560            $self->param(PARAM => 'value',
561                         PARAM2 => 'value'
562                        );
563
564             # And with some TMPL_LOOPs:
565             $self->param(PARAM => 'value',
566                          PARAM2 => 'value',
567                          LOOP_PARAM =>
568                          [
569                           { PARAM => VALUE_FOR_FIRST_PASS, ... },
570                           { PARAM => VALUE_FOR_SECOND_PASS, ... }
571                           ...
572                          ],
573                          ANOTHER_LOOP_PARAM =>
574                          [
575                           { PARAM => VALUE_FOR_FIRST_PASS, ... },
576                           { PARAM => VALUE_FOR_SECOND_PASS, ... }
577                           ...
578                          ]
579                         );
580
581       5) To set the value of a a number of parameters using a hash-ref :
582
583             $self->param(
584                          {
585                             PARAM => 'value',
586                             PARAM2 => 'value',
587                             LOOP_PARAM =>
588                             [
589                               { PARAM => VALUE_FOR_FIRST_PASS, ... },
590                               { PARAM => VALUE_FOR_SECOND_PASS, ... }
591                               ...
592                             ],
593                             ANOTHER_LOOP_PARAM =>
594                             [
595                               { PARAM => VALUE_FOR_FIRST_PASS, ... },
596                               { PARAM => VALUE_FOR_SECOND_PASS, ... }
597                               ...
598                             ]
599                           }
600                          );
601
602   clear_params()
603       Sets all the parameters to undef.  Useful internally, if nowhere else!
604
605   output()
606       output() returns the final result of the template.  In most situations
607       you'll want to print this, like:
608
609          print $template->output();
610
611       When output is called each occurrence of <TMPL_VAR NAME=name> is
612       replaced with the value assigned to "name" via "param()".  If a named
613       parameter is unset it is simply replaced with ''.  <TMPL_LOOPS> are
614       evaluated once per parameter set, accumulating output on each pass.
615
616       Calling output() is guaranteed not to change the state of the Template
617       object, in case you were wondering.  This property is mostly important
618       for the internal implementation of loops.
619
620       You may optionally supply a filehandle to print to automatically as the
621       template is generated.  This may improve performance and lower memory
622       consumption.  Example:
623
624          $template->output(print_to => *STDOUT);
625
626       The return value is undefined when using the "print_to" option.
627
628   query()
629       This method is not supported in HTML::Template::Pro.
630

DISTINCTIONS AND INCOMPATIBILITIES

632       The main reason for small incompatibilities between HTML::Template and
633       HTML::Template::Pro is the fact that HTML::Template builds parsed tree
634       of template before anything else. So it has an additional information
635       which HTML::Template::Pro obtains during output.
636
637       In cases when HTML::Template dies, such as no_includes, bad syntax of
638       template, max_includes and so on, HTML::Template::Pro issues warning to
639       STDERR and continue.
640
641   new()
642       the following options are not supported in HTML::Template::Pro:
643
644        vanguard_compatibility_mode.
645
646       The options die_on_bad_params and strict are ignored.
647       HTML::Template::Pro behaves itself as HTML::Template called with
648        die_on_bad_params => 0, strict => 0.
649
650       It currently can't be changed, because HTML::Template::Pro can't know
651       whether a parameter is bad before it start output.  This may change in
652       future releases.
653
654       To keep backward compatibility with HTML::Template, you should
655       explicitly call its new() with die_on_bad_params => 0, strict => 0.
656
657   query()
658       This method is not supported in HTML::Template::Pro.
659
660   param()
661       param() without arguments should return a list of parameters in the
662       template.  In HTML::Template::Pro it returns a list of parameters set
663       after new().
664

BUGS

666       With case_sensitive and loop_context_vars the special loop variables
667       should be available in lower-case only.
668
669       associate is case_sensitive inside loops.
670
671       When submitting bug reports, be sure to include full details, including
672       the VERSION of the module, a test script and a test template
673       demonstrating the problem!
674

EXPR: DEFINING NEW FUNCTIONS

676       To define a new function, pass a "functions" option to new:
677
678         $t = HTML::Template::Pro->new(filename => 'foo.tmpl',
679                                        functions =>
680                                          { func_name => \&func_handler });
681       or
682
683         $t = HTML::Template::Expr->new(filename => 'foo.tmpl',
684                                        functions =>
685                                          { func_name => \&func_handler });
686
687       Or, you can use "register_function" class method to register the
688       function globally:
689
690         HTML::Template::Pro->register_function(func_name => \&func_handler);
691       or
692         HTML::Template::Expr->register_function(func_name => \&func_handler);
693
694       You provide a subroutine reference that will be called during output.
695       It will receive as arguments the parameters specified in the template.
696       For example, here's a function that checks if a directory exists:
697
698         sub directory_exists {
699           my $dir_name = shift;
700           return 1 if -d $dir_name;
701           return 0;
702         }
703
704       If you call HTML::Template::Expr->new() with a "functions" arg:
705
706         $t = HTML::Template::Expr->new(filename => 'foo.tmpl',
707                                        functions => {
708                                           directory_exists => \&directory_exists
709                                        });
710
711       Then you can use it in your template:
712
713         <tmpl_if expr="directory_exists('/home/sam')">
714
715       This can be abused in ways that make my teeth hurt.
716
717   register_function() extended usage (HTML::Template::Pro specific)
718       "register_function()" can be called in a number of ways
719
720       1) To fetch the names of registered functions in the template:
721
722       ·   if "register_function()" was called in a newly created object it
723           returns a
724
725              list of function's that set _after_ or _in_ new():
726
727              my @registered_functions_names = $self->register_function();
728
729       ·   in global context "register_function()" will return a list of _ALL_
730              avalible function's
731
732              my @all_avalible_functions_names =
733           HTML::Template::Pro->register_function();
734
735           2) To fetching the function by name:
736
737              my $function = $self->register_function('FUNCTION_NAME');
738
739           3) To set a new function:
740
741               # Set function, that can be called in templates, wich are processed
742               # by the current object:
743               $self->register_function(foozicate => sub { ... });
744
745               # Set global function:
746               HTML::Template::Pro->register_function(barify    => sub { ... });
747
748       for details of "how to defined a function" see in "EXPR: DEFINING NEW
749       FUNCTIONS".
750

EXPR MOD_PERL TIP

752       "register_function" class method can be called in mod_perl's startup.pl
753       to define widely used common functions to HTML::Template::Expr. Add
754       something like this to your startup.pl:
755
756         use HTML::Template::Pro;
757
758         HTML::Template::Pro->register_function(foozicate => sub { ... });
759         HTML::Template::Pro->register_function(barify    => sub { ... });
760         HTML::Template::Pro->register_function(baznate   => sub { ... });
761

EXPR CAVEATS

763       HTML::Template::Pro does not forces the HTML::Template global_vars
764       option to be set, whereas currently HTML::Template::Expr does.  Anyway,
765       this also will hopefully go away in a future version of
766       HTML::Template::Expr, so if you need global_vars in your templates then
767       you should set it explicitly.
768

CREDITS

770       to Sam Tregar, sam@tregar.com
771
772       Original credits of HTML::Template:
773
774       This module was the brain child of my boss, Jesse Erlbaum (
775       jesse@vm.com ) at Vanguard Media ( http://vm.com ) .  The most original
776       idea in this module - the <TMPL_LOOP> - was entirely his.
777
778       Fixes, Bug Reports, Optimizations and Ideas have been generously
779       provided by:
780
781          Richard Chen
782          Mike Blazer
783          Adriano Nagelschmidt Rodrigues
784          Andrej Mikus
785          Ilya Obshadko
786          Kevin Puetz
787          Steve Reppucci
788          Richard Dice
789          Tom Hukins
790          Eric Zylberstejn
791          David Glasser
792          Peter Marelas
793          James William Carlson
794          Frank D. Cringle
795          Winfried Koenig
796          Matthew Wickline
797          Doug Steinwand
798          Drew Taylor
799          Tobias Brox
800          Michael Lloyd
801          Simran Gambhir
802          Chris Houser <chouser@bluweb.com>
803          Larry Moore
804          Todd Larason
805          Jody Biggs
806          T.J. Mather
807          Martin Schroth
808          Dave Wolfe
809          uchum
810          Kawai Takanori
811          Peter Guelich
812          Chris Nokleberg
813          Ralph Corderoy
814          William Ward
815          Ade Olonoh
816          Mark Stosberg
817          Lance Thomas
818          Roland Giersig
819          Jere Julian
820          Peter Leonard
821          Kenny Smith
822          Sean P. Scanlon
823          Martin Pfeffer
824          David Ferrance
825          Gyepi Sam
826          Darren Chamberlain
827          Paul Baker
828          Gabor Szabo
829          Craig Manley
830          Richard Fein
831          The Phalanx Project
832          Sven Neuhaus
833
834       Thanks!
835
836       Original credits of HTML::Template::Expr:
837
838       The following people have generously submitted bug reports, patches and
839       ideas:
840
841          Peter Leonard
842          Tatsuhiko Miyagawa
843
844       Thanks!
845

WEBSITE

847       You can find information about HTML::Template::Pro at:
848
849          http://html-tmpl-pro.sourceforge.net
850
851       You can find information about HTML::Template and other related modules
852       at:
853
854          http://html-template.sourceforge.net
855

AUTHOR

857       Sam Tregar, sam@tregar.com (Main text)
858
859       I. Vlasenko, <viy@altlinux.org> (Pecularities of HTML::Template::Pro)
860

LICENSE

862         HTML::Template : A module for using HTML Templates with Perl
863         Copyright (C) 2000-2002 Sam Tregar (sam@tregar.com)
864
865         This module is free software; you can redistribute it and/or modify it
866         under the terms of either:
867
868         a) the GNU General Public License as published by the Free Software
869         Foundation; either version 1, or (at your option) any later version,
870
871         or
872
873         b) the "Artistic License" which comes with this module.
874
875         This program is distributed in the hope that it will be useful,
876         but WITHOUT ANY WARRANTY; without even the implied warranty of
877         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See either
878         the GNU General Public License or the Artistic License for more details.
879
880         You should have received a copy of the Artistic License with this
881         module, in the file ARTISTIC.  If not, I'll be glad to provide one.
882
883         You should have received a copy of the GNU General Public License
884         along with this program; if not, write to the Free Software
885         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
886         USA
887
888
889
890perl v5.28.1                      2013-05-13  HTML::Template::PerlInterface(3)
Impressum