Nik Clayton wrote:
> Am I on the right track, or is this sort of approach doomed to
> failure?  It did occur to me that I'm reinventing code that
> Template::Filters already has, which is probably not a good thing...

Yes, it looks like you might be re-inventing what the context filter() 
method does.  You call it with a filter name and optional arguments and 
it returns you the filter or undef if it can't be found.

Here's an untested example of a plugin that installs a 'multifilter'
filter when loaded.

package Template::Plugin::Multifilter;
use base 'Template::Plugin';

sub new {
   my ($class, $context) = @_;
   $context->define_filter( multifilter => sub {
      multifilter($context, @_);
   });
}

sub multifilter {
   my ($context, $text) = @_;

   foreach my $filter in (@LIST_OF_FILTERS) {
     my $filter = $context->filter($filter)
       || next;
     $text = &$filter($text);
   }
   return $text;
}

And here's how you would use it:

  [% USE Multifilter %]

  [% message | multifilter %]

Of course, it would be nice if you could specify what filters you
wanted (and any of their arguments) in the arguments to USE Multifilter.

Something like this, perhaps?

  [% USE Multifilter( 
       html_line_break = [], 
       format = ['%60s']
       indent = [4] 
     ) 
  %]

But I'll leave that as an excercise for the reader ;-)

HTH
A


_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to