Is there a concise syntax for conditional processing a block through a
filter?
I'm currently enhancing the templates that come with SVN::Web. When
viewing Subversion log messages there's a snippet that looks like this:
[% msg | html | html_line_break %]
So far, so obvious.
What I'd like to do is make it possible for the template to use various
additional filters if they're installed, but to fall back to the default
filters if they're not installed.
For example, in my ideal world all the user would have to do is install
Template::Plugin::Clickable and URLs in the log message would be clickable.
I know I can do something like
[% TRY %]
[% USE Clickable %]
[% msg | html | html_line_break | clickable %]
[% CATCH %]
[% msg | html | html_line_break %]
[% END %]
but that's not going to scale. I envisage documenting several different
filters (::RecogniseRtTicketNumber, ::RecogiseSvnRevision, and so on) as
being automatically recognised and used if they're installed.
At the moment the only idea I've come up with is to create a catch-all
filter, and then when I create my TT object do something like:
my $tt = Template->new({
FILTERS => {
'catch_all' => \&catch_all,
}
});
sub catch_all {
my $text = shift;
$text = clickable($text) if $have_clickable;
$text = recognise_rt_ticket_number($text) if ...
$text = recognise_svn_revision($text) if ...
return $text;
}
and in the template:
[% msg | html | html_line_break | catch_all %]
Which should work, but doesn't strike me as being terribly elegant.
N
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates