NAME
Template::Perl - evaluate perl code embedded in text.
SYNOPSIS
use Template::Perl;
# you can any argumnets at initialization
my $t = Template::Perl->new({});
my $template = q{
Yo nombre es [- $name -].
I am [- $age -] years old.
};
# initialize a couple vars in package 'main'
my $name = 'Steve';
my $age = 31;
# parse defaults to package 'main' (unless a hash has been loaded)
print $t->parse({
text => $text
});
# or...use a hash ( slower, but MUCH easier to work with )
my %hash = (
name => 'Steve',
age => 31
);
print $t->parse({
text => $text,
hash => \%hash
});
# ...or however you like it, as long as text and hash or package name
# is loaded before or when parse() is called.
DESCRIPTION
Template::Perl
a module for evaluating perl embedded in text. The perl can be evaluated under a specified package, or under a package built from a provided hash.
FUNCTIONS
- new()
-
Initializes a Template::Perl object. Pass parameter as a hash reference. Optionally pass: delimiters, hash, package, text, file, inline_errs (see descriptions below).
- hash()
-
Installs values identified by a given hash reference into a package under which to evaluate perl tokens.
- text()
-
Install the text to be parsed as the template.
- file()
-
Specify a file containing the text to be parsed as the template.
- inline_errs()
-
Specify how to handle error messages generated during the evaluation of perl tokens. a true value = inline, a flase value = ignore.
- package()
-
Set the package name under which to evaluate the extracted perl. If used in concert with a hash, the package name must be set prior to installation of a hash.
- parse()
-
Runs the parser. Optionally accepts parameters as specified for new();.
- parsed();
-
Returns the fully parsed and evaluated text.
CHANGES
0.24 - Bug Fix: Internal package cleanup now works correctly when using hashes.
0.23 - Can now specify a package underwhich to install a hash (was explicitly 'Safe'). This also means that the package name must be set prior to or at the time of installation of a hash, or not at all.
Changed default delimiters to '<?' and '?>' (was '[-' and '-]').
AUTHOR
Steve McKay, steve@colgreen.com
COPYRIGHT
Copyright 2000-2001 Steve McKay. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
Parse::Tokens
, Text::Template
, Text::SimpleTemplate