[Templates] Template::Plugin::Filter
Stephen Howard
howars@alum.rpi.edu
Fri, 15 Mar 2002 08:54:13 -0500
Great idea Mark. I'll give it a spin, but regardless of whether the implementation shakes down well or not (and I don't see from
here why it wouldn't), I would certainly advocate that an implementation of some sort become part of TT's standard distribution.
It's a great way to keep filter definitions delineated from the rest of your code
-Stephen
-----Original Message-----
From: templates-admin@template-toolkit.org
[mailto:templates-admin@template-toolkit.org]On Behalf Of Mark Fowler
Sent: Thursday, March 14, 2002 07:15 PM
To: templates@template-toolkit.org
Subject: [Templates] Template::Plugin::Filter
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/
_______________________________________________
templates mailing list
templates@template-toolkit.org
http://www.template-toolkit.org/mailman/listinfo/templates