Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.tt2.org/tt/Template2/trunk@47 d5a88997-0a34-4036-9ed2-92fb5d660d91
  • Loading branch information
abw committed Sep 13, 2000
1 parent c17f6d5 commit b505a87
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Changes
Expand Up @@ -20,6 +20,25 @@
# Version 2.00 beta 4 12th September 2000
#------------------------------------------------------------------------

* Changed the Template::Context filter() method to accept a code
reference as the filter name and use it as the filter sub. This
allows filters to be bound to template variables which are then
used as:

[% FILTER $myfilter %]

There is one catch, however. TT will automatically call a subroutine
bound to a variable when evaluated. Thus you must wrap your filter
sub in another sub: $stash->set('foo', sub { \&myfilter }); or bless
it into some class (any class) to fool TT into thinking it's not a
subroutine ref: $stash->set('bar', bless \&myfilter, 'any_old_name');

* Template::Tutorial

#------------------------------------------------------------------------
# Version 2.00 beta 4 12th September 2000
#------------------------------------------------------------------------

* Added the PROCESS config option which allows a template or templates
to be specified which is/are processed instead of the template
passed as an argument to the Template process() method. The
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -49,6 +49,7 @@ lib/Template/Stash.pm
lib/Template/Stash.pod
lib/Template/Test.pm
lib/Template/Test.pod
lib/Template/Tutorial.pod
parser/Grammar.pm.skel
parser/Parser.yp
parser/README
Expand Down
6 changes: 5 additions & 1 deletion lib/Template/Context.pm
Expand Up @@ -157,13 +157,17 @@ sub filter {

# use any cached version of the filter if no params provided
return $filter
if ! $args && ($filter = $self->{ FILTER_CACHE }->{ $name });
if ! $args && ! ref $name
&& ($filter = $self->{ FILTER_CACHE }->{ $name });

# request the named filter from each of the FILTERS providers in turn
foreach my $provider (@{ $self->{ LOAD_FILTERS } }) {
# print STDERR "Asking filter provider $provider for $name...\n"
# if $DEBUG;

$filter = $name, last
if ref $name;

($filter, $error) = $provider->fetch($name, $args, $self);
last unless $error;
return $self->error($filter)
Expand Down
39 changes: 39 additions & 0 deletions t/filter.t
Expand Up @@ -641,3 +641,42 @@ wiz: The cat sat on the mat
wiz: The dog sat on the log
-- test --
-- use evalperl --
[% PERL %]
$stash->set('merlyn', bless \&merlyn1, 'ttfilter');
sub merlyn1 {
my $text = shift || '<no text>';
$text =~ s/stone/henge/g;
return $text;
}
[% END -%]
[% FILTER $merlyn -%]
Let him who is without sin cast the first stone.
[% END %]
-- expect --
Let him who is without sin cast the first henge.
-- test --
-- use evalperl --
[% PERL %]
$stash->set('merlyn', sub { \&merlyn2 });
sub merlyn2 {
my $text = shift || '<no text>';
$text =~ s/stone/henge/g;
return $text;
}
[% END -%]
[% FILTER $merlyn -%]
Let him who is without sin cast the first stone.
[% END %]
-- expect --
Let him who is without sin cast the first henge.
-- test --
[% myfilter = 'html' -%]
[% FILTER $myfilter -%]
<html>
[% END %]
-- expect --
&lt;html&gt;

0 comments on commit b505a87

Please sign in to comment.