Template::Plugin::Perl - TT2 plugin to import Perl built-in functions
This document describes Template::Plugin::Perl 0.06 released on 12 March, 2007.
[% 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) %]
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. However,
reverse are notable exceptions. 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.
builtins that modify their arguments won't work either, such as
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.
Constructor called by the TT2 template system
TT2 exception handling procedure.
Non-Perl builtin added for ease of use
You can always get the latest version of the source code from the follow Subversion repository:
There is anonymous access to all.
If you'd like a commit bit, please let me know :)
Agent Zhang, <email@example.com>
Copyright (c) 2005, 2006, 2007 by Agent Zhang. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.