Positional parameters in same order.
Pass attribute hash as last to subroutine: no
Must pass named parameter interpolate=1 to cause interpolation.
This is a container tag, i.e. [filter] FOO [/filter]. Nesting: NO
Invalidates cache: no
Called Routine:
ASP/perl tag calls:
$Tag->filter( { op => VALUE, }, BODY ) OR $Tag->filter($op, $BODY);
Filters can be applied in sequence and as many as needed can be applied.
Here is an example. If you store your author or artist names in the database ``LAST, First'' so that they sort properly, you still might want to display them normally as ``First Last''. This call
[filter op="name namecase"]WOOD, Grant[/filter]
will display as
Grant Wood
Another way to do this would be:
[data table=products column=artist key=99-102 filter="name namecase"]
Filters available include:
'cgi' => sub { return $CGI::values(shift); },
'digits' => sub { my $val = shift; $val =~ s/\D+//g; return $val; },
'digits_dot' => sub { my $val = shift; $val =~ s/[^\d.]+//g; return $val; },
'dos' => sub { my $val = shift; $val =~ s/\r?\n/\r\n/g; return $val; },
<
to <
, "
to "
, etc.
'entities' => sub { return HTML::Entities::encode(shift); },
'gate' => sub { my ($val, $var) = @_; return '' unless $::Scratch->{$var}; return $val; },
'lc' => sub { return lc(shift); },
[filter op="uc lookup.country.name"]us[/filter]
This would be the equivalent of [data table=country column=name key=US].
'lookup' => sub { my ($val, $tag, $table, $column) = @_; return tag_data($table, $column, $val) || $val; },
'mac' => sub { my $val = shift; $val =~ s/\r?\n|\r\n?/\r/g; return $val; },
'name' => sub { my $val = shift; return $val unless $val =~ /,/; my($last, $first) = split /\s*,\s*/, $val, 2; return "$first $last"; },
'namecase' => sub { my $val = shift; $val =~ s/([A-Z]\w+)/\L\u$1/g; return $val; },
'no_white' => sub { my $val = shift; $val =~ s/\s+//g; return $val; },
'pagefile' => sub { $_[0] =~ s:^[./]+::; return $_[0]; },
'sql' => sub { my $val = shift; $val =~ s:':'':g; # ' return $val; },
'strip' => sub { my $val = shift; $val =~ s/^\s+//; $val =~ s/\s+$//; return $val; },
'text2html' => sub { my $val = shift; $val =~ s|\r?\n\r?\n|<P>|; $val =~ s|\r?\n|<BR>|; return $val; },
'uc' => sub { return uc(shift); },
'unix' => sub { my $val = shift; $val =~ s/\r?\n/\n/g; return $val; },
%3c
notation.
'urlencode' => sub { my $val = shift; $val =~ s|[^\w:]|sprintf "%%%02x", ord $1|eg; return $val; },
'value' => sub { return $::Values->(shift); },
'word' => sub { my $val = shift; $val =~ s/\W+//g; return $val; },
You can define your own filters in an GlobalSub (or Sub or ActionMap):
package Vend::Interpolate;
$Filter{reverse} = sub { $val = shift; return scalar reverse $val };
That filter will reverse the characters sent.
The arguments sent to the subroutine are the value to be filtered, any associated variable or tag name, and any arguments appended to the filter name with periods as the separator.
A [filter op=lookup.products.price]99-102[/filter]
will send ('99-102', undef, 'products', 'price') as the parameters.
Assuming the value of the user variable foo
is bar
, the call
[value name=foo filter="lookup.products.price.extra"]
will send ('bar', 'foo', 'products', 'price', 'extra').