> I have a need to use Digest::MD5 (actually md5_hex) in my code.
> How do I pull in the md5_hext function into my template inside
> the [% ... %] tags?
Several ways:
- write a short plugin
- set LOAD_PERL and use it directly
use Template;
my $tt = Template->new({ LOAD_PERL => 1})
|| die("can't run Template->new");
$tt->process(\*DATA, {}) || die $tt->error();
__DATA__
[%
USE md5 = Digest.MD5;
CALL md5.add('this is a string');
md5.hexdigest();
%]
- add a sub ref to md5_hex when you call process:
use Template;
use Digest::MD5 qw(md5_hex);
my $tt = Template->new() || die("can't run Template->new");
$tt->process(\*DATA, {
md5_hex => \&md5_hex,
}) || die $tt->error();
__DATA__
[% md5_hex('this is a string') %]
Craig