NAME
Template::Plugin::Perl - Plugin to Import Perl Built-in Functions
SYNOPSIS
[% USE Perl %]
[% Perl.log(100) %]
[% Perl.rand(1) %]
[% Perl.exp(2) %]
[% Perl.sprintf("%.0f", 3.5) %]
[% Perl.pow(2, 3) %] # 2 ** 3;
[% Perl.eval('2**3') %]
[% Perl.sin(3.14) %]
[% Perl.cos(0) %]
[% Perl.join(',', 'a', 'b', 'c') %]
[% list = ['a','b','c'];
Perl.join(',' list) %]
DESCRIPTION
As a TT programmer, I found it quite inflexible to use the Template Toolkit's presentation language Language due to the very limited vocabulary. So I wrote this little plugin in order to open a window for the template file to the full richness of most Perl built-in functions, making the Template language a "programming language" in a much more serious sense.
As I writing this stuff, The Template language does not support exponential operator (**). So I add an extra function 'pow' to support this missing feature. However, there is no doubt that we could treat "Perl.eval" as a good workaround, just as the "SYNOPSIS" demonstrates.
According to the current implementation, don't use the functions for real @ARRAYs, such as shift, pop. They won't function at all. Moreover, Arguments of all Perl.* functions are passed by values, and returned in scalar context, so some functions for list data, like map and grep, make little sense in this context.
Please keep in mind I just used AUTOLOAD, eval, and Data::Dumper to do the magic here.
If you're looking for even more functions, I suggest you take a look at the Template::Plugin::POSIX module which exports the excellent POSIX repertoire.
SEE ALSO
Template, Template::Plugin::POSIX, Data::Dumper
AUTHOR
Agent Zhang, <agent2002@126.com>
COPYRIGHT AND LICENSE
Copyright (c) 2005 Agent Zhang.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available.