On Mon, Aug 27, 2001 at 10:27:13AM -0700, Craig Barratt wrote:
> > I wondering why this doesn't work :
> >  <? field == 'Field'  ? row.$field FILTER sprintf('%.4f') : row.$field ?>
> 
> The parser doesn't allow FILTER to be mixed inside expressions.
> This will be fixed in v3.
> 
> > OR the best way should be :
> >  <? field == 'Field'  ? row.$field.sprintf('%.4f') : row.$field ?>
> > OR :
> >  <? field == 'Field'  ? sprintf('%.4f', row.$field) : row.$field ?>
> 
> Instead of a filter you can add your own SCALAR_OPS to the Stash, eg:

We could add an option to Template::Context to have the define_filter()
method update the SCALAR_OPS in the stash to add an entry to access the
filter.

    $context->define_filter(foo => sub { ... });

    [% scalar.foo %]

It would be trickier to expose all filters automatically, including
all the pre-defined ones.  I suppose we could have a plugin which,
when given a list of filter names, fetches the filters and then updates
the SCALAR_OPS list.

e.g.

    [% USE filters('html') %]

    [% scalar.html %]

As Craig points out, this messiness will go away in v3 when scalar ops
and filters will be one and the same.  Also, there is the possibility
of having filters that operate on non-scalar types.

    [% mylist.myfilter %]

That will be nice.

A



Reply via email to