/usr/lib/perl5/HTML/Template/PerlInterface.pod is in libhtml-template-pro-perl 0.9510-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 | =head1 NAME
HTML::Template::PerlInterface - perl interface of HTML::Template::Pro
=head1 SYNOPSIS
This help is only on perl interface of HTML::Template::Pro.
For syntax of html template files you should see
L<HTML::Template::SYNTAX/SYNOPSIS>.
First you make a template - this is just a normal HTML file with a few
extra tags, the simplest being <TMPL_VAR>
For example, test.tmpl:
<html>
<head><title>Test Template</title>
<body>
My Home Directory is <TMPL_VAR NAME=HOME>
<p>
My Path is set to <TMPL_VAR NAME=PATH>
</body>
</html>
See L<HTML::Template::SYNTAX|HTML::Template::SYNTAX> for their syntax.
Now create a small CGI program:
#!/usr/bin/perl -w
use HTML::Template::Pro;
# open the html template
my $template = HTML::Template::Pro->new(
filename => 'test.tmpl',
case_sensitive=> 1);
# fill in some parameters
$template->param(HOME => $ENV{HOME});
$template->param(PATH => $ENV{PATH});
# send the obligatory Content-Type and print the template output
print "Content-Type: text/html\n\n";
# print output
$template->output(print_to=>\*STDOUT);
# this would also work.
# print $template->output();
# this would also work. It is faster,
# but (WARNING!) not compatible with original HTML::Template.
# $template->output();
If all is well in the universe this should show something like this in
your browser when visiting the CGI:
My Home Directory is /home/some/directory
My Path is set to /bin;/usr/bin
For the best performance it is recommended to use
case_sensitive=>1 in new()
and print_to=>\*STDOUT in output().
Note that (HTML::Template::Pro version 0.90+)
output(), called in void context, also prints to stdout
using built-in htmltmplpro C library calls, so the last call
"$template->output();"
might be, in fact, the fastest way to call output().
IMPORTANT NOTE: you can safely write
my $template = HTML::Template->new( ... options ...)
or even
my $template = HTML::Template::Expr->new( ... options ...)
with HTML::Template::Pro, because in absence of original HTML::Template
and HTML::Template::Expr HTML::Template::Pro intercepts their calls.
You can also use all three modules and safely mix their calls
(benchmarking may be the only reason for it).
In case you want to mix calls to HTML::Template::Expr and
HTML::Template::Pro, the only proper usage of their load is
use HTML::Template;
use HTML::Template::Expr;
use HTML::Template::Pro;
Of course, if you don't plan to mix them (in most cases)
it is enough to simply write
use HTML::Template::Pro;
Simply use HTML::Template::Pro,
it supports all functions of HTML::Template::Expr.
=head1 DESCRIPTION
HTML::Template::Pro is a fast C/perl+XS implementation of HTML::Template
and HTML::Template::Expr.
See L<HTML::Template::Pro|HTML::Template::Pro> for details.
It fully supports template language of HTML::Template
as described in L<HTML::Template::SYNTAX|HTML::Template::SYNTAX>.
Briefly,
"This module attempts to make using HTML templates simple and natural.
It extends standard HTML with a few new HTML-esque tags - <TMPL_VAR>,
<TMPL_LOOP>, <TMPL_INCLUDE>, <TMPL_IF>, <TMPL_ELSE> and <TMPL_UNLESS>.
The file written with HTML and these new tags is called a template.
It is usually saved separate from your script - possibly even created
by someone else! Using this module you fill in the values for the
variables, loops and branches declared in the template. This allows
you to separate design - the HTML - from the data, which you generate
in the Perl script."
Here is described a perl interface of HTML::Template::Pro and
HTML::Template + HTML::Template::Expr.
See B<DISTINCTIONS> for brief summary of distinctions between
HTML::Template::Pro and HTML::Template.
=head1 METHODS
=head2 new()
Call new() to create a new Template object:
my $template = HTML::Template->new( filename => 'file.tmpl',
option => 'value'
);
You must call new() with at least one name => value pair specifying how
to access the template text. You can use C<< filename => 'file.tmpl' >>
to specify a filename to be opened as the template. Alternately you can
use:
my $t = HTML::Template->new( scalarref => $ref_to_template_text,
option => 'value'
);
and
my $t = HTML::Template->new( arrayref => $ref_to_array_of_lines ,
option => 'value'
);
These initialize the template from in-memory resources. In almost
every case you'll want to use the filename parameter. If you're
worried about all the disk access from reading a template file just
use mod_perl and the cache option detailed below.
You can also read the template from an already opened filehandle,
either traditionally as a glob or as a FileHandle:
my $t = HTML::Template->new( filehandle => *FH, option => 'value');
The four new() calling methods can also be accessed as below, if you
prefer.
my $t = HTML::Template->new_file('file.tmpl', option => 'value');
my $t = HTML::Template->new_scalar_ref($ref_to_template_text,
option => 'value');
my $t = HTML::Template->new_array_ref($ref_to_array_of_lines,
option => 'value');
my $t = HTML::Template->new_filehandle($fh,
option => 'value');
And as a final option, for those that might prefer it, you can call new as:
my $t = HTML::Template->new(type => 'filename',
source => 'file.tmpl');
Which works for all three of the source types.
If the environment variable HTML_TEMPLATE_ROOT is set and your
filename doesn't begin with /, then the path will be relative to the
value of $HTML_TEMPLATE_ROOT. Example - if the environment variable
HTML_TEMPLATE_ROOT is set to "/home/sam" and I call
HTML::Template->new() with filename set to "sam.tmpl", the
HTML::Template will try to open "/home/sam/sam.tmpl" to access the
template file. You can also affect the search path for files with the
"path" option to new() - see below for more information.
You can modify the Template object's behavior with new(). The options
are available:
=over 4
=item Error Detection Options
=over 4
=item *
die_on_bad_params - if set to 0 the module will let you call
$template->param(param_name => 'value') even if 'param_name' doesn't
exist in the template body. Defaults to 1 in HTML::Template.
HTML::Template::Pro always use die_on_bad_params => 0.
It currently can't be changed, because HTML::Template::Pro can't
know whether a parameter is bad until it finishes output.
Note that it is wrapper-only option: it is not implemented
in the htmltmplpro C library.
=item *
force_untaint - if set to 1 the module will not allow you to set
unescaped parameters with tainted values. If set to 2 you will have
to untaint all parameters, including ones with the escape attribute.
This option makes sure you untaint everything so you don't accidentally
introduce e.g. cross-site-scripting (CSS) vulnerabilities. Requires
taint mode. Defaults to 0.
In the original HTML::Template, if the "force_untaint" option is set
an error occurs if you try to set a value that is tainted in the param()
call. In HTML::Template::Pro, an error occurs when output is called.
Note that the tainted value will never be printed; but, to completely
suppress output, one should use call to output() that returns string,
like
print $tmpl->output();
Then output() will die before it returns the string to print.
Note that it is wrapper-only perl-specific option: it is not
implemented in the htmltmplpro C library.
=item *
strict - if set to 0 the module will allow things that look like they
might be TMPL_* tags to get by without dieing. Example:
<TMPL_HUH NAME=ZUH>
Would normally cause an error, but if you call new with strict => 0,
HTML::Template will ignore it. Defaults to 1.
HTML::Template::Pro always implies strict => 0.
=begin comment
=item *
vanguard_compatibility_mode - if set to 1 the module will expect to
see <TMPL_VAR>s that look like %NAME% in addition to the standard
syntax. Also sets die_on_bad_params => 0. If you're not at Vanguard
Media trying to use an old format template don't worry about this one.
Defaults to 0.
vanguard_compatibility_mode is not supported in HTML::Template::Pro.
=end comment
=back
=item Caching Options
HTML::Template use many caching options such as
cache, shared_cache, double_cache, blind_cache, file_cache,
file_cache_dir, file_cache_dir_mode, double_file_cache
to cache preparsed html templates.
Since HTML::Template::Pro parses and outputs templates at once,
it silently ignores those options.
=item Filesystem Options
=over 4
=item *
path - you can set this variable with a list of paths to search for
files specified with the "filename" option to new() and for files
included with the <TMPL_INCLUDE> tag. This list is only consulted
when the filename is relative. The HTML_TEMPLATE_ROOT environment
variable is always tried first if it exists. Also, if
HTML_TEMPLATE_ROOT is set then an attempt will be made to prepend
HTML_TEMPLATE_ROOT onto paths in the path array. In the case of a
<TMPL_INCLUDE> file, the path to the including file is also tried
before path is consulted.
Example:
my $template = HTML::Template->new( filename => 'file.tmpl',
path => [ '/path/to/templates',
'/alternate/path'
]
);
NOTE: the paths in the path list must be expressed as UNIX paths,
separated by the forward-slash character ('/').
=item *
search_path_on_include - if set to a true value the module will search
from the top of the array of paths specified by the path option on
every <TMPL_INCLUDE> and use the first matching template found. The
normal behavior is to look only in the current directory for a
template to include. Defaults to 0.
=back
=item Debugging Options
=over 4
=item *
debug - if set to 1 the module will write random debugging information
to STDERR. Defaults to 0.
=item *
HTML::Template use many cache debug options such as
stack_debug, cache_debug, shared_cache_debug, memory_debug.
Since HTML::Template::Pro parses and outputs templates at once,
it silently ignores those options.
=back
=item Miscellaneous Options
=over 4
=item *
associate - this option allows you to inherit the parameter values
from other objects. The only requirement for the other object is that
it have a C<param()> method that works like HTML::Template's C<param()>. A
good candidate would be a CGI.pm query object. Example:
my $query = new CGI;
my $template = HTML::Template->new(filename => 'template.tmpl',
associate => $query);
Now, C<< $template->output() >> will act as though
$template->param('FormField', $cgi->param('FormField'));
had been specified for each key/value pair that would be provided by
the C<< $cgi->param() >> method. Parameters you set directly take
precedence over associated parameters.
You can specify multiple objects to associate by passing an anonymous
array to the associate option. They are searched for parameters in
the order they appear:
my $template = HTML::Template->new(filename => 'template.tmpl',
associate => [$query, $other_obj]);
=begin comment
The old associateCGI() call is still supported, but should be
considered obsolete.
=end comment
NOTE: If the option case_sensitive => 0,
the parameter names are matched in a case-insensitive manner. If
you have two parameters in a CGI object like 'NAME' and 'Name' one
will be chosen randomly by associate. This behavior can be changed by
setting option case_sensitive to 1.
=item *
case_sensitive - setting this option to true causes HTML::Template to
treat template variable names case-sensitively. The following example
would only set one parameter without the "case_sensitive" option:
my $template = HTML::Template->new(filename => 'template.tmpl',
case_sensitive => 1);
$template->param(
FieldA => 'foo',
fIELDa => 'bar',
);
This option defaults to off to keep compatibility with HTML::Template.
Nevertheless, setting case_sensitive => 1 is encouraged, because
it significantly improves performance.
If case_sensitive is set to 0, the perl wrapper is forced to lowercase
keys in every hash it will find in "param" tree, which is sometimes
an expensive operation. To avoid this, set case_sensitive => 1.
If case conversion is necessary, there is an alternative lightweight
option tmpl_var_case, which is HTML::Template::Pro specific.
Note that case_sensitive is wrapper-only option: it is not implemented
in the htmltmplpro C library.
=item *
tmpl_var_case - this option is similar to case_sensitive, but is
implemented directly in the htmltmplpro C library.
Instead of converting keys in every hash of "param" tree, it
converts the name of variable.
For example, in case of <tmpl_var name="CamelCaseName"> setting
tmpl_var_case = ASK_NAME_AS_IS | ASK_NAME_LOWERCASE | ASK_NAME_UPPERCASE
will cause HTML::Template::Pro to look into "param" tree for 3 names:
CamelCaseName, camelcasename, and CAMELCASENAME.
By default, the name is asked "as is".
=item *
loop_context_vars - when this parameter is set to true (it is false by
default) four loop context variables are made available inside a loop:
__first__, __last__, __inner__, __odd__. They can be used with
<TMPL_IF>, <TMPL_UNLESS> and <TMPL_ELSE> to control how a loop is
output.
In addition to the above, a __counter__ var is also made available
when loop context variables are turned on.
Example:
<TMPL_LOOP NAME="FOO">
<TMPL_IF NAME="__first__">
This only outputs on the first pass.
</TMPL_IF>
<TMPL_IF NAME="__odd__">
This outputs every other pass, on the odd passes.
</TMPL_IF>
<TMPL_UNLESS NAME="__odd__">
This outputs every other pass, on the even passes.
</TMPL_UNLESS>
<TMPL_IF NAME="__inner__">
This outputs on passes that are neither first nor last.
</TMPL_IF>
This is pass number <TMPL_VAR NAME="__counter__">.
<TMPL_IF NAME="__last__">
This only outputs on the last pass.
</TMPL_IF>
</TMPL_LOOP>
One use of this feature is to provide a "separator" similar in effect
to the perl function join(). Example:
<TMPL_LOOP FRUIT>
<TMPL_IF __last__> and </TMPL_IF>
<TMPL_VAR KIND><TMPL_UNLESS __last__>, <TMPL_ELSE>.</TMPL_UNLESS>
</TMPL_LOOP>
Would output (in a browser) something like:
Apples, Oranges, Brains, Toes, and Kiwi.
Given an appropriate C<param()> call, of course. NOTE: A loop with only
a single pass will get both __first__ and __last__ set to true, but
not __inner__.
NOTE: in the original HTML::Template with case_sensitive = 1 and loop_context_vars
the special loop variables are available in lower-case only.
In HTML::Template::Pro they are recognized regardless of case.
=item *
no_includes - set this option to 1 to disallow the <TMPL_INCLUDE> tag
in the template file. This can be used to make opening untrusted
templates B<slightly> less dangerous. Defaults to 0.
=item *
max_includes - set this variable to determine the maximum depth that
includes can reach. Set to 10 by default. Including files to a depth
greater than this value causes an error message to be displayed. Set
to 0 to disable this protection.
=item *
global_vars - normally variables declared outside a loop are not
available inside a loop. This option makes <TMPL_VAR>s like global
variables in Perl - they have unlimited scope. This option also
affects <TMPL_IF> and <TMPL_UNLESS>.
Example:
This is a normal variable: <TMPL_VAR NORMAL>.<P>
<TMPL_LOOP NAME=FROOT_LOOP>
Here it is inside the loop: <TMPL_VAR NORMAL><P>
</TMPL_LOOP>
Normally this wouldn't work as expected, since <TMPL_VAR NORMAL>'s
value outside the loop is not available inside the loop.
The global_vars option also allows you to access the values of an
enclosing loop within an inner loop. For example, in this loop the
inner loop will have access to the value of OUTER_VAR in the correct
iteration:
<TMPL_LOOP OUTER_LOOP>
OUTER: <TMPL_VAR OUTER_VAR>
<TMPL_LOOP INNER_LOOP>
INNER: <TMPL_VAR INNER_VAR>
INSIDE OUT: <TMPL_VAR OUTER_VAR>
</TMPL_LOOP>
</TMPL_LOOP>
B<NOTE>: C<global_vars> is not C<global_loops> (which does not exist).
That means that loops you declare at one scope are not available
inside other loops even when C<global_vars> is on.
=item *
path_like_variable_scope - this option switches on a Shigeki Morimoto
extension to HTML::Template::Pro that allows access to variables that
are outside the current loop scope using path-like expressions.
Example:
{{{
<TMPL_LOOP NAME=class>
<TMPL_LOOP NAME=person>
<TMPL_VAR NAME="../teacher_name"> <!-- access to class.teacher_name -->
<TMPL_VAR NAME="name">
<TMPL_VAR NAME="/top_level_value"> <!-- access to top level value -->
<TMPL_VAR NAME="age">
<TMPL_LOOP NAME="../../school"> <!-- enter loop before accessing its vars -->
<TMPL_VAR NAME="school_name"> <!-- access to [../../]school.school_name -->
</TMPL_LOOP>
</TMPL_LOOP>
</TMPL_LOOP>
}}}
=item *
filter - this option allows you to specify a filter for your template
files. A filter is a subroutine that will be called after
HTML::Template reads your template file but before it starts parsing
template tags.
In the most simple usage, you simply assign a code reference to the
filter parameter. This subroutine will receive a single argument - a
reference to a string containing the template file text. Here is an
example that accepts templates with tags that look like "!!!ZAP_VAR
FOO!!!" and transforms them into HTML::Template tags:
my $filter = sub {
my $text_ref = shift;
$$text_ref =~ s/!!!ZAP_(.*?)!!!/<TMPL_$1>/g;
};
# open zap.tmpl using the above filter
my $template = HTML::Template->new(filename => 'zap.tmpl',
filter => $filter);
More complicated usages are possible. You can request that your
filter receive the template text as an array of lines rather than as
a single scalar. To do that you need to specify your filter using a
hash-ref. In this form you specify the filter using the C<sub> key and
the desired argument format using the C<format> key. The available
formats are C<scalar> and C<array>. Using the C<array> format will incur
a performance penalty but may be more convenient in some situations.
my $template = HTML::Template->new(filename => 'zap.tmpl',
filter => { sub => $filter,
format => 'array' });
You may also have multiple filters. This allows simple filters to be
combined for more elaborate functionality. To do this you specify an
array of filters. The filters are applied in the order they are
specified.
my $template = HTML::Template->new(filename => 'zap.tmpl',
filter => [
{ sub => \&decompress,
format => 'scalar' },
{ sub => \&remove_spaces,
format => 'array' }
]);
The specified filters will be called for any TMPL_INCLUDEed files just
as they are for the main template file.
=item *
default_escape - Set this parameter to "HTML", "URL" or "JS" and
HTML::Template will apply the specified escaping to all variables
unless they declare a different escape in the template.
=back
=back
=cut
=head2 param()
C<param()> can be called in a number of ways
1) To return a list of parameters in the template :
( this features is distinct in HTML::Template::Pro:
it returns a list of parameters _SET_ after new() )
my @parameter_names = $self->param();
2) To return the value set to a param :
my $value = $self->param('PARAM');
3) To set the value of a parameter :
# For simple TMPL_VARs:
$self->param(PARAM => 'value');
# with a subroutine reference that gets called to get the value
# of the scalar. The sub will receive the template object as a
# parameter.
$self->param(PARAM => sub { return 'value' });
# And TMPL_LOOPs:
$self->param(LOOP_PARAM =>
[
{ PARAM => VALUE_FOR_FIRST_PASS, ... },
{ PARAM => VALUE_FOR_SECOND_PASS, ... }
...
]
);
4) To set the value of a a number of parameters :
# For simple TMPL_VARs:
$self->param(PARAM => 'value',
PARAM2 => 'value'
);
# And with some TMPL_LOOPs:
$self->param(PARAM => 'value',
PARAM2 => 'value',
LOOP_PARAM =>
[
{ PARAM => VALUE_FOR_FIRST_PASS, ... },
{ PARAM => VALUE_FOR_SECOND_PASS, ... }
...
],
ANOTHER_LOOP_PARAM =>
[
{ PARAM => VALUE_FOR_FIRST_PASS, ... },
{ PARAM => VALUE_FOR_SECOND_PASS, ... }
...
]
);
5) To set the value of a a number of parameters using a hash-ref :
$self->param(
{
PARAM => 'value',
PARAM2 => 'value',
LOOP_PARAM =>
[
{ PARAM => VALUE_FOR_FIRST_PASS, ... },
{ PARAM => VALUE_FOR_SECOND_PASS, ... }
...
],
ANOTHER_LOOP_PARAM =>
[
{ PARAM => VALUE_FOR_FIRST_PASS, ... },
{ PARAM => VALUE_FOR_SECOND_PASS, ... }
...
]
}
);
=cut
=pod
=head2 clear_params()
Sets all the parameters to undef. Useful internally, if nowhere else!
=head2 output()
output() returns the final result of the template. In most situations
you'll want to print this, like:
print $template->output();
When output is called each occurrence of <TMPL_VAR NAME=name> is
replaced with the value assigned to "name" via C<param()>. If a named
parameter is unset it is simply replaced with ''. <TMPL_LOOPS> are
evaluated once per parameter set, accumulating output on each pass.
Calling output() is guaranteed not to change the state of the
Template object, in case you were wondering. This property is mostly
important for the internal implementation of loops.
You may optionally supply a filehandle to print to automatically as
the template is generated. This may improve performance and lower
memory consumption. Example:
$template->output(print_to => *STDOUT);
The return value is undefined when using the C<print_to> option.
=head2 query()
This method is not supported in HTML::Template::Pro.
=begin comment
This method allow you to get information about the template structure.
It can be called in a number of ways. The simplest usage of query is
simply to check whether a parameter name exists in the template, using
the C<name> option:
if ($template->query(name => 'foo')) {
# do something if a varaible of any type
# named FOO is in the template
}
This same usage returns the type of the parameter. The type is the
same as the tag minus the leading 'TMPL_'. So, for example, a
TMPL_VAR parameter returns 'VAR' from C<query()>.
if ($template->query(name => 'foo') eq 'VAR') {
# do something if FOO exists and is a TMPL_VAR
}
Note that the variables associated with TMPL_IFs and TMPL_UNLESSs will
be identified as 'VAR' unless they are also used in a TMPL_LOOP, in
which case they will return 'LOOP'.
C<query()> also allows you to get a list of parameters inside a loop
(and inside loops inside loops). Example loop:
<TMPL_LOOP NAME="EXAMPLE_LOOP">
<TMPL_VAR NAME="BEE">
<TMPL_VAR NAME="BOP">
<TMPL_LOOP NAME="EXAMPLE_INNER_LOOP">
<TMPL_VAR NAME="INNER_BEE">
<TMPL_VAR NAME="INNER_BOP">
</TMPL_LOOP>
</TMPL_LOOP>
And some query calls:
# returns 'LOOP'
$type = $template->query(name => 'EXAMPLE_LOOP');
# returns ('bop', 'bee', 'example_inner_loop')
@param_names = $template->query(loop => 'EXAMPLE_LOOP');
# both return 'VAR'
$type = $template->query(name => ['EXAMPLE_LOOP', 'BEE']);
$type = $template->query(name => ['EXAMPLE_LOOP', 'BOP']);
# and this one returns 'LOOP'
$type = $template->query(name => ['EXAMPLE_LOOP',
'EXAMPLE_INNER_LOOP']);
# and finally, this returns ('inner_bee', 'inner_bop')
@inner_param_names = $template->query(loop => ['EXAMPLE_LOOP',
'EXAMPLE_INNER_LOOP']);
# for non existent parameter names you get undef
# this returns undef.
$type = $template->query(name => 'DWEAZLE_ZAPPA');
# calling loop on a non-loop parameter name will cause an error.
# this dies:
$type = $template->query(loop => 'DWEAZLE_ZAPPA');
As you can see above the C<loop> option returns a list of parameter
names and both C<name> and C<loop> take array refs in order to refer
to parameters inside loops. It is an error to use C<loop> with a
parameter that is not a loop.
Note that all the names are returned in lowercase and the types are
uppercase.
Just like C<param()>, C<query()> with no arguments returns all the
parameter names in the template at the top level.
=end comment
=cut
=head1 DISTINCTIONS AND INCOMPATIBILITIES
The main reason for small incompatibilities between HTML::Template and
HTML::Template::Pro is the fact that HTML::Template builds parsed tree of
template before anything else. So it has an additional information
which HTML::Template::Pro obtains during output.
In cases when HTML::Template dies, such as no_includes,
bad syntax of template, max_includes and so on,
HTML::Template::Pro issues warning to STDERR and continue.
=head2 new()
the following options are not supported in HTML::Template::Pro:
vanguard_compatibility_mode.
The options die_on_bad_params and strict are ignored.
HTML::Template::Pro behaves itself as HTML::Template called with
die_on_bad_params => 0, strict => 0.
It currently can't be changed, because HTML::Template::Pro can't
know whether a parameter is bad before it start output.
This may change in future releases.
To keep backward compatibility with HTML::Template, you should
explicitly call its new() with die_on_bad_params => 0, strict => 0.
=head2 query()
This method is not supported in HTML::Template::Pro.
=head2 param()
param() without arguments should return a list of parameters in the template.
In HTML::Template::Pro it returns a list of parameters set after new().
=head1 BUGS
With I<case_sensitive> and I<loop_context_vars> the special loop
variables should be available in lower-case only.
I<associate> is case_sensitive inside loops.
=begin comment
I am aware of no bugs - if you find one, join the mailing list and
tell us about it. You can join the HTML::Template mailing-list by
visiting:
http://lists.sourceforge.net/lists/listinfo/html-template-users
Of course, you can still email me directly (sam@tregar.com) with bugs,
but I reserve the right to forward bug reports to the mailing list.
=end comment
When submitting bug reports, be sure to include full details,
including the VERSION of the module, a test script and a test template
demonstrating the problem!
=begin comment
If you're feeling really adventurous, HTML::Template has a publically
available Subversion server. See below for more information in the PUBLIC
SUBVERSION SERVER section.
=end comment
=head1 EXPR: DEFINING NEW FUNCTIONS
To define a new function, pass a C<functions> option to new:
$t = HTML::Template::Pro->new(filename => 'foo.tmpl',
functions =>
{ func_name => \&func_handler });
or
$t = HTML::Template::Expr->new(filename => 'foo.tmpl',
functions =>
{ func_name => \&func_handler });
Or, you can use C<register_function> class method to register
the function globally:
HTML::Template::Pro->register_function(func_name => \&func_handler);
or
HTML::Template::Expr->register_function(func_name => \&func_handler);
You provide a subroutine reference that will be called during output.
It will receive as arguments the parameters specified in the template.
For example, here's a function that checks if a directory exists:
sub directory_exists {
my $dir_name = shift;
return 1 if -d $dir_name;
return 0;
}
If you call HTML::Template::Expr->new() with a C<functions> arg:
$t = HTML::Template::Expr->new(filename => 'foo.tmpl',
functions => {
directory_exists => \&directory_exists
});
Then you can use it in your template:
<tmpl_if expr="directory_exists('/home/sam')">
This can be abused in ways that make my teeth hurt.
=head2 register_function() extended usage (HTML::Template::Pro specific)
C<register_function()> can be called in a number of ways
1) To fetch the names of registered functions in the template:
=over 4
=item *
if C<register_function()> was called in a newly created object it returns a
list of function's that set _after_ or _in_ new():
my @registered_functions_names = $self->register_function();
=item *
in global context C<register_function()> will return a list of _ALL_
avalible function's
my @all_avalible_functions_names =
HTML::Template::Pro->register_function();
2) To fetching the function by name:
my $function = $self->register_function('FUNCTION_NAME');
3) To set a new function:
# Set function, that can be called in templates, wich are processed
# by the current object:
$self->register_function(foozicate => sub { ... });
# Set global function:
HTML::Template::Pro->register_function(barify => sub { ... });
=back
for details of "how to defined a function" see in
L<EXPR: DEFINING NEW FUNCTIONS>.
=head1 EXPR MOD_PERL TIP
C<register_function> class method can be called in mod_perl's
startup.pl to define widely used common functions to
HTML::Template::Expr. Add something like this to your startup.pl:
use HTML::Template::Pro;
HTML::Template::Pro->register_function(foozicate => sub { ... });
HTML::Template::Pro->register_function(barify => sub { ... });
HTML::Template::Pro->register_function(baznate => sub { ... });
=head1 EXPR CAVEATS
HTML::Template::Pro does not forces the HTML::Template global_vars
option to be set, whereas currently HTML::Template::Expr does.
Anyway, this also will hopefully go away in a future version of
HTML::Template::Expr, so if you need global_vars in your templates
then you should set it explicitly.
=head1 CREDITS
to Sam Tregar, sam@tregar.com
Original credits of HTML::Template:
This module was the brain child of my boss, Jesse Erlbaum
( jesse@vm.com ) at Vanguard Media ( http://vm.com ) . The most original
idea in this module - the <TMPL_LOOP> - was entirely his.
Fixes, Bug Reports, Optimizations and Ideas have been generously
provided by:
Richard Chen
Mike Blazer
Adriano Nagelschmidt Rodrigues
Andrej Mikus
Ilya Obshadko
Kevin Puetz
Steve Reppucci
Richard Dice
Tom Hukins
Eric Zylberstejn
David Glasser
Peter Marelas
James William Carlson
Frank D. Cringle
Winfried Koenig
Matthew Wickline
Doug Steinwand
Drew Taylor
Tobias Brox
Michael Lloyd
Simran Gambhir
Chris Houser <chouser@bluweb.com>
Larry Moore
Todd Larason
Jody Biggs
T.J. Mather
Martin Schroth
Dave Wolfe
uchum
Kawai Takanori
Peter Guelich
Chris Nokleberg
Ralph Corderoy
William Ward
Ade Olonoh
Mark Stosberg
Lance Thomas
Roland Giersig
Jere Julian
Peter Leonard
Kenny Smith
Sean P. Scanlon
Martin Pfeffer
David Ferrance
Gyepi Sam
Darren Chamberlain
Paul Baker
Gabor Szabo
Craig Manley
Richard Fein
The Phalanx Project
Sven Neuhaus
Thanks!
Original credits of HTML::Template::Expr:
The following people have generously submitted bug reports, patches
and ideas:
Peter Leonard
Tatsuhiko Miyagawa
Thanks!
=head1 WEBSITE
You can find information about HTML::Template::Pro at:
http://html-tmpl-pro.sourceforge.net
You can find information about HTML::Template and other related modules at:
http://html-template.sourceforge.net
=begin comment
=head1 PUBLIC SUBVERSION SERVER
HTML::Template now has a publicly accessible Subversion server
provided by SourceForge (www.sourceforge.net). You can access it by
going to http://sourceforge.net/svn/?group_id=1075. Give it a try!
=end comment
=head1 AUTHOR
Sam Tregar, sam@tregar.com (Main text)
I. Vlasenko, E<lt>viy@altlinux.orgE<gt> (Pecularities of HTML::Template::Pro)
=head1 LICENSE
HTML::Template : A module for using HTML Templates with Perl
Copyright (C) 2000-2002 Sam Tregar (sam@tregar.com)
This module is free software; you can redistribute it and/or modify it
under the terms of either:
a) the GNU General Public License as published by the Free Software
Foundation; either version 1, or (at your option) any later version,
or
b) the "Artistic License" which comes with this module.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either
the GNU General Public License or the Artistic License for more details.
You should have received a copy of the Artistic License with this
module, in the file ARTISTIC. If not, I'll be glad to provide one.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
=cut
|