| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::Template::Filter::TT2; |
|
2
|
2
|
|
|
2
|
|
26815
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
113
|
|
|
3
|
|
|
|
|
|
|
require Exporter; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
{ |
|
6
|
2
|
|
|
2
|
|
10
|
no strict "vars"; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
1051
|
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.03'; |
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
9
|
|
|
|
|
|
|
@EXPORT = qw(ht_tt2_filter); |
|
10
|
|
|
|
|
|
|
} |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
HTML::Template::Filter::TT2 - Template Toolkit 2 syntax for HTML::Template |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Version 0.03 |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use HTML::Template::Filter::TT2; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $tmpl = HTML::Template->new(filter => \&ht_tt2_filter, ...); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This C filter allows you to use a subset of the Template Toolkit 2 |
|
29
|
|
|
|
|
|
|
syntax, which is much less verbose than the default syntax. This is not |
|
30
|
|
|
|
|
|
|
an emulation of TT2, so you're still limited to the usual C |
|
31
|
|
|
|
|
|
|
semantics. Also, in order to keep the filter fast and simple, the |
|
32
|
|
|
|
|
|
|
C<[% end %]> must be written with the block name. See below for details. |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 SYNTAX |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Here is the syntax recognised by this module. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 Variables |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Simple interpolation: |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
[% variable %] |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Interpolation with default value: |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
[% variable :default %] |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Interpolation with filter (i.e. a C escape mode): |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
[% variable |filter %] |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Interpolation with default value and filter: |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
[% variable :default |filter %] |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 If statements |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
[% if condition %] ... [% else %] ... [end_if %] |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
The difference with the actual TT2 syntax is that you must use C |
|
61
|
|
|
|
|
|
|
instead of C |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 Loops |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
[% loop loop-name %] ... [% end_loop %] |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
As for the C statement, you must use C instead of C. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 EXPORT |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Exports the C function by default. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 ht_tt2_filter() |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Pass a reference to this function to the C parameter when calling |
|
78
|
|
|
|
|
|
|
C<< HTML::Template->new() >> |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub ht_tt2_filter { |
|
83
|
8
|
|
|
8
|
1
|
21558
|
my ($text_ref) = @_; |
|
84
|
8
|
|
|
|
|
81
|
$$text_ref =~ s{\[% *(loop|if|unless) +(\w+) *%\]}{}gm; |
|
85
|
8
|
|
|
|
|
33
|
$$text_ref =~ s{\[% *(else) *%\]}{}gm; |
|
86
|
8
|
|
|
|
|
32
|
$$text_ref =~ s{\[% *end_(\w+) *%\]}{}gm; |
|
87
|
8
|
|
|
|
|
68
|
$$text_ref =~ s{ |
|
88
|
|
|
|
|
|
|
\[% # begin tag |
|
89
|
|
|
|
|
|
|
\s* (\w+) \s* # variable name |
|
90
|
|
|
|
|
|
|
\s* (?:: \s* (.+?))? # optional default value |
|
91
|
|
|
|
|
|
|
\s* (?:\| \s* (\w+))? # optional filter |
|
92
|
|
|
|
|
|
|
\s* %\] # end tag |
|
93
|
|
|
|
|
|
|
} |
|
94
|
7
|
|
|
|
|
22
|
{__format_variable($1, $2, $3)}gemx; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub __format_variable { |
|
98
|
7
|
|
|
7
|
|
22
|
my ($var, $default, $filter) = @_; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# variable name |
|
101
|
7
|
|
|
|
|
13
|
my $ht_syntax = "
|
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# handle default value |
|
104
|
7
|
100
|
|
|
|
26
|
if (defined $default) { |
|
105
|
|
|
|
|
|
|
# autoquote unquoted values |
|
106
|
3
|
50
|
|
|
|
14
|
if ($default !~ /^["']/) { |
|
107
|
3
|
50
|
|
|
|
12
|
if ($default !~ /"/) { $default = qq/"$default"/ } |
|
|
3
|
0
|
|
|
|
8
|
|
|
108
|
0
|
|
|
|
|
0
|
elsif ($default !~ /'/) { $default = qq/'$default'/ } |
|
109
|
0
|
|
|
|
|
0
|
else { warn "Can't handle unquoted value '$default' for variable $var" } |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
3
|
|
|
|
|
8
|
$ht_syntax .= " DEFAULT=$default"; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# handle escape filter |
|
116
|
7
|
100
|
|
|
|
27
|
$ht_syntax .= " ESCAPE=$filter" if defined $filter; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# end tag |
|
119
|
7
|
|
|
|
|
11
|
$ht_syntax .= ">"; |
|
120
|
|
|
|
|
|
|
|
|
121
|
7
|
|
|
|
|
38
|
return $ht_syntax; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 AUTHOR |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
SEbastien Aperghis-Tramoni, C<< >> |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 SEE ALSO |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
L, L |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 BUGS |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
136
|
|
|
|
|
|
|
C, or through the web interface at |
|
137
|
|
|
|
|
|
|
L. |
|
138
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
139
|
|
|
|
|
|
|
your bug as I make changes. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 SUPPORT |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
perldoc HTML::Template::Filter::TT2 |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
You can also look for information at: |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over 4 |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
L |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
L |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
L |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item * Search CPAN |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
L |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=back |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Copyright 2007 SEbastien Aperghis-Tramoni, all rights reserved. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
174
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1; # End of HTML::Template::Filter::TT2 |