[Templates] Template::Plugin::Filter
Mark Fowler
mark@indicosoftware.com
Fri, 15 Mar 2002 00:15:09 +0000 (GMT)
An idea I had:
NAME
Template::Plugin::Filter - base class for easily adding
filters from Plugins
SYNOPSIS
package Template::Plugin::Filter::Underline;
use base qw(Template::Plugin::Filter);
our @FILTERS = qw(underline);
sub underline
{
my ($text, $char) = (shift(), shift() || "-");
my $output;
foreach(split /\n/, $text)
{
$output .= $text . "\n";
$output .= ($char x length($text)) . "\n";
}
return $output;
}
... and later in the template ...
[% USE Filter %]
[% FILTER underline('=') %]The Title[% END %]
DESCRIPTION
Allows you to quickly define modules that add filters to
the Template Toolkit without really having to understand
how the Template Toolkit works internally.
This module is based on the design of the Exporter module
module where functions to be 'exported' are simply
declared in a package varible and the module hadles the
rest. Template::Plugin::Filter 'exports' all subroutines
named in the package variable @FILTERS as filters so they
can be used in the template that USEed the plugin.
There's support for @FILTERS_STATIC and @FILTERS_DYNAMIC too.
The full pod, source code, and a distribution that includes tests is up
(for now) on my website at http://2shortplanks.com/temp/tpf/
Could people please people take a look and decide if this is worthwhile or
not, and help decided if it *is* worthwhile what would be best done with
it (release on CPAN? Bundle it with TT?)
Documentation needs a tidy, but since it's past midnight that'll have to
wait till tommorow.
Later.
Mark.
--
Mark Fowler
Technology Developer
http://www.indicosoftware.com/