CGI-FastTemplate
view release on metacpan or search on metacpan
FastTemplate.pm view on Meta::CPAN
=head2 clear_parse()
See: clear()
=head2 clear_href(NUMBER)
Removes a given number of hash references from the list of hash refs that is built using:
$tpl->assign(HASH REF);
If called with no arguments, it removes all hash references
from the array. This is often used for database queries where each row from the query
is a hash or hash reference.
e.g.
while($hash_row = $sth->fetchrow_hashref)
{
$tpl->assign($hash_row);
$tpl->parse(ROW => ".row");
$tpl->clear_href(1);
}
=head2 clear_define()
Clears the internal hash that stores data passed to:
$tpl->define();
Note: The hash that holds the loaded templates is not touched with
this method. See: clear_tpl
=head2 clear_tpl() clear_tpl(NAME)
The first time a template is used, it is loaded and stored in a hash
in memory. clear_tpl() removes all the templates being held in memory.
clear_tpl(NAME) only removes the one with NAME. This is generally not
required for normal CGI programming, but if you have long running scripts
(e.g. mod_perl) and have very large templates that a re infrequently
used gives you some control over how memory is being used.
=head2 clear_all()
Cleans the module of any data, except for the ROOT directory. Equivalent to:
$tpl->clear_define();
$tpl->clear_href();
$tpl->clear_tpl();
$tpl->clear_parse();
=head2 Variables
A variable is defined as:
$[A-Z0-9][A-Z0-9_]+
This means, that a variable must begin with a dollar sign '$'.
The second character must be an uppercase letter or digit 'A-Z0-9'.
Remaining characters can include an underscore.
As of version 1.07 variables can also be delimited by curly brackets.
${[A-Z0-9][A-Z0-9_]+}
For example, the following are valid variables:
$FOO
$F123F
$TOP_OF_PAGE
${NEW_STYLE}
=head2 Variable Interpolation (Template Parsing)
When the a template is being scanned for variables, pattern matching
is greedy. (For more info on "greediness" of regexps see L<perlre>.)
This is important, because if there are valid variable characters after
your variable, FastTemplate will consider them to be part of the variable.
As of version 1.07 you can use curly brackets as delimiters for your
variable names. e.g. ${VARIABLE} You do not need to use curly brackets
if the character immediately after your variable name is not an uppercase
letter, digit or underscore. ['A-Z0-9_']
If a variable cannot be resolved to a value then there are two
possibilities. If strict() has been called (it is on by default) then
the variable remains and a warning is printed to STDERR. If no_strict()
has been called then the variables is converted to an empty string [''].
See L<strict()> and L<no_strict()> for more info.
Some examples will make this clearer.
Assume:
$FOO = "foo";
$BAR = "bar";
$ONE = "1";
$TWO = "2";
$UND = "_";
Variable Interpolated/Parsed
------------------------------------------------
$FOO foo
$FOO-$BAR foo-bar
$ONE_$TWO 2 ## $ONE_ is undefined!
$ONE_$TWO $ONE_2 ## assume: strict()
$ONE$UND$TWO 1_2 ## kludge!
${ONE}_$TWO 1_2 ## much better
$$FOO $foo
$25,000 $25,000
=head2 FULL EXAMPLE
( run in 1.644 second using v1.01-cache-2.11-cpan-5735350b133 )