perlnews
tobyink
<p>Why learn a whole new language for templating when you already know a perfectly good one? This isn't the first module that allows you to embed Perl in your templates, but it's yet another one.</p>
<c>
use Types::Standard -types;
use Template::Compiled;
my $template = Template::Compiled->new(
signature => [
name => Str,
age => Int->plus_coercions(Num, sub { int $_ } ),
],
template => '<p>Hi <?= $name ?>. You are <?= $age ?> years old.</p>',
escape => 'html',
);
# The number will be rounded.
# The ampersand will be escaped properly.
#
print $template->( name => 'Alice & Bob', age => 45.1 );
</c>
<p><a href="https://metacpan.org/release/Template-Compiled">Template::Compiled on MetaCPAN</a>.</p>