line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package HTML::Transmorgify::FormDefault; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
608
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
6
|
1
|
|
|
1
|
|
5
|
use Digest::MD5 qw(md5_hex); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
7
|
1
|
|
|
1
|
|
5
|
use HTML::Transmorgify qw(dangling %variables $query_param $debug queue_intercept queue_capture run $debug rbuf postbuf capture_compile); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
116
|
|
8
|
1
|
|
|
1
|
|
720
|
use URI::Escape; |
|
1
|
|
|
|
|
1145
|
|
|
1
|
|
|
|
|
54
|
|
9
|
1
|
|
|
1
|
|
751
|
use HTML::Entities; |
|
1
|
|
|
|
|
4930
|
|
|
1
|
|
|
|
|
138
|
|
10
|
1
|
|
|
1
|
|
7
|
use Scalar::Util qw(refaddr blessed); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
11
|
1
|
|
|
1
|
|
727
|
use YAML; |
|
1
|
|
|
|
|
6449
|
|
|
1
|
|
|
|
|
1374
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @ISA = qw(HTML::Transmorgify Exporter); |
15
|
|
|
|
|
|
|
our @EXPORT = qw(validate_form_submission); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %tags; |
18
|
|
|
|
|
|
|
my $tag_package = { tag_package => __PACKAGE__ }; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @rtmp; |
21
|
|
|
|
|
|
|
our $default_enable = 1; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub add_tags |
24
|
|
|
|
|
|
|
{ |
25
|
1
|
|
|
1
|
0
|
2
|
my ($self, $tobj) = @_; |
26
|
1
|
|
|
|
|
20
|
$self->intercept_shared($tobj, __PACKAGE__, 65, %tags); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our @btmp; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
2
|
0
|
5
|
sub return_true { 1 } |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$tags{input} = undef; |
34
|
|
|
|
|
|
|
$tags{button} = undef; |
35
|
|
|
|
|
|
|
$tags{textarea} = undef; |
36
|
|
|
|
|
|
|
$tags{"/textarea"} = undef; |
37
|
|
|
|
|
|
|
$tags{select} = undef; |
38
|
|
|
|
|
|
|
$tags{"/select"} = undef; |
39
|
|
|
|
|
|
|
$tags{option} = undef; |
40
|
|
|
|
|
|
|
$tags{"/option"} = undef; |
41
|
|
|
|
|
|
|
$tags{"/form"} = \&dangling; |
42
|
|
|
|
|
|
|
$tags{form} = \&form_tag; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub qpval |
45
|
|
|
|
|
|
|
{ |
46
|
26
|
|
|
26
|
0
|
36
|
my ($name, $value) = @_; |
47
|
26
|
50
|
|
|
|
50
|
return '' unless $query_param->{$name}; |
48
|
26
|
100
|
|
|
|
45
|
if (ref $query_param->{$name}) { |
49
|
12
|
50
|
|
|
|
20
|
if (defined $value) { |
50
|
12
|
|
|
|
|
10
|
return grep { $_ eq $value } @{$query_param->{$name}}; |
|
32
|
|
|
|
|
62
|
|
|
12
|
|
|
|
|
23
|
|
51
|
|
|
|
|
|
|
} else { |
52
|
0
|
|
|
|
|
0
|
return ''; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} else { |
55
|
14
|
100
|
|
|
|
34
|
if (defined $value) { |
56
|
9
|
|
|
|
|
25
|
return $query_param->{$name} eq $value; |
57
|
|
|
|
|
|
|
} else { |
58
|
5
|
|
|
|
|
29
|
return $query_param->{$name}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub compile_time_gate |
64
|
|
|
|
|
|
|
{ |
65
|
42
|
|
|
42
|
0
|
47
|
my ($attr) = @_; |
66
|
42
|
50
|
|
|
|
108
|
unless ($attr->boolean('auto_default', undef, 1, raw => 1)) { |
67
|
0
|
0
|
|
|
|
0
|
print STDERR "GATE: Bailing early from $attr\n" if $debug; |
68
|
0
|
|
|
|
|
0
|
return 0; |
69
|
|
|
|
|
|
|
} |
70
|
42
|
50
|
|
|
|
329
|
if ($attr->boolean('readonly', undef, 0, raw => 1)) { |
71
|
0
|
0
|
|
|
|
0
|
print STDERR "GATE: Bailing early from $attr is read-only\n" if $debug; |
72
|
0
|
|
|
|
|
0
|
return 0; |
73
|
|
|
|
|
|
|
} |
74
|
42
|
|
|
|
|
275
|
$attr->hide('no_auto_defaults'); |
75
|
42
|
|
|
|
|
93
|
$attr->hide('readonly'); |
76
|
42
|
50
|
|
|
|
79
|
print STDERR "GATE: compile time okay for $attr\n" if $debug; |
77
|
42
|
|
|
|
|
105
|
return 1; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub run_time_gate |
81
|
|
|
|
|
|
|
{ |
82
|
33
|
|
|
33
|
0
|
38
|
my ($attr) = @_; |
83
|
33
|
50
|
33
|
|
|
160
|
unless ($query_param && %$query_param) { |
84
|
0
|
0
|
|
|
|
0
|
print STDERR "GATE: No query parameters\n" if $debug; |
85
|
0
|
|
|
|
|
0
|
return 0; |
86
|
|
|
|
|
|
|
} |
87
|
33
|
50
|
|
|
|
82
|
unless ($attr->boolean('auto_default', undef, 1)) { |
88
|
0
|
0
|
|
|
|
0
|
print STDERR "GATE: Bailing late from $attr\n" if $debug; |
89
|
0
|
|
|
|
|
0
|
return 0; |
90
|
|
|
|
|
|
|
} |
91
|
33
|
50
|
|
|
|
72
|
if ($attr->boolean('readonly', undef, 0)) { |
92
|
0
|
0
|
|
|
|
0
|
print STDERR "GATE: Bailing late from $attr is read-only\n" if $debug; |
93
|
0
|
|
|
|
|
0
|
return 0; |
94
|
|
|
|
|
|
|
} |
95
|
33
|
|
33
|
|
|
71
|
my $name = $attr->get('name') |
96
|
|
|
|
|
|
|
|| $attr->get('id'); |
97
|
33
|
50
|
|
|
|
60
|
unless ($name) { |
98
|
0
|
0
|
|
|
|
0
|
print STDERR "GATE: No name or id for $attr\n" if $debug; |
99
|
0
|
|
|
|
|
0
|
return 0; |
100
|
|
|
|
|
|
|
} |
101
|
33
|
100
|
|
|
|
61
|
unless (exists $query_param->{$name}) { |
102
|
7
|
50
|
|
|
|
12
|
print STDERR "GATE: No user input for $attr\n" if $debug; |
103
|
7
|
|
|
|
|
16
|
return 0; |
104
|
|
|
|
|
|
|
} |
105
|
26
|
50
|
|
|
|
37
|
print STDERR "GATE: run time time okay for $attr\n" if $debug; |
106
|
26
|
|
|
|
|
55
|
return $name; |
107
|
|
|
|
|
|
|
}; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub form_tag |
110
|
|
|
|
|
|
|
{ |
111
|
2
|
|
|
2
|
0
|
4
|
my ($fattr, $closed) = @_; |
112
|
2
|
50
|
|
|
|
6
|
die if $closed; |
113
|
|
|
|
|
|
|
|
114
|
2
|
|
|
|
|
4
|
my $default; |
115
|
|
|
|
|
|
|
|
116
|
2
|
50
|
|
|
|
6
|
return unless compile_time_gate($fattr); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $text_cb = sub { |
119
|
4
|
|
|
4
|
|
4
|
my ($attr, $closed) = @_; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
rbuf(sub { |
122
|
4
|
100
|
|
|
|
8
|
return 1 unless run_time_gate($attr); |
123
|
2
|
|
|
|
|
7
|
$attr->set(value => qpval($attr->get('name'))); |
124
|
4
|
|
|
|
|
16
|
}); |
125
|
2
|
|
|
|
|
11
|
}; |
126
|
|
|
|
|
|
|
|
127
|
2
|
|
|
|
|
3
|
my $vals = {}; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $radio_cb = sub { |
130
|
15
|
|
|
15
|
|
19
|
my ($attr, $closed) = @_; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
rbuf(sub { |
133
|
15
|
|
|
|
|
46
|
my $name = run_time_gate($attr); |
134
|
15
|
100
|
|
|
|
29
|
return 1 unless $name; |
135
|
11
|
|
|
|
|
26
|
my $value = $attr->get('value'); |
136
|
11
|
100
|
|
|
|
19
|
if (qpval($name, $value)) { |
137
|
7
|
|
|
|
|
19
|
$attr->set(checked => undef); |
138
|
|
|
|
|
|
|
} else { |
139
|
4
|
|
|
|
|
10
|
$attr->set(checked => 0); |
140
|
4
|
|
|
|
|
10
|
$attr->hide('checked'); |
141
|
|
|
|
|
|
|
} |
142
|
11
|
|
|
|
|
25
|
return 1; |
143
|
15
|
|
|
|
|
61
|
}); |
144
|
2
|
|
|
|
|
8
|
}; |
145
|
|
|
|
|
|
|
|
146
|
2
|
|
|
5
|
|
13
|
my $nothing = sub { 1 }; |
|
5
|
|
|
|
|
6
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
my $input_cb = sub { |
149
|
24
|
|
|
24
|
|
31
|
my ($attr, $closed) = @_; |
150
|
|
|
|
|
|
|
|
151
|
24
|
50
|
|
|
|
40
|
return 1 unless compile_time_gate($attr); |
152
|
|
|
|
|
|
|
|
153
|
24
|
|
|
|
|
151
|
my %handlers = ( |
154
|
|
|
|
|
|
|
text => $text_cb, |
155
|
|
|
|
|
|
|
password => $text_cb, |
156
|
|
|
|
|
|
|
radio => $radio_cb, |
157
|
|
|
|
|
|
|
checkbox => $radio_cb, |
158
|
|
|
|
|
|
|
submit => $nothing, |
159
|
|
|
|
|
|
|
hidden => $nothing, |
160
|
|
|
|
|
|
|
reset => $nothing, |
161
|
|
|
|
|
|
|
file => $nothing, # if we have some sort of caching, cache it! |
162
|
|
|
|
|
|
|
image => $nothing, |
163
|
|
|
|
|
|
|
button => $nothing, |
164
|
|
|
|
|
|
|
); |
165
|
|
|
|
|
|
|
|
166
|
24
|
|
|
|
|
54
|
my $type = lc($attr->get('type')); |
167
|
24
|
50
|
|
|
|
234
|
die unless $handlers{$type}; |
168
|
24
|
|
|
|
|
41
|
$handlers{$type}->($attr, $closed); |
169
|
24
|
|
|
|
|
63
|
$attr->eval_at_runtime(1); |
170
|
24
|
|
|
|
|
83
|
return 1; |
171
|
2
|
|
|
|
|
9
|
}; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
my $textarea_cb = sub { |
174
|
2
|
|
|
2
|
|
4
|
my ($attr, $closed) = @_; |
175
|
2
|
50
|
|
|
|
6
|
return 1 unless compile_time_gate($attr); |
176
|
|
|
|
|
|
|
|
177
|
2
|
|
|
|
|
9
|
$attr->eval_at_runtime(1); |
178
|
2
|
|
|
|
|
8
|
my ($b, $deferred) = capture_compile('textarea', $attr, undef, %HTML::Transmorgify::queued_intercepts); |
179
|
|
|
|
|
|
|
|
180
|
2
|
|
|
|
|
16
|
my $b2 = []; |
181
|
|
|
|
|
|
|
{ |
182
|
2
|
|
|
|
|
3
|
local($HTML::Transmorgify::rbuf) = $b2; |
|
2
|
|
|
|
|
3
|
|
183
|
2
|
|
|
|
|
6
|
for my $ccb (@HTML::Transmorgify::queued_captures) { |
184
|
0
|
|
|
|
|
0
|
$ccb->($b); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
postbuf(sub { |
189
|
2
|
|
|
|
|
5
|
my $name = run_time_gate($attr); |
190
|
|
|
|
|
|
|
|
191
|
2
|
100
|
|
|
|
6
|
if ($name) { |
192
|
1
|
|
|
|
|
3
|
$HTML::Transmorgify::result->[0] .= encode_entities(qpval($name)) . ""; |
193
|
|
|
|
|
|
|
} else { |
194
|
1
|
|
|
|
|
7
|
run($b); |
195
|
1
|
|
|
|
|
3
|
run($b2); |
196
|
1
|
|
|
|
|
4
|
$deferred->doit(); |
197
|
1
|
|
|
|
|
2
|
$HTML::Transmorgify::result->[0] .= ""; |
198
|
|
|
|
|
|
|
} |
199
|
2
|
|
|
|
|
13
|
}); |
200
|
2
|
|
|
|
|
5
|
return 1; |
201
|
2
|
|
|
|
|
10
|
}; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
my $select_cb = sub { |
204
|
2
|
|
|
2
|
|
4
|
my ($attr, $closed) = @_; |
205
|
2
|
50
|
|
|
|
7
|
return 1 unless compile_time_gate($attr); |
206
|
2
|
|
|
|
|
6
|
$attr->eval_at_runtime(1); |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
my $option_cb = sub { |
209
|
12
|
|
|
|
|
16
|
my ($oattr, $closed) = @_; |
210
|
12
|
50
|
|
|
|
18
|
return 1 unless compile_time_gate($attr); |
211
|
|
|
|
|
|
|
|
212
|
12
|
|
|
|
|
27
|
$oattr->eval_at_runtime(1); |
213
|
|
|
|
|
|
|
|
214
|
12
|
|
|
|
|
11
|
my $get_value; |
215
|
12
|
100
|
|
|
|
23
|
if (defined $oattr->raw('value')) { |
216
|
|
|
|
|
|
|
$get_value = sub { |
217
|
6
|
|
|
|
|
12
|
$oattr->get('value'); |
218
|
6
|
|
|
|
|
17
|
}; |
219
|
|
|
|
|
|
|
} else { |
220
|
6
|
|
|
|
|
6
|
my $b; |
221
|
|
|
|
|
|
|
queue_capture(sub { |
222
|
6
|
|
|
|
|
20
|
$b = shift; |
223
|
6
|
|
|
|
|
24
|
}); |
224
|
|
|
|
|
|
|
$get_value = sub { |
225
|
6
|
|
|
|
|
18
|
local(@btmp) = (''); |
226
|
6
|
|
|
|
|
15
|
run($b, \@btmp); |
227
|
6
|
|
|
|
|
14
|
return $btmp[0]; |
228
|
6
|
|
|
|
|
17
|
}; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
rbuf(sub { |
232
|
12
|
|
|
|
|
20
|
my $name = run_time_gate($attr); |
233
|
12
|
50
|
|
|
|
22
|
return 1 unless $name; |
234
|
|
|
|
|
|
|
|
235
|
12
|
|
|
|
|
22
|
my $value = $get_value->(); |
236
|
|
|
|
|
|
|
|
237
|
12
|
100
|
|
|
|
21
|
if (qpval($name, $value)) { |
238
|
4
|
|
|
|
|
12
|
$oattr->set(selected => undef); |
239
|
|
|
|
|
|
|
} else { |
240
|
8
|
|
|
|
|
21
|
$oattr->set(selected => 0); |
241
|
8
|
|
|
|
|
25
|
$oattr->hide('selected'); |
242
|
|
|
|
|
|
|
} |
243
|
12
|
|
|
|
|
51
|
}); |
244
|
2
|
|
|
|
|
9
|
}; |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
queue_intercept(__PACKAGE__, |
247
|
|
|
|
|
|
|
option => $option_cb, |
248
|
2
|
|
|
|
|
5
|
"/select", => sub { 1 }, |
249
|
2
|
|
|
|
|
11
|
); |
250
|
2
|
|
|
|
|
15
|
}; |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
|
253
|
2
|
|
|
|
|
12
|
queue_intercept(__PACKAGE__, |
254
|
|
|
|
|
|
|
input => $input_cb, |
255
|
|
|
|
|
|
|
textarea => $textarea_cb, |
256
|
|
|
|
|
|
|
select => $select_cb, |
257
|
|
|
|
|
|
|
'/form' => \&return_true, |
258
|
|
|
|
|
|
|
); |
259
|
2
|
|
|
|
|
6
|
return 1; |
260
|
|
|
|
|
|
|
}; |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
__END__ |