Su::Template - A module to make the string using the specified template and passed parameters.
my $tmpl = Su::Template->new; my $str = $tmpl->expand( <<'HERE', $arg); % my $arg = shift; arg is <%=$arg%> HERE
Su::Template is a module to make the string using the specified template and passed parameters.
lottz <lottzaddr@gmail.com>
A constructor.
Expand the template using the passed context and return the result string. Note that the keyword for here document must quoted by single quote. Double quote should cause unexpected error.
Template syntax:
<%= $val %> render the variable. Html special character will escaped. <%== $val %> render the variable. Html special character will not escaped. End tag ~%> discards line separator. Expression surrounded by <% %> or the line start with '%' will parsed as Perl statements.
If you want debug output, set the following flag on, then expand method return the debug string.
$Su::Template::DEBUG=1;
The functional style usage of this method is the following.
$ret = Su::Template::expand(<<'__HERE__'); <% foreach my $v ("aa","bb","cc"){~%> <%= $v%> <%}~%> xxx yyy zzz __HERE__
The OO style usage of this method is the following.
my $tmpl = Su::Template->new; my $str = $tmpl->expand( <<'HERE', $title, $link ); % my $title = shift; % my $link = shift; <a href="<%=$link%>"><%=$title%></a> HERE
The html special character in variable expression will be escaped like the following.
$ret = $t->expand( <<'__HERE__', "aa<bb>cc'dd\"ee&ff" ); % my $arg = shift; <%= $arg ~%> __HERE__ is( $ret, "aa<bb>cc'dd"ee&ff" );
Note that the html special character described in the raw part of the template will not be escaped.
An alias to the method expand.
To install Su, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Su
CPAN shell
perl -MCPAN -e shell install Su
For more information on module installation, please visit the detailed CPAN module installation guide.