The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Su::Template - A module to make the string using the specified template and passed parameters.

SYNOPSIS

 my $tmpl = Su::Template->new;
 my $str = $tmpl->expand( <<'HERE', $arg);
 % my $arg = shift;
 arg is <%=$arg%>
 HERE

DESCRIPTION

Su::Template is a module to make the string using the specified template and passed parameters.

AUTHOR

lottz <lottzaddr@gmail.com>

FUNCTIONS

new()

A constructor.

expand()

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&lt;bb&gt;cc&apos;dd&quot;ee&amp;ff" );

Note that the html special character described in the raw part of the template will not be escaped.

render()

An alias to the method expand.