line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Template::Compiled::Plugin::HTML_Tags; |
2
|
|
|
|
|
|
|
# $Id: HTML_Tags.pm,v 1.17 2007/10/27 11:33:29 tinita Exp $ |
3
|
2
|
|
|
2
|
|
76401
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
84
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
72
|
|
5
|
2
|
|
|
2
|
|
24
|
use Carp qw(croak carp); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
160
|
|
6
|
2
|
|
|
2
|
|
12
|
use HTML::Template::Compiled::Expression qw(:expressions); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
419
|
|
7
|
2
|
|
|
2
|
|
11
|
use HTML::Template::Compiled; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
17
|
|
8
|
|
|
|
|
|
|
HTML::Template::Compiled->register('HTML::Template::Compiled::Plugin::HTML_Tags'); |
9
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub register { |
12
|
2
|
|
|
2
|
1
|
32
|
my ($class) = @_; |
13
|
|
|
|
|
|
|
my %plugs = ( |
14
|
|
|
|
|
|
|
tagnames => { |
15
|
|
|
|
|
|
|
HTML::Template::Compiled::Token::OPENING_TAG() => { |
16
|
2
|
|
|
2
|
|
2933
|
HTML_OPTION => [sub { exists $_[1]->{NAME} }, qw(NAME)], |
17
|
1
|
|
|
1
|
|
2595
|
HTML_SELECT => [sub { exists $_[1]->{NAME} }, qw(NAME SELECT_ATTR)], |
18
|
|
|
|
|
|
|
HTML_TABLE => [ |
19
|
1
|
|
|
1
|
|
1799
|
sub { exists $_[1]->{NAME} }, |
20
|
|
|
|
|
|
|
qw(NAME TH_ATTR TD_ATTR TR_ATTR TABLE_ATTR HEADER) |
21
|
|
|
|
|
|
|
], |
22
|
1
|
|
|
1
|
|
1716
|
HTML_OPTION_LOOP => [sub { exists $_[1]->{NAME} }, qw(NAME)], |
23
|
2
|
|
|
1
|
|
68
|
HTML_BOX_LOOP => [sub { exists $_[1]->{NAME} }, qw(NAME)], |
|
1
|
|
|
|
|
1721
|
|
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
HTML::Template::Compiled::Token::CLOSING_TAG() => { |
26
|
|
|
|
|
|
|
HTML_OPTION_LOOP => [undef, qw(NAME)], |
27
|
|
|
|
|
|
|
HTML_BOX_LOOP => [undef, qw(NAME)], |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
compile => { |
31
|
|
|
|
|
|
|
HTML_SELECT => { |
32
|
|
|
|
|
|
|
open => \&_html_select, |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
HTML_OPTION => { |
35
|
|
|
|
|
|
|
open => \&_html_option, |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
HTML_TABLE => { |
38
|
|
|
|
|
|
|
open => \&_html_table, |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
HTML_OPTION_LOOP => { |
41
|
|
|
|
|
|
|
open => \&_html_option_loop, |
42
|
|
|
|
|
|
|
close => \&_html_option_loop_close, |
43
|
|
|
|
|
|
|
}, |
44
|
|
|
|
|
|
|
HTML_BOX_LOOP => { |
45
|
|
|
|
|
|
|
open => \&_html_box_loop, |
46
|
|
|
|
|
|
|
close => \&_html_option_loop_close, # sic! |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
); |
50
|
2
|
|
|
|
|
10
|
return \%plugs; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _html_option_loop_close { |
54
|
2
|
|
|
2
|
|
2586
|
return <<'EOM'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
EOM |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _option_loop { |
61
|
2
|
|
|
2
|
|
1051
|
my ($select_string, $var) = @_; |
62
|
2
|
|
|
|
|
5
|
my @var = @{ $var }; |
|
2
|
|
|
|
|
6
|
|
63
|
2
|
|
|
|
|
4
|
my $selected = shift @var; |
64
|
0
|
|
|
|
|
0
|
my %selected = defined $selected |
65
|
|
|
|
|
|
|
? ref $selected eq 'ARRAY' |
66
|
2
|
50
|
|
|
|
13
|
? (map { $_ => 1 } @$selected) |
|
|
50
|
|
|
|
|
|
67
|
|
|
|
|
|
|
: ($selected => 1) |
68
|
|
|
|
|
|
|
: (); |
69
|
2
|
|
|
|
|
3
|
my @options; |
70
|
2
|
|
|
|
|
4
|
for (@var) { |
71
|
6
|
100
|
|
|
|
38
|
push @options, { |
72
|
|
|
|
|
|
|
value => $_->[0], |
73
|
|
|
|
|
|
|
label => $_->[1], |
74
|
|
|
|
|
|
|
selected => $selected{$_->[0]} ? qq#$select_string="$select_string"# : '', |
75
|
|
|
|
|
|
|
}; |
76
|
|
|
|
|
|
|
} |
77
|
2
|
|
|
|
|
58
|
return \@options; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _html_box_loop { |
81
|
1
|
|
|
1
|
|
53
|
my ($htc, $token, $args) = @_; |
82
|
1
|
|
|
|
|
6
|
my $attr = $token->get_attributes; |
83
|
1
|
|
|
|
|
8
|
my $varstr = $htc->get_compiler->parse_var($htc, |
84
|
|
|
|
|
|
|
var => $attr->{NAME}, |
85
|
|
|
|
|
|
|
method_call => $htc->method_call, |
86
|
|
|
|
|
|
|
deref => $htc->deref, |
87
|
|
|
|
|
|
|
formatter_path => $htc->formatter_path, |
88
|
|
|
|
|
|
|
); |
89
|
1
|
|
|
|
|
133
|
my $expression = <<"EOM"; |
90
|
|
|
|
|
|
|
\{ |
91
|
|
|
|
|
|
|
my \$items = HTML::Template::Compiled::Plugin::HTML_Tags::_option_loop( |
92
|
|
|
|
|
|
|
"checked", |
93
|
|
|
|
|
|
|
$varstr, |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
for my \$_html_option_loop_entry (\@\$items) { |
96
|
|
|
|
|
|
|
my \$C = \\\$_html_option_loop_entry; |
97
|
|
|
|
|
|
|
EOM |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _html_option_loop { |
101
|
1
|
|
|
1
|
|
1532
|
my ($htc, $token, $args) = @_; |
102
|
1
|
|
|
|
|
6
|
my $attr = $token->get_attributes; |
103
|
1
|
|
|
|
|
9
|
my $varstr = $htc->get_compiler->parse_var($htc, |
104
|
|
|
|
|
|
|
var => $attr->{NAME}, |
105
|
|
|
|
|
|
|
method_call => $htc->method_call, |
106
|
|
|
|
|
|
|
deref => $htc->deref, |
107
|
|
|
|
|
|
|
formatter_path => $htc->formatter_path, |
108
|
|
|
|
|
|
|
); |
109
|
1
|
|
|
|
|
169
|
my $expression = <<"EOM"; |
110
|
|
|
|
|
|
|
\{ |
111
|
|
|
|
|
|
|
my \$items = HTML::Template::Compiled::Plugin::HTML_Tags::_option_loop( |
112
|
|
|
|
|
|
|
"selected", |
113
|
|
|
|
|
|
|
$varstr, |
114
|
|
|
|
|
|
|
); |
115
|
|
|
|
|
|
|
for my \$_html_option_loop_entry (\@\$items) { |
116
|
|
|
|
|
|
|
my \$C = \\\$_html_option_loop_entry; |
117
|
|
|
|
|
|
|
EOM |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _html_table { |
121
|
1
|
|
|
1
|
|
370
|
my ($htc, $token, $args) = @_; |
122
|
1
|
|
|
|
|
3
|
my $OUT = $args->{out}; |
123
|
1
|
|
|
|
|
6
|
my $attr = $token->get_attributes; |
124
|
1
|
|
|
|
|
6
|
my $varstr = $htc->get_compiler->parse_var($htc, |
125
|
|
|
|
|
|
|
var => $attr->{NAME}, |
126
|
|
|
|
|
|
|
method_call => $htc->method_call, |
127
|
|
|
|
|
|
|
deref => $htc->deref, |
128
|
|
|
|
|
|
|
formatter_path => $htc->formatter_path, |
129
|
|
|
|
|
|
|
); |
130
|
1
|
|
50
|
|
|
160
|
my $header = $attr->{HEADER} || 0; |
131
|
1
|
|
50
|
|
|
8
|
my $tr_attr = $attr->{TR_ATTR} || ''; |
132
|
1
|
|
50
|
|
|
7
|
my $td_attr = $attr->{TD_ATTR} || ''; |
133
|
1
|
|
50
|
|
|
6
|
my $th_attr = $attr->{TH_ATTR} || ''; |
134
|
1
|
|
50
|
|
|
7
|
my $table_attr = $attr->{TABLE_ATTR} || ''; |
135
|
1
|
|
|
|
|
2
|
for ($tr_attr, $td_attr, $th_attr, $table_attr) { |
136
|
4
|
|
|
|
|
8
|
s/'/\\'/g; |
137
|
|
|
|
|
|
|
} |
138
|
1
|
|
|
|
|
4
|
my $expression = qq#my \@aoa = \@{ +$varstr };\n#; |
139
|
1
|
|
|
|
|
8
|
$expression .= <<"EOM"; |
140
|
|
|
|
|
|
|
$OUT ''."\\n";
141
|
|
|
|
|
|
|
if ($header) \{ |
142
|
|
|
|
|
|
|
my \$header = shift \@aoa; |
143
|
|
|
|
|
|
|
$OUT join "", ' | ', (map {
144
|
|
|
|
|
|
|
qq# | \$_ | #
145
|
|
|
|
|
|
|
} \@\$header), ' | ', "\\n";
146
|
|
|
|
|
|
|
\} |
147
|
|
|
|
|
|
|
for (\@aoa) \{ |
148
|
|
|
|
|
|
|
$OUT join "\\n", ' | ', (map {
149
|
|
|
|
|
|
|
qq# | \$_# |
150
|
|
|
|
|
|
|
} \@\$_), ' | ', "\\n";
151
|
|
|
|
|
|
|
\} |
152
|
|
|
|
|
|
|
$OUT ' | '. "\\n"; |
153
|
|
|
|
|
|
|
EOM |
154
|
1
|
|
|
|
|
7
|
return $expression; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub _html_select { |
158
|
1
|
|
|
1
|
|
382
|
my ($htc, $token, $args) = @_; |
159
|
1
|
|
|
|
|
3
|
my $OUT = $args->{out}; |
160
|
1
|
|
|
|
|
5
|
my $attr = $token->get_attributes; |
161
|
1
|
|
|
|
|
8
|
my $varstr = $htc->get_compiler->parse_var($htc, |
162
|
|
|
|
|
|
|
var => $attr->{NAME}, |
163
|
|
|
|
|
|
|
method_call => $htc->method_call, |
164
|
|
|
|
|
|
|
deref => $htc->deref, |
165
|
|
|
|
|
|
|
formatter_path => $htc->formatter_path, |
166
|
|
|
|
|
|
|
); |
167
|
1
|
|
50
|
|
|
151
|
my $select_attr = $attr->{SELECT_ATTR} || ''; |
168
|
1
|
|
|
|
|
5
|
$select_attr =~ s/'/\\'/g; |
169
|
1
|
|
|
|
|
3
|
my $expression = qq#\{\nmy \$var = $varstr;\n#; |
170
|
1
|
|
|
|
|
4
|
$expression .= qq#my \$attr = '$select_attr';\n#; |
171
|
1
|
|
|
|
|
3
|
$expression .= <<'EOM'; |
172
|
|
|
|
|
|
|
my $name = $var->{name}; |
173
|
|
|
|
|
|
|
my $value = $var->{value}; |
174
|
|
|
|
|
|
|
my @options = @{ $var->{options} }; |
175
|
|
|
|
|
|
|
my $select = qq# |
176
|
|
|
|
|
|
|
$select .= HTML::Template::Compiled::Plugin::HTML_Tags::_options($value, @options); |
177
|
|
|
|
|
|
|
$select .= qq#\n\n#; |
178
|
|
|
|
|
|
|
EOM |
179
|
1
|
|
|
|
|
4
|
$expression .= qq#$OUT \$select;\n\}#; |
180
|
1
|
|
|
|
|
8
|
return $expression; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub _html_option { |
184
|
2
|
|
|
2
|
|
933
|
my ($htc, $token, $args) = @_; |
185
|
2
|
|
|
|
|
5
|
my $OUT = $args->{out}; |
186
|
2
|
|
|
|
|
19
|
my $attr = $token->get_attributes; |
187
|
2
|
|
|
|
|
12
|
my $varstr = $htc->get_compiler->parse_var($htc, |
188
|
|
|
|
|
|
|
var => $attr->{NAME}, |
189
|
|
|
|
|
|
|
method_call => $htc->method_call, |
190
|
|
|
|
|
|
|
deref => $htc->deref, |
191
|
|
|
|
|
|
|
formatter_path => $htc->formatter_path, |
192
|
|
|
|
|
|
|
); |
193
|
2
|
|
|
|
|
415
|
my $expression = qq! |
194
|
|
|
|
|
|
|
my \$aref = $varstr; |
195
|
|
|
|
|
|
|
my \@aoa = \@\$aref; |
196
|
|
|
|
|
|
|
!; |
197
|
2
|
|
|
|
|
7
|
$expression .= <<'EOM'; |
198
|
|
|
|
|
|
|
my $options = HTML::Template::Compiled::Plugin::HTML_Tags::_options(@aoa); |
199
|
|
|
|
|
|
|
EOM |
200
|
2
|
|
|
|
|
6
|
$expression .= qq#$OUT \$options;\n#; |
201
|
2
|
|
|
|
|
13
|
return $expression; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub _options { |
205
|
8
|
|
|
8
|
|
22376
|
my @aoa = @_; |
206
|
8
|
|
|
|
|
17
|
my $selected = shift @aoa; |
207
|
4
|
|
|
|
|
35
|
my %selected = defined $selected |
208
|
|
|
|
|
|
|
? ref $selected eq 'ARRAY' |
209
|
8
|
100
|
|
|
|
52
|
? (map { $_ => 1 } @$selected) |
|
|
50
|
|
|
|
|
|
210
|
|
|
|
|
|
|
: ($selected => 1) |
211
|
|
|
|
|
|
|
: (); |
212
|
|
|
|
|
|
|
my $options = join "\n", map { |
213
|
8
|
100
|
|
|
|
18
|
unless (ref $_ eq 'ARRAY') { |
|
20
|
|
|
|
|
62
|
|
214
|
|
|
|
|
|
|
# values and labels should be equal |
215
|
3
|
|
|
|
|
9
|
$_ = [$_, $_]; |
216
|
|
|
|
|
|
|
} |
217
|
20
|
|
|
|
|
73
|
my $escaped = HTML::Template::Compiled::Utils::escape_html($_->[0]); |
218
|
20
|
100
|
|
|
|
219
|
my $sel = $selected{ $_->[0] } ? 'selected="selected"' : ''; |
219
|
20
|
50
|
|
|
|
71
|
my $escaped_display = @$_ > 1 |
220
|
|
|
|
|
|
|
? HTML::Template::Compiled::Utils::escape_html($_->[1]) |
221
|
|
|
|
|
|
|
: $escaped; |
222
|
20
|
|
|
|
|
393
|
qq##; |
223
|
|
|
|
|
|
|
} @aoa; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
1; |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
__END__ |