package HTML::Template::Ex::Filter;
#
# Copyright (C) 2007 Bee Flag, Corp, All Rights Reserved.
# Masatoshi Mizuno EmizunoE<64>bomcity.comE
#
# $Id: Filter.pm 297 2007-03-25 14:34:59Z lushe $
#
use strict;
use warnings;
our $VERSION = '0.02';
sub set {
{
format=> 'scalar',
sub=> sub {
my $text= shift;
$$text=~s{\[\%\s*([^\%]+)\s*\%\]} [ &__filter($1) ]sge;
},
};
}
sub __filter {
local($_)= @_;
return
/^(?:var|\=)\s*(\S+)/i ? do {
my $v= $1;
$v=~/^(url|html)\s*\:(.+)/i
? qq{}
: qq{};
}:
/^ex(?:\s+(.+))?/i ? do {
my($str, $option)= ($1, "");
if ($str) {
my($name, $escape)=
$str=~/^([^\:\"\']+)\s*\:\s*([^\s\"\']+)/ ? ($2, $1):
$str=~/^([^\:\"\']+)\:\s*$/ ? ("", $1):
$str=~/([^\s\"\']+)/ ? ($1, ""): ("", "");
$option = qq{ escape="$escape} if $escape;
$option.= qq{ name="$name"} if $name;
}
qq{};
}:
/^set\s+([^\s\=]+)\s*\=\s*(.+)/i ? do {
my($name, $value)= ($1, $2);
$value=~s/(?:^[\"\']|[\"\']\s*$)//g;
qq{};
}:
/^(if|unless)\s+(\S+)/i ? do { qq{} }:
/^else/i ? do { qq{} }:
/^loop\s+(\S+)/i ? do { qq{} }:
/^(?:end_loop|\/\s*loop)/ ? do { qq{} }:
/^(?:include|\.\.\.?)\s*(\S+)/i ? do { qq{} }:
/^(?:end_|\/\s*)(if|unless|ex)/i ? do { qq{} }:
/^(?:\!|comment)/ ? do { "" }:
do { qq{[% $_ %]} };
}
1;
__END__
=head1 NAME
HTML::Template::Ex::Filter - tmpl_tag filter for HTML::Template::Ex.
=head1 SYNOPSIS
use HTML::Template::Ex;
use HTML::Template::Ex::Filter;
my $tmpl= HTML::Template::Ex->new(
...
filter=> HTML::Template::Ex::Filter->set,
);
[%... include_template.tmpl %]
[% ex %]
my($self, $param)= @_;
...
..... ban, bo, bon.
"";
[% end_ex %]
[% =param_name %]
[% loop loop_param_name %]
...
[% end_loop %]
=head1 DESCRIPTION
This module offers the filter to make the format of HTML::Template easy a little.
=head1 TAGS
=head2 [% ex %] ... [% end_ex %]
It corresponds to ' ... '.
To specify the NAME attribute, as follows is done.
[% ex param_name %] ...
In addition, delimit by the ESCAPE attribute and to the following
[% ex html:param_name %]
NAME attribute a unspecified ESCAPE attribute must make the head and to the
following
[% ex html: %]
=head2 [% set PARAM_NAME="PARAM_VALUE" %]
It corresponds to ''.
=head2 [% =VAR_NAME %]
It corresponds to ''.
The ESCAPE attribute does as follows.
[% =html:VAR_NAME %]
=head2 [% if VAR_NAME %] ... [% else %] ... [% end_if %]
It corresponds to ' ... ... '.
=head2 [% unless VAR_NAME %] ... [% else %] ... [% end_unless %]
It corresponds to ' ... ... '.
=head2 [% loop ARRAY_NAME %] ... [% end_loop %]
It corresponds to ' ... '.
=head2 [%... INCLUDE_TEMPLATE %] or [% include INCLUDE_TEMPLATE %]
It corresponds to ''.
=head2 [% ! COMMENT_STRING %] or [% comment COMMENT_STRING %]
It is a comment. It is not reflected in the template.
=head1 SEE ALSO
L,
=head1 AUTHOR
Masatoshi Mizuno EmizunoE<64>bomcity.comE
=head1 COPYRIGHT
Copyright (C) 2007 by Bee Flag, Corp. ELE, All Rights Reserved.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.6 or,
at your option, any later version of Perl 5 you may have available.
=cut