You can also pass functions (i.e. routines) to the template as follows:
use strict; use warnings; use List::Util (); use Template; my $tt = Template->new({ INCLUDE_PATH => '.', }); $tt->process( 'not_plugin.tt', { divider => sub { '=' x $_[0] }, capitalize => sub { ucfirst $_[0] }, sum => sub { List::Util::sum( @_ ) }, });
not_plugin.tt
[% divider (40)%]
Hello my name is [% capitalize ('barry')%], how are u today?
The ultimate answer to life is [% sum (10, 30, 2)%]
[% divider (40)%]
will produce the following:
==========================================
Hello my name is Barry, how are u today?
The ultimate answer to life is 42
==========================================
source share