| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::Form; |
|
2
|
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
478423
|
use strict; |
|
|
10
|
|
|
|
|
94
|
|
|
|
10
|
|
|
|
|
264
|
|
|
4
|
10
|
|
|
10
|
|
4501
|
use URI; |
|
|
10
|
|
|
|
|
62355
|
|
|
|
10
|
|
|
|
|
277
|
|
|
5
|
10
|
|
|
10
|
|
60
|
use Carp (); |
|
|
10
|
|
|
|
|
17
|
|
|
|
10
|
|
|
|
|
110
|
|
|
6
|
10
|
|
|
10
|
|
4719
|
use Encode (); |
|
|
10
|
|
|
|
|
132242
|
|
|
|
10
|
|
|
|
|
12368
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '6.10'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %form_tags = map {$_ => 1} qw(input textarea button select option); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my %type2class = ( |
|
13
|
|
|
|
|
|
|
text => "TextInput", |
|
14
|
|
|
|
|
|
|
password => "TextInput", |
|
15
|
|
|
|
|
|
|
hidden => "TextInput", |
|
16
|
|
|
|
|
|
|
textarea => "TextInput", |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
"reset" => "IgnoreInput", |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
radio => "ListInput", |
|
21
|
|
|
|
|
|
|
checkbox => "ListInput", |
|
22
|
|
|
|
|
|
|
option => "ListInput", |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
button => "SubmitInput", |
|
25
|
|
|
|
|
|
|
submit => "SubmitInput", |
|
26
|
|
|
|
|
|
|
image => "ImageInput", |
|
27
|
|
|
|
|
|
|
file => "FileInput", |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
keygen => "KeygenInput", |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# The new HTML5 input types |
|
33
|
|
|
|
|
|
|
%type2class = (%type2class, map { $_ => 'TextInput' } qw( |
|
34
|
|
|
|
|
|
|
tel search url email |
|
35
|
|
|
|
|
|
|
datetime date month week time datetime-local |
|
36
|
|
|
|
|
|
|
number range color |
|
37
|
|
|
|
|
|
|
)); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# ABSTRACT: Class that represents an HTML form element |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub parse |
|
43
|
|
|
|
|
|
|
{ |
|
44
|
34
|
|
|
34
|
1
|
44143
|
my $class = shift; |
|
45
|
34
|
|
|
|
|
68
|
my $html = shift; |
|
46
|
34
|
100
|
|
|
|
137
|
unshift(@_, "base") if @_ == 1; |
|
47
|
34
|
|
|
|
|
116
|
my %opt = @_; |
|
48
|
|
|
|
|
|
|
|
|
49
|
34
|
|
|
|
|
3883
|
require HTML::TokeParser; |
|
50
|
34
|
100
|
|
|
|
79685
|
my $p = HTML::TokeParser->new(ref($html) ? $html->decoded_content(ref => 1) : \$html); |
|
51
|
34
|
50
|
|
|
|
4933
|
Carp::croak "Failed to create HTML::TokeParser object" unless $p; |
|
52
|
|
|
|
|
|
|
|
|
53
|
34
|
|
|
|
|
77
|
my $base_uri = delete $opt{base}; |
|
54
|
34
|
|
|
|
|
64
|
my $charset = delete $opt{charset}; |
|
55
|
34
|
|
|
|
|
64
|
my $strict = delete $opt{strict}; |
|
56
|
34
|
|
|
|
|
66
|
my $verbose = delete $opt{verbose}; |
|
57
|
|
|
|
|
|
|
|
|
58
|
34
|
50
|
|
|
|
128
|
if ($^W) { |
|
59
|
0
|
|
|
|
|
0
|
Carp::carp("Unrecognized option $_ in HTML::Form->parse") for sort keys %opt; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
34
|
100
|
|
|
|
86
|
unless (defined $base_uri) { |
|
63
|
3
|
50
|
|
|
|
7
|
if (ref($html)) { |
|
64
|
3
|
|
|
|
|
12
|
$base_uri = $html->base; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
else { |
|
67
|
0
|
|
|
|
|
0
|
Carp::croak("HTML::Form::parse: No \$base_uri provided"); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
34
|
50
|
|
|
|
82
|
unless (defined $charset) { |
|
71
|
34
|
100
|
100
|
|
|
120
|
if (ref($html) and $html->can("content_charset")) { |
|
72
|
2
|
|
|
|
|
20
|
$charset = $html->content_charset; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
34
|
100
|
|
|
|
423
|
unless ($charset) { |
|
75
|
33
|
|
|
|
|
51
|
$charset = "UTF-8"; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
34
|
|
|
|
|
79
|
my @forms; |
|
80
|
|
|
|
|
|
|
my $f; # current form |
|
81
|
|
|
|
|
|
|
|
|
82
|
34
|
|
|
|
|
0
|
my %openselect; # index to the open instance of a select |
|
83
|
|
|
|
|
|
|
|
|
84
|
34
|
|
|
|
|
105
|
while (my $t = $p->get_tag) { |
|
85
|
60
|
|
|
|
|
3308
|
my($tag,$attr) = @$t; |
|
86
|
60
|
100
|
|
|
|
181
|
if ($tag eq "form") { |
|
|
|
50
|
|
|
|
|
|
|
87
|
38
|
|
|
|
|
67
|
my $action = delete $attr->{'action'}; |
|
88
|
38
|
100
|
|
|
|
94
|
$action = "" unless defined $action; |
|
89
|
38
|
|
|
|
|
167
|
$action = URI->new_abs($action, $base_uri); |
|
90
|
|
|
|
|
|
|
$f = $class->new($attr->{'method'}, |
|
91
|
|
|
|
|
|
|
$action, |
|
92
|
38
|
|
|
|
|
67383
|
$attr->{'enctype'}); |
|
93
|
38
|
100
|
|
|
|
122
|
$f->accept_charset($attr->{'accept-charset'}) if $attr->{'accept-charset'}; |
|
94
|
38
|
|
|
|
|
76
|
$f->{default_charset} = $charset; |
|
95
|
38
|
|
|
|
|
83
|
$f->{attr} = $attr; |
|
96
|
38
|
100
|
|
|
|
87
|
$f->strict(1) if $strict; |
|
97
|
38
|
|
|
|
|
72
|
%openselect = (); |
|
98
|
38
|
|
|
|
|
66
|
push(@forms, $f); |
|
99
|
38
|
|
|
|
|
59
|
my(%labels, $current_label); |
|
100
|
38
|
|
|
|
|
129
|
while (my $t = $p->get_tag) { |
|
101
|
208
|
|
|
|
|
4789
|
my($tag, $attr) = @$t; |
|
102
|
208
|
100
|
|
|
|
464
|
last if $tag eq "/form"; |
|
103
|
|
|
|
|
|
|
|
|
104
|
172
|
100
|
|
|
|
289
|
if ($tag ne 'textarea') { |
|
105
|
|
|
|
|
|
|
# if we are inside a label tag, then keep |
|
106
|
|
|
|
|
|
|
# appending any text to the current label |
|
107
|
169
|
100
|
|
|
|
269
|
if(defined $current_label) { |
|
108
|
|
|
|
|
|
|
$current_label = join " ", |
|
109
|
13
|
50
|
|
|
|
26
|
grep { defined and length } |
|
|
26
|
|
|
|
|
644
|
|
|
110
|
|
|
|
|
|
|
$current_label, |
|
111
|
|
|
|
|
|
|
$p->get_phrase; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
172
|
100
|
|
|
|
264
|
if ($tag eq "input") { |
|
116
|
|
|
|
|
|
|
$attr->{value_name} = |
|
117
|
|
|
|
|
|
|
exists $attr->{id} && exists $labels{$attr->{id}} ? $labels{$attr->{id}} : |
|
118
|
66
|
100
|
100
|
|
|
299
|
defined $current_label ? $current_label : |
|
|
|
100
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$p->get_phrase; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
172
|
100
|
|
|
|
4262
|
if ($tag eq "label") { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
123
|
7
|
|
|
|
|
16
|
$current_label = $p->get_phrase; |
|
124
|
|
|
|
|
|
|
$labels{ $attr->{for} } = $current_label |
|
125
|
7
|
100
|
|
|
|
423
|
if exists $attr->{for}; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
elsif ($tag eq "/label") { |
|
128
|
7
|
|
|
|
|
16
|
$current_label = undef; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
elsif ($tag eq "input") { |
|
131
|
66
|
|
100
|
|
|
172
|
my $type = delete $attr->{type} || "text"; |
|
132
|
66
|
|
|
|
|
225
|
$f->push_input($type, $attr, $verbose); |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
elsif ($tag eq "button") { |
|
135
|
2
|
|
50
|
|
|
7
|
my $type = delete $attr->{type} || "submit"; |
|
136
|
2
|
|
|
|
|
4
|
$f->push_input($type, $attr, $verbose); |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
elsif ($tag eq "textarea") { |
|
139
|
|
|
|
|
|
|
$attr->{textarea_value} = $attr->{value} |
|
140
|
3
|
50
|
|
|
|
8
|
if exists $attr->{value}; |
|
141
|
3
|
|
|
|
|
21
|
my $text = $p->get_text("/textarea"); |
|
142
|
3
|
|
|
|
|
157
|
$attr->{value} = $text; |
|
143
|
3
|
|
|
|
|
9
|
$f->push_input("textarea", $attr, $verbose); |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
elsif ($tag eq "select") { |
|
146
|
|
|
|
|
|
|
# rename attributes reserved to come for the option tag |
|
147
|
29
|
|
|
|
|
60
|
for ("value", "value_name") { |
|
148
|
|
|
|
|
|
|
$attr->{"select_$_"} = delete $attr->{$_} |
|
149
|
58
|
100
|
|
|
|
108
|
if exists $attr->{$_}; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
# count this new select option separately |
|
152
|
29
|
|
|
|
|
44
|
my $name = $attr->{name}; |
|
153
|
29
|
100
|
|
|
|
58
|
$name = "" unless defined $name; |
|
154
|
29
|
|
|
|
|
59
|
$openselect{$name}++; |
|
155
|
|
|
|
|
|
|
|
|
156
|
29
|
|
|
|
|
67
|
while ($t = $p->get_tag) { |
|
157
|
126
|
|
|
|
|
2729
|
my $tag = shift @$t; |
|
158
|
126
|
100
|
|
|
|
260
|
last if $tag eq "/select"; |
|
159
|
101
|
50
|
|
|
|
159
|
next if $tag =~ m,/?optgroup,; |
|
160
|
101
|
100
|
|
|
|
160
|
next if $tag eq "/option"; |
|
161
|
76
|
100
|
|
|
|
114
|
if ($tag eq "option") { |
|
162
|
71
|
|
|
|
|
64
|
my %a = %{$t->[0]}; |
|
|
71
|
|
|
|
|
189
|
|
|
163
|
|
|
|
|
|
|
# rename keys so they don't clash with %attr |
|
164
|
71
|
|
|
|
|
144
|
for (keys %a) { |
|
165
|
56
|
100
|
|
|
|
98
|
next if $_ eq "value"; |
|
166
|
25
|
|
|
|
|
62
|
$a{"option_$_"} = delete $a{$_}; |
|
167
|
|
|
|
|
|
|
} |
|
168
|
71
|
|
|
|
|
187
|
while (my($k,$v) = each %$attr) { |
|
169
|
123
|
|
|
|
|
299
|
$a{$k} = $v; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
71
|
|
|
|
|
165
|
$a{value_name} = $p->get_trimmed_text; |
|
172
|
|
|
|
|
|
|
$a{value} = delete $a{value_name} |
|
173
|
71
|
100
|
|
|
|
3764
|
unless defined $a{value}; |
|
174
|
71
|
|
|
|
|
159
|
$a{idx} = $openselect{$name}; |
|
175
|
71
|
|
|
|
|
161
|
$f->push_input("option", \%a, $verbose); |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
else { |
|
178
|
5
|
50
|
|
|
|
11
|
warn("Bad |
|
179
|
5
|
50
|
100
|
|
|
44
|
if ($tag eq "/form" || |
|
|
|
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
180
|
|
|
|
|
|
|
$tag eq "input" || |
|
181
|
|
|
|
|
|
|
$tag eq "textarea" || |
|
182
|
|
|
|
|
|
|
$tag eq "select" || |
|
183
|
|
|
|
|
|
|
$tag eq "keygen") |
|
184
|
|
|
|
|
|
|
{ |
|
185
|
|
|
|
|
|
|
# MSIE implicitly terminates the |
|
186
|
|
|
|
|
|
|
# try to do the same. Actually the MSIE behaviour |
|
187
|
|
|
|
|
|
|
# appears really strange: and |
|
188
|
|
|
|
|
|
|
# do implicitly close, but not |
|
189
|
|
|
|
|
|
|
# . |
|
190
|
4
|
100
|
|
|
|
19
|
my $type = ($tag =~ s,^/,,) ? "E" : "S"; |
|
191
|
4
|
|
|
|
|
16
|
$p->unget_token([$type, $tag, @$t]); |
|
192
|
4
|
|
|
|
|
33
|
last; |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
elsif ($tag eq "keygen") { |
|
198
|
1
|
|
|
|
|
3
|
$f->push_input("keygen", $attr, $verbose); |
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
elsif ($form_tags{$tag}) { |
|
203
|
0
|
0
|
|
|
|
0
|
warn("<$tag> outside |
|
204
|
|
|
|
|
|
|
} |
|
205
|
|
|
|
|
|
|
} |
|
206
|
34
|
|
|
|
|
832
|
for (@forms) { |
|
207
|
38
|
|
|
|
|
100
|
$_->fixup; |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
|
|
210
|
34
|
100
|
|
|
|
593
|
wantarray ? @forms : $forms[0]; |
|
211
|
|
|
|
|
|
|
} |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub new { |
|
214
|
49
|
|
|
49
|
0
|
33346
|
my $class = shift; |
|
215
|
49
|
|
|
|
|
129
|
my $self = bless {}, $class; |
|
216
|
49
|
|
100
|
|
|
286
|
$self->{method} = uc(shift || "GET"); |
|
217
|
49
|
|
33
|
|
|
171
|
$self->{action} = shift || Carp::croak("No action defined"); |
|
218
|
49
|
|
100
|
|
|
489
|
$self->{enctype} = lc(shift || "application/x-www-form-urlencoded"); |
|
219
|
49
|
|
|
|
|
90
|
$self->{accept_charset} = "UNKNOWN"; |
|
220
|
49
|
|
|
|
|
86
|
$self->{default_charset} = "UTF-8"; |
|
221
|
49
|
|
|
|
|
101
|
$self->{inputs} = [@_]; |
|
222
|
49
|
|
|
|
|
110
|
$self; |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub push_input |
|
227
|
|
|
|
|
|
|
{ |
|
228
|
154
|
|
|
154
|
1
|
313
|
my($self, $type, $attr, $verbose) = @_; |
|
229
|
154
|
|
|
|
|
247
|
$type = lc $type; |
|
230
|
154
|
|
|
|
|
262
|
my $class = $type2class{$type}; |
|
231
|
154
|
100
|
|
|
|
279
|
unless ($class) { |
|
232
|
1
|
50
|
|
|
|
300
|
Carp::carp("Unknown input type '$type'") if $verbose; |
|
233
|
1
|
|
|
|
|
8
|
$class = "TextInput"; |
|
234
|
|
|
|
|
|
|
} |
|
235
|
154
|
|
|
|
|
252
|
$class = "HTML::Form::$class"; |
|
236
|
154
|
|
|
|
|
207
|
my @extra; |
|
237
|
154
|
100
|
|
|
|
316
|
push(@extra, readonly => 1) if $type eq "hidden"; |
|
238
|
154
|
100
|
|
|
|
306
|
push(@extra, strict => 1) if $self->{strict}; |
|
239
|
154
|
100
|
100
|
|
|
295
|
if ($type eq "file" && exists $attr->{value}) { |
|
240
|
|
|
|
|
|
|
# it's not safe to trust the value set by the server |
|
241
|
|
|
|
|
|
|
# the user always needs to explicitly set the names of files to upload |
|
242
|
2
|
|
|
|
|
7
|
$attr->{orig_value} = delete $attr->{value}; |
|
243
|
|
|
|
|
|
|
} |
|
244
|
154
|
|
|
|
|
184
|
delete $attr->{type}; # don't confuse the type argument |
|
245
|
154
|
|
|
|
|
661
|
my $input = $class->new(type => $type, %$attr, @extra); |
|
246
|
154
|
|
|
|
|
386
|
$input->add_to_form($self); |
|
247
|
|
|
|
|
|
|
} |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
BEGIN { |
|
252
|
|
|
|
|
|
|
# Set up some accessors |
|
253
|
10
|
|
|
10
|
|
37
|
for my $m (qw(method action enctype accept_charset)) { |
|
254
|
10
|
|
|
10
|
|
85
|
no strict 'refs'; |
|
|
10
|
|
|
|
|
19
|
|
|
|
10
|
|
|
|
|
976
|
|
|
255
|
40
|
|
|
|
|
119
|
*{$m} = sub { |
|
256
|
86
|
|
|
86
|
|
6560
|
my $self = shift; |
|
257
|
86
|
|
|
|
|
178
|
my $old = $self->{$m}; |
|
258
|
86
|
100
|
|
|
|
155
|
$self->{$m} = shift if @_; |
|
259
|
86
|
|
|
|
|
242
|
$old; |
|
260
|
40
|
|
|
|
|
113
|
}; |
|
261
|
|
|
|
|
|
|
} |
|
262
|
10
|
|
|
|
|
43796
|
*uri = \&action; # alias |
|
263
|
|
|
|
|
|
|
} |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub attr { |
|
267
|
2
|
|
|
2
|
1
|
1521
|
my $self = shift; |
|
268
|
2
|
|
|
|
|
4
|
my $name = shift; |
|
269
|
2
|
50
|
|
|
|
6
|
return undef unless defined $name; |
|
270
|
|
|
|
|
|
|
|
|
271
|
2
|
|
|
|
|
5
|
my $old = $self->{attr}{$name}; |
|
272
|
2
|
50
|
|
|
|
6
|
$self->{attr}{$name} = shift if @_; |
|
273
|
2
|
|
|
|
|
12
|
return $old; |
|
274
|
|
|
|
|
|
|
} |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
sub strict { |
|
278
|
6
|
|
|
6
|
1
|
10
|
my $self = shift; |
|
279
|
6
|
|
|
|
|
15
|
my $old = $self->{strict}; |
|
280
|
6
|
50
|
|
|
|
52
|
if (@_) { |
|
281
|
6
|
|
|
|
|
28
|
$self->{strict} = shift; |
|
282
|
6
|
|
|
|
|
36
|
for my $input (@{$self->{inputs}}) { |
|
|
6
|
|
|
|
|
24
|
|
|
283
|
7
|
|
|
|
|
19
|
$input->strict($self->{strict}); |
|
284
|
|
|
|
|
|
|
} |
|
285
|
|
|
|
|
|
|
} |
|
286
|
6
|
|
|
|
|
10
|
return $old; |
|
287
|
|
|
|
|
|
|
} |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
sub inputs |
|
292
|
|
|
|
|
|
|
{ |
|
293
|
45
|
|
|
45
|
1
|
76
|
my $self = shift; |
|
294
|
45
|
|
|
|
|
48
|
@{$self->{'inputs'}}; |
|
|
45
|
|
|
|
|
159
|
|
|
295
|
|
|
|
|
|
|
} |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
sub find_input |
|
300
|
|
|
|
|
|
|
{ |
|
301
|
179
|
|
|
179
|
1
|
18156
|
my($self, $selector, $type, $no) = @_; |
|
302
|
179
|
100
|
100
|
|
|
702
|
Carp::croak "Invalid index $no" |
|
303
|
|
|
|
|
|
|
if defined $no && $no < 1; |
|
304
|
177
|
100
|
|
|
|
312
|
if (wantarray) { |
|
305
|
4
|
100
|
|
|
|
108
|
warn "find_input called in list context with index specified\n" |
|
306
|
|
|
|
|
|
|
if defined $no; |
|
307
|
4
|
|
|
|
|
16
|
my @res; |
|
308
|
|
|
|
|
|
|
my $c; |
|
309
|
4
|
|
|
|
|
64
|
for (@{$self->{'inputs'}}) { |
|
|
4
|
|
|
|
|
19
|
|
|
310
|
11
|
100
|
|
|
|
26
|
if ( defined($selector) ) { |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
# an input that explicitly has no name |
|
313
|
9
|
100
|
|
|
|
17
|
if ( ref($selector) eq 'SCALAR' ) { |
|
314
|
|
|
|
|
|
|
next |
|
315
|
4
|
100
|
66
|
|
|
13
|
if !defined($$selector) && $_->{name}; |
|
316
|
|
|
|
|
|
|
} |
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
# an input that does not fit this selector |
|
319
|
|
|
|
|
|
|
else { |
|
320
|
|
|
|
|
|
|
next |
|
321
|
5
|
100
|
|
|
|
10
|
if !$_->selected($selector); |
|
322
|
|
|
|
|
|
|
} |
|
323
|
|
|
|
|
|
|
} |
|
324
|
7
|
50
|
66
|
|
|
28
|
next if $type && $type ne $_->{type}; |
|
325
|
7
|
|
|
|
|
13
|
$c++; |
|
326
|
7
|
50
|
33
|
|
|
16
|
next if $no && $no != $c; |
|
327
|
7
|
|
|
|
|
16
|
push(@res, $_); |
|
328
|
|
|
|
|
|
|
} |
|
329
|
4
|
|
|
|
|
32
|
return @res; |
|
330
|
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
} |
|
332
|
|
|
|
|
|
|
else { |
|
333
|
173
|
|
100
|
|
|
461
|
$no ||= 1; |
|
334
|
173
|
|
|
|
|
197
|
for (@{$self->{'inputs'}}) { |
|
|
173
|
|
|
|
|
337
|
|
|
335
|
594
|
50
|
|
|
|
896
|
if ( defined($selector) ) { |
|
336
|
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
# an input that explicitly has no name |
|
338
|
594
|
100
|
|
|
|
756
|
if ( ref($selector) eq 'SCALAR' ) { |
|
339
|
|
|
|
|
|
|
next |
|
340
|
19
|
100
|
66
|
|
|
54
|
if !defined($$selector) && $_->{name}; |
|
341
|
|
|
|
|
|
|
} |
|
342
|
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
# an input that does not fit this selector |
|
344
|
|
|
|
|
|
|
else { |
|
345
|
|
|
|
|
|
|
next |
|
346
|
575
|
100
|
|
|
|
839
|
if !$_->selected($selector); |
|
347
|
|
|
|
|
|
|
} |
|
348
|
|
|
|
|
|
|
} |
|
349
|
170
|
100
|
100
|
|
|
437
|
next if $type && $type ne $_->{type}; |
|
350
|
162
|
100
|
|
|
|
315
|
next if --$no; |
|
351
|
140
|
|
|
|
|
360
|
return $_; |
|
352
|
|
|
|
|
|
|
} |
|
353
|
33
|
|
|
|
|
82
|
return undef; |
|
354
|
|
|
|
|
|
|
} |
|
355
|
|
|
|
|
|
|
} |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
sub fixup |
|
358
|
|
|
|
|
|
|
{ |
|
359
|
38
|
|
|
38
|
0
|
62
|
my $self = shift; |
|
360
|
38
|
|
|
|
|
78
|
for (@{$self->{'inputs'}}) { |
|
|
38
|
|
|
|
|
82
|
|
|
361
|
105
|
|
|
|
|
242
|
$_->fixup; |
|
362
|
|
|
|
|
|
|
} |
|
363
|
|
|
|
|
|
|
} |
|
364
|
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
sub value |
|
368
|
|
|
|
|
|
|
{ |
|
369
|
41
|
|
|
41
|
1
|
15399
|
my $self = shift; |
|
370
|
41
|
|
|
|
|
74
|
my $key = shift; |
|
371
|
41
|
|
|
|
|
96
|
my $input = $self->find_input($key); |
|
372
|
41
|
50
|
|
|
|
85
|
unless ($input) { |
|
373
|
0
|
0
|
|
|
|
0
|
Carp::croak("No such field '$key'") if $self->{strict}; |
|
374
|
0
|
0
|
|
|
|
0
|
return undef unless @_; |
|
375
|
0
|
|
|
|
|
0
|
$input = $self->push_input("text", { name => $key, value => "" }); |
|
376
|
|
|
|
|
|
|
} |
|
377
|
41
|
|
|
|
|
81
|
local $Carp::CarpLevel = 1; |
|
378
|
41
|
|
|
|
|
105
|
$input->value(@_); |
|
379
|
|
|
|
|
|
|
} |
|
380
|
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
sub param { |
|
383
|
32
|
|
|
32
|
1
|
9518
|
my $self = shift; |
|
384
|
32
|
100
|
|
|
|
64
|
if (@_) { |
|
385
|
30
|
|
|
|
|
43
|
my $name = shift; |
|
386
|
30
|
|
|
|
|
35
|
my @inputs; |
|
387
|
30
|
|
|
|
|
43
|
for ($self->inputs) { |
|
388
|
186
|
|
|
|
|
257
|
my $n = $_->name; |
|
389
|
186
|
100
|
66
|
|
|
454
|
next if !defined($n) || $n ne $name; |
|
390
|
51
|
|
|
|
|
75
|
push(@inputs, $_); |
|
391
|
|
|
|
|
|
|
} |
|
392
|
|
|
|
|
|
|
|
|
393
|
30
|
100
|
|
|
|
56
|
if (@_) { |
|
394
|
|
|
|
|
|
|
# set |
|
395
|
8
|
50
|
|
|
|
27
|
Carp::croak "No '$name' parameter exists" unless @inputs; |
|
396
|
8
|
|
|
|
|
14
|
my @v = @_; |
|
397
|
8
|
100
|
100
|
|
|
25
|
@v = @{$v[0]} if @v == 1 && ref($v[0]); |
|
|
3
|
|
|
|
|
6
|
|
|
398
|
8
|
|
|
|
|
15
|
while (@v) { |
|
399
|
9
|
|
|
|
|
13
|
my $v = shift @v; |
|
400
|
9
|
|
|
|
|
9
|
my $err; |
|
401
|
9
|
|
|
|
|
28
|
for my $i (0 .. @inputs-1) { |
|
402
|
16
|
|
|
|
|
20
|
eval { |
|
403
|
16
|
|
|
|
|
32
|
$inputs[$i]->value($v); |
|
404
|
|
|
|
|
|
|
}; |
|
405
|
16
|
100
|
|
|
|
263
|
unless ($@) { |
|
406
|
7
|
|
|
|
|
11
|
undef($err); |
|
407
|
7
|
|
|
|
|
9
|
splice(@inputs, $i, 1); |
|
408
|
7
|
|
|
|
|
10
|
last; |
|
409
|
|
|
|
|
|
|
} |
|
410
|
9
|
|
66
|
|
|
28
|
$err ||= $@; |
|
411
|
|
|
|
|
|
|
} |
|
412
|
9
|
100
|
|
|
|
116
|
Carp::croak $err if $err; |
|
413
|
|
|
|
|
|
|
} |
|
414
|
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
# the rest of the input should be cleared |
|
416
|
6
|
|
|
|
|
11
|
for (@inputs) { |
|
417
|
6
|
|
|
|
|
11
|
$_->value(undef); |
|
418
|
|
|
|
|
|
|
} |
|
419
|
|
|
|
|
|
|
} |
|
420
|
|
|
|
|
|
|
else { |
|
421
|
|
|
|
|
|
|
# get |
|
422
|
22
|
|
|
|
|
24
|
my @v; |
|
423
|
22
|
|
|
|
|
29
|
for (@inputs) { |
|
424
|
35
|
100
|
|
|
|
68
|
if (defined(my $v = $_->value)) { |
|
425
|
22
|
|
|
|
|
38
|
push(@v, $v); |
|
426
|
|
|
|
|
|
|
} |
|
427
|
|
|
|
|
|
|
} |
|
428
|
22
|
100
|
|
|
|
118
|
return wantarray ? @v : $v[0]; |
|
429
|
|
|
|
|
|
|
} |
|
430
|
|
|
|
|
|
|
} |
|
431
|
|
|
|
|
|
|
else { |
|
432
|
|
|
|
|
|
|
# list parameter names |
|
433
|
2
|
|
|
|
|
3
|
my @n; |
|
434
|
|
|
|
|
|
|
my %seen; |
|
435
|
2
|
|
|
|
|
5
|
for ($self->inputs) { |
|
436
|
14
|
|
|
|
|
29
|
my $n = $_->name; |
|
437
|
14
|
100
|
66
|
|
|
53
|
next if !defined($n) || $seen{$n}++; |
|
438
|
8
|
|
|
|
|
13
|
push(@n, $n); |
|
439
|
|
|
|
|
|
|
} |
|
440
|
2
|
|
|
|
|
23
|
return @n; |
|
441
|
|
|
|
|
|
|
} |
|
442
|
|
|
|
|
|
|
} |
|
443
|
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
sub try_others |
|
447
|
|
|
|
|
|
|
{ |
|
448
|
0
|
|
|
0
|
1
|
0
|
my($self, $cb) = @_; |
|
449
|
0
|
|
|
|
|
0
|
my @try; |
|
450
|
0
|
|
|
|
|
0
|
for (@{$self->{'inputs'}}) { |
|
|
0
|
|
|
|
|
0
|
|
|
451
|
0
|
|
|
|
|
0
|
my @not_tried_yet = $_->other_possible_values; |
|
452
|
0
|
0
|
|
|
|
0
|
next unless @not_tried_yet; |
|
453
|
0
|
|
|
|
|
0
|
push(@try, [\@not_tried_yet, $_]); |
|
454
|
|
|
|
|
|
|
} |
|
455
|
0
|
0
|
|
|
|
0
|
return unless @try; |
|
456
|
0
|
|
|
|
|
0
|
$self->_try($cb, \@try, 0); |
|
457
|
|
|
|
|
|
|
} |
|
458
|
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
sub _try |
|
460
|
|
|
|
|
|
|
{ |
|
461
|
0
|
|
|
0
|
|
0
|
my($self, $cb, $try, $i) = @_; |
|
462
|
0
|
|
|
|
|
0
|
for (@{$try->[$i][0]}) { |
|
|
0
|
|
|
|
|
0
|
|
|
463
|
0
|
|
|
|
|
0
|
$try->[$i][1]->value($_); |
|
464
|
0
|
|
|
|
|
0
|
&$cb($self); |
|
465
|
0
|
0
|
|
|
|
0
|
$self->_try($cb, $try, $i+1) if $i+1 < @$try; |
|
466
|
|
|
|
|
|
|
} |
|
467
|
|
|
|
|
|
|
} |
|
468
|
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
sub make_request |
|
472
|
|
|
|
|
|
|
{ |
|
473
|
42
|
|
|
42
|
1
|
84
|
my $self = shift; |
|
474
|
42
|
|
|
|
|
86
|
my $method = uc $self->{'method'}; |
|
475
|
42
|
|
|
|
|
64
|
my $uri = $self->{'action'}; |
|
476
|
42
|
|
|
|
|
55
|
my $enctype = $self->{'enctype'}; |
|
477
|
42
|
|
|
|
|
89
|
my @form = $self->form; |
|
478
|
|
|
|
|
|
|
|
|
479
|
42
|
100
|
|
|
|
106
|
my $charset = $self->accept_charset eq "UNKNOWN" ? $self->{default_charset} : $self->accept_charset; |
|
480
|
42
|
|
|
|
|
78
|
foreach my $fi (@form) { |
|
481
|
142
|
100
|
|
|
|
6919
|
$fi = Encode::encode($charset, $fi) unless ref($fi); |
|
482
|
|
|
|
|
|
|
} |
|
483
|
|
|
|
|
|
|
|
|
484
|
42
|
100
|
|
|
|
673
|
if ($method eq "GET") { |
|
|
|
50
|
|
|
|
|
|
|
485
|
21
|
|
|
|
|
1714
|
require HTTP::Request; |
|
486
|
21
|
|
|
|
|
33622
|
$uri = URI->new($uri, "http"); |
|
487
|
21
|
|
|
|
|
1773
|
$uri->query_form(@form); |
|
488
|
21
|
|
|
|
|
1661
|
return HTTP::Request->new(GET => $uri); |
|
489
|
|
|
|
|
|
|
} |
|
490
|
|
|
|
|
|
|
elsif ($method eq "POST") { |
|
491
|
21
|
|
|
|
|
1704
|
require HTTP::Request::Common; |
|
492
|
21
|
|
|
|
|
17860
|
return HTTP::Request::Common::POST($uri, \@form, |
|
493
|
|
|
|
|
|
|
Content_Type => $enctype); |
|
494
|
|
|
|
|
|
|
} |
|
495
|
|
|
|
|
|
|
else { |
|
496
|
0
|
|
|
|
|
0
|
Carp::croak("Unknown method '$method'"); |
|
497
|
|
|
|
|
|
|
} |
|
498
|
|
|
|
|
|
|
} |
|
499
|
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
sub click |
|
503
|
|
|
|
|
|
|
{ |
|
504
|
31
|
|
|
31
|
1
|
111
|
my $self = shift; |
|
505
|
31
|
|
|
|
|
47
|
my $name; |
|
506
|
31
|
50
|
|
|
|
115
|
$name = shift if (@_ % 2) == 1; # odd number of arguments |
|
507
|
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
# try to find first submit button to activate |
|
509
|
31
|
|
|
|
|
46
|
for (@{$self->{'inputs'}}) { |
|
|
31
|
|
|
|
|
86
|
|
|
510
|
59
|
100
|
|
|
|
260
|
next unless $_->can("click"); |
|
511
|
7
|
50
|
33
|
|
|
19
|
next if $name && !$_->selected($name); |
|
512
|
7
|
100
|
|
|
|
23
|
next if $_->disabled; |
|
513
|
6
|
|
|
|
|
22
|
return $_->click($self, @_); |
|
514
|
|
|
|
|
|
|
} |
|
515
|
25
|
50
|
|
|
|
60
|
Carp::croak("No clickable input with name $name") if $name; |
|
516
|
25
|
|
|
|
|
57
|
$self->make_request; |
|
517
|
|
|
|
|
|
|
} |
|
518
|
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
sub form |
|
522
|
|
|
|
|
|
|
{ |
|
523
|
44
|
|
|
44
|
1
|
62
|
my $self = shift; |
|
524
|
44
|
|
|
|
|
83
|
map { $_->form_name_value($self) } @{$self->{'inputs'}}; |
|
|
94
|
|
|
|
|
210
|
|
|
|
44
|
|
|
|
|
90
|
|
|
525
|
|
|
|
|
|
|
} |
|
526
|
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
sub dump |
|
530
|
|
|
|
|
|
|
{ |
|
531
|
2
|
|
|
2
|
1
|
6
|
my $self = shift; |
|
532
|
2
|
|
|
|
|
7
|
my $method = $self->{'method'}; |
|
533
|
2
|
|
|
|
|
4
|
my $uri = $self->{'action'}; |
|
534
|
2
|
|
|
|
|
5
|
my $enctype = $self->{'enctype'}; |
|
535
|
2
|
|
|
|
|
13
|
my $dump = "$method $uri"; |
|
536
|
2
|
50
|
|
|
|
17
|
$dump .= " ($enctype)" |
|
537
|
|
|
|
|
|
|
if $enctype ne "application/x-www-form-urlencoded"; |
|
538
|
|
|
|
|
|
|
$dump .= " [$self->{attr}{name}]" |
|
539
|
2
|
100
|
|
|
|
12
|
if exists $self->{attr}{name}; |
|
540
|
2
|
|
|
|
|
4
|
$dump .= "\n"; |
|
541
|
2
|
|
|
|
|
10
|
for ($self->inputs) { |
|
542
|
1
|
|
|
|
|
8
|
$dump .= " " . $_->dump . "\n"; |
|
543
|
|
|
|
|
|
|
} |
|
544
|
2
|
50
|
|
|
|
9
|
print STDERR $dump unless defined wantarray; |
|
545
|
2
|
|
|
|
|
9
|
$dump; |
|
546
|
|
|
|
|
|
|
} |
|
547
|
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
#--------------------------------------------------- |
|
550
|
|
|
|
|
|
|
package HTML::Form::Input; |
|
551
|
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
sub new |
|
554
|
|
|
|
|
|
|
{ |
|
555
|
154
|
|
|
154
|
|
217
|
my $class = shift; |
|
556
|
154
|
|
|
|
|
474
|
my $self = bless {@_}, $class; |
|
557
|
154
|
|
|
|
|
268
|
$self; |
|
558
|
|
|
|
|
|
|
} |
|
559
|
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
sub add_to_form |
|
561
|
|
|
|
|
|
|
{ |
|
562
|
116
|
|
|
116
|
|
192
|
my($self, $form) = @_; |
|
563
|
116
|
|
|
|
|
136
|
push(@{$form->{'inputs'}}, $self); |
|
|
116
|
|
|
|
|
208
|
|
|
564
|
116
|
|
|
|
|
477
|
$self; |
|
565
|
|
|
|
|
|
|
} |
|
566
|
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
sub strict { |
|
568
|
10
|
|
|
10
|
|
1022
|
my $self = shift; |
|
569
|
10
|
|
|
|
|
20
|
my $old = $self->{strict}; |
|
570
|
10
|
100
|
|
|
|
22
|
if (@_) { |
|
571
|
8
|
|
|
|
|
12
|
$self->{strict} = shift; |
|
572
|
|
|
|
|
|
|
} |
|
573
|
10
|
|
|
|
|
26
|
$old; |
|
574
|
|
|
|
|
|
|
} |
|
575
|
|
|
|
|
|
|
|
|
576
|
|
|
|
50
|
|
|
sub fixup {} |
|
577
|
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
sub type |
|
581
|
|
|
|
|
|
|
{ |
|
582
|
145
|
|
|
145
|
|
253
|
shift->{type}; |
|
583
|
|
|
|
|
|
|
} |
|
584
|
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
sub name |
|
587
|
|
|
|
|
|
|
{ |
|
588
|
234
|
|
|
234
|
|
246
|
my $self = shift; |
|
589
|
234
|
|
|
|
|
275
|
my $old = $self->{name}; |
|
590
|
234
|
100
|
|
|
|
338
|
$self->{name} = shift if @_; |
|
591
|
234
|
|
|
|
|
311
|
$old; |
|
592
|
|
|
|
|
|
|
} |
|
593
|
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
sub id |
|
595
|
|
|
|
|
|
|
{ |
|
596
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
|
597
|
1
|
|
|
|
|
2
|
my $old = $self->{id}; |
|
598
|
1
|
50
|
|
|
|
3
|
$self->{id} = shift if @_; |
|
599
|
1
|
|
|
|
|
4
|
$old; |
|
600
|
|
|
|
|
|
|
} |
|
601
|
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
sub class |
|
603
|
|
|
|
|
|
|
{ |
|
604
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
|
605
|
1
|
|
|
|
|
2
|
my $old = $self->{class}; |
|
606
|
1
|
50
|
|
|
|
3
|
$self->{class} = shift if @_; |
|
607
|
1
|
|
|
|
|
4
|
$old; |
|
608
|
|
|
|
|
|
|
} |
|
609
|
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
sub selected { |
|
611
|
580
|
|
|
580
|
|
713
|
my($self, $sel) = @_; |
|
612
|
580
|
50
|
|
|
|
784
|
return undef unless defined $sel; |
|
613
|
580
|
100
|
|
|
|
1342
|
my $attr = |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
$sel =~ s/^\^// ? "name" : |
|
615
|
|
|
|
|
|
|
$sel =~ s/^#// ? "id" : |
|
616
|
|
|
|
|
|
|
$sel =~ s/^\.// ? "class" : |
|
617
|
|
|
|
|
|
|
"name"; |
|
618
|
580
|
100
|
|
|
|
966
|
return 0 unless defined $self->{$attr}; |
|
619
|
575
|
|
|
|
|
1258
|
return $self->{$attr} eq $sel; |
|
620
|
|
|
|
|
|
|
} |
|
621
|
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
sub value |
|
623
|
|
|
|
|
|
|
{ |
|
624
|
11
|
|
|
11
|
|
17
|
my $self = shift; |
|
625
|
11
|
|
|
|
|
18
|
my $old = $self->{value}; |
|
626
|
11
|
100
|
|
|
|
21
|
$self->{value} = shift if @_; |
|
627
|
11
|
|
|
|
|
27
|
$old; |
|
628
|
|
|
|
|
|
|
} |
|
629
|
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
sub autocomplete |
|
631
|
|
|
|
|
|
|
{ |
|
632
|
6
|
|
|
6
|
|
14
|
my $self = shift; |
|
633
|
6
|
|
|
|
|
8
|
my $old = $self->{autocomplete}; |
|
634
|
6
|
100
|
|
|
|
15
|
$self->{autocomplete} = shift if @_; |
|
635
|
6
|
|
|
|
|
13
|
$old; |
|
636
|
|
|
|
|
|
|
} |
|
637
|
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
sub possible_values |
|
640
|
|
|
|
|
|
|
{ |
|
641
|
0
|
|
|
0
|
|
0
|
return; |
|
642
|
|
|
|
|
|
|
} |
|
643
|
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
sub other_possible_values |
|
646
|
|
|
|
|
|
|
{ |
|
647
|
0
|
|
|
0
|
|
0
|
return; |
|
648
|
|
|
|
|
|
|
} |
|
649
|
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
sub value_names { |
|
652
|
|
|
|
|
|
|
return |
|
653
|
0
|
|
|
0
|
|
0
|
} |
|
654
|
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
sub readonly { |
|
657
|
6
|
|
|
6
|
|
646
|
my $self = shift; |
|
658
|
6
|
|
|
|
|
11
|
my $old = $self->{readonly}; |
|
659
|
6
|
100
|
|
|
|
15
|
$self->{readonly} = shift if @_; |
|
660
|
6
|
|
|
|
|
20
|
$old; |
|
661
|
|
|
|
|
|
|
} |
|
662
|
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
sub disabled { |
|
665
|
60
|
|
|
60
|
|
81
|
my $self = shift; |
|
666
|
60
|
|
|
|
|
96
|
my $old = $self->{disabled}; |
|
667
|
60
|
100
|
|
|
|
121
|
$self->{disabled} = shift if @_; |
|
668
|
60
|
|
|
|
|
174
|
$old; |
|
669
|
|
|
|
|
|
|
} |
|
670
|
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
sub form_name_value |
|
673
|
|
|
|
|
|
|
{ |
|
674
|
76
|
|
|
76
|
|
90
|
my $self = shift; |
|
675
|
76
|
|
|
|
|
121
|
my $name = $self->{'name'}; |
|
676
|
76
|
100
|
|
|
|
127
|
return unless defined $name; |
|
677
|
68
|
100
|
|
|
|
140
|
return if $self->disabled; |
|
678
|
65
|
|
|
|
|
122
|
my $value = $self->value; |
|
679
|
65
|
100
|
|
|
|
133
|
return unless defined $value; |
|
680
|
60
|
|
|
|
|
200
|
return ($name => $value); |
|
681
|
|
|
|
|
|
|
} |
|
682
|
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
sub dump |
|
684
|
|
|
|
|
|
|
{ |
|
685
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
|
686
|
1
|
|
|
|
|
7
|
my $name = $self->name; |
|
687
|
1
|
50
|
|
|
|
4
|
$name = "" unless defined $name; |
|
688
|
1
|
|
|
|
|
3
|
my $value = $self->value; |
|
689
|
1
|
50
|
|
|
|
16
|
$value = "" unless defined $value; |
|
690
|
1
|
|
|
|
|
18
|
my $dump = "$name=$value"; |
|
691
|
|
|
|
|
|
|
|
|
692
|
1
|
|
|
|
|
37
|
my $type = $self->type; |
|
693
|
|
|
|
|
|
|
|
|
694
|
1
|
50
|
|
|
|
21
|
$type .= " disabled" if $self->disabled; |
|
695
|
1
|
50
|
|
|
|
8
|
$type .= " readonly" if $self->readonly; |
|
696
|
1
|
50
|
|
|
|
29
|
return sprintf "%-30s %s", $dump, "($type)" unless $self->{menu}; |
|
697
|
|
|
|
|
|
|
|
|
698
|
0
|
|
|
|
|
0
|
my @menu; |
|
699
|
0
|
|
|
|
|
0
|
my $i = 0; |
|
700
|
0
|
|
|
|
|
0
|
for (@{$self->{menu}}) { |
|
|
0
|
|
|
|
|
0
|
|
|
701
|
0
|
|
|
|
|
0
|
my $opt = $_->{value}; |
|
702
|
0
|
0
|
|
|
|
0
|
$opt = "" unless defined $opt; |
|
703
|
|
|
|
|
|
|
$opt .= "/$_->{name}" |
|
704
|
0
|
0
|
0
|
|
|
0
|
if defined $_->{name} && length $_->{name} && $_->{name} ne $opt; |
|
|
|
|
0
|
|
|
|
|
|
705
|
0
|
0
|
|
|
|
0
|
substr($opt,0,0) = "-" if $_->{disabled}; |
|
706
|
0
|
0
|
0
|
|
|
0
|
if (exists $self->{current} && $self->{current} == $i) { |
|
707
|
0
|
0
|
|
|
|
0
|
substr($opt,0,0) = "!" unless $_->{seen}; |
|
708
|
0
|
|
|
|
|
0
|
substr($opt,0,0) = "*"; |
|
709
|
|
|
|
|
|
|
} |
|
710
|
|
|
|
|
|
|
else { |
|
711
|
0
|
0
|
|
|
|
0
|
substr($opt,0,0) = ":" if $_->{seen}; |
|
712
|
|
|
|
|
|
|
} |
|
713
|
0
|
|
|
|
|
0
|
push(@menu, $opt); |
|
714
|
0
|
|
|
|
|
0
|
$i++; |
|
715
|
|
|
|
|
|
|
} |
|
716
|
|
|
|
|
|
|
|
|
717
|
0
|
|
|
|
|
0
|
return sprintf "%-30s %-10s %s", $dump, "($type)", "[" . join("|", @menu) . "]"; |
|
718
|
|
|
|
|
|
|
} |
|
719
|
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
#--------------------------------------------------- |
|
722
|
|
|
|
|
|
|
package HTML::Form::TextInput; |
|
723
|
|
|
|
|
|
|
@HTML::Form::TextInput::ISA=qw(HTML::Form::Input); |
|
724
|
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
#input/text |
|
726
|
|
|
|
|
|
|
#input/password |
|
727
|
|
|
|
|
|
|
#input/hidden |
|
728
|
|
|
|
|
|
|
#textarea |
|
729
|
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
sub value |
|
731
|
|
|
|
|
|
|
{ |
|
732
|
116
|
|
|
116
|
|
1485
|
my $self = shift; |
|
733
|
116
|
|
|
|
|
164
|
my $old = $self->{value}; |
|
734
|
116
|
100
|
|
|
|
215
|
$old = "" unless defined $old; |
|
735
|
116
|
100
|
|
|
|
229
|
if (@_) { |
|
736
|
|
|
|
|
|
|
Carp::croak("Input '$self->{name}' is readonly") |
|
737
|
24
|
100
|
100
|
|
|
357
|
if $self->{strict} && $self->{readonly}; |
|
738
|
22
|
|
|
|
|
36
|
my $new = shift; |
|
739
|
22
|
100
|
|
|
|
56
|
my $n = exists $self->{maxlength} ? $self->{maxlength} : undef; |
|
740
|
|
|
|
|
|
|
Carp::croak("Input '$self->{name}' has maxlength '$n'") |
|
741
|
22
|
100
|
100
|
|
|
263
|
if $self->{strict} && defined($n) && defined($new) && length($new) > $n; |
|
|
|
|
66
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
742
|
21
|
|
|
|
|
37
|
$self->{value} = $new; |
|
743
|
|
|
|
|
|
|
} |
|
744
|
113
|
|
|
|
|
241
|
$old; |
|
745
|
|
|
|
|
|
|
} |
|
746
|
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
#--------------------------------------------------- |
|
748
|
|
|
|
|
|
|
package HTML::Form::IgnoreInput; |
|
749
|
|
|
|
|
|
|
@HTML::Form::IgnoreInput::ISA=qw(HTML::Form::Input); |
|
750
|
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
#input/button |
|
752
|
|
|
|
|
|
|
#input/reset |
|
753
|
|
|
|
|
|
|
|
|
754
|
1
|
|
|
1
|
|
1
|
sub value { return } |
|
755
|
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
#--------------------------------------------------- |
|
758
|
|
|
|
|
|
|
package HTML::Form::ListInput; |
|
759
|
|
|
|
|
|
|
@HTML::Form::ListInput::ISA=qw(HTML::Form::Input); |
|
760
|
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
#select/option (val1, val2, ....) |
|
762
|
|
|
|
|
|
|
#input/radio (undef, val1, val2,...) |
|
763
|
|
|
|
|
|
|
#input/checkbox (undef, value) |
|
764
|
|
|
|
|
|
|
#select-multiple/option (undef, value) |
|
765
|
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
sub new |
|
767
|
|
|
|
|
|
|
{ |
|
768
|
93
|
|
|
93
|
|
132
|
my $class = shift; |
|
769
|
93
|
|
|
|
|
201
|
my $self = $class->SUPER::new(@_); |
|
770
|
|
|
|
|
|
|
|
|
771
|
93
|
|
|
|
|
180
|
my $value = delete $self->{value}; |
|
772
|
93
|
|
|
|
|
115
|
my $value_name = delete $self->{value_name}; |
|
773
|
93
|
|
|
|
|
111
|
my $type = $self->{type}; |
|
774
|
|
|
|
|
|
|
|
|
775
|
93
|
100
|
|
|
|
152
|
if ($type eq "checkbox") { |
|
776
|
7
|
100
|
|
|
|
17
|
$value = "on" unless defined $value; |
|
777
|
|
|
|
|
|
|
$self->{menu} = [ |
|
778
|
7
|
|
|
|
|
51
|
{ value => undef, name => "off", }, |
|
779
|
|
|
|
|
|
|
{ value => $value, name => $value_name, }, |
|
780
|
|
|
|
|
|
|
]; |
|
781
|
7
|
100
|
|
|
|
23
|
$self->{current} = (delete $self->{checked}) ? 1 : 0; |
|
782
|
|
|
|
|
|
|
; |
|
783
|
|
|
|
|
|
|
} |
|
784
|
|
|
|
|
|
|
else { |
|
785
|
|
|
|
|
|
|
$self->{option_disabled}++ |
|
786
|
86
|
100
|
100
|
|
|
168
|
if $type eq "radio" && delete $self->{disabled}; |
|
787
|
|
|
|
|
|
|
$self->{menu} = [ |
|
788
|
86
|
|
|
|
|
216
|
{value => $value, name => $value_name}, |
|
789
|
|
|
|
|
|
|
]; |
|
790
|
86
|
|
100
|
|
|
228
|
my $checked = $self->{checked} || $self->{option_selected}; |
|
791
|
86
|
|
|
|
|
91
|
delete $self->{checked}; |
|
792
|
86
|
|
|
|
|
93
|
delete $self->{option_selected}; |
|
793
|
86
|
100
|
|
|
|
138
|
if (exists $self->{multiple}) { |
|
794
|
16
|
|
|
|
|
19
|
unshift(@{$self->{menu}}, { value => undef, name => "off"}); |
|
|
16
|
|
|
|
|
40
|
|
|
795
|
16
|
100
|
|
|
|
34
|
$self->{current} = $checked ? 1 : 0; |
|
796
|
|
|
|
|
|
|
} |
|
797
|
|
|
|
|
|
|
else { |
|
798
|
70
|
100
|
|
|
|
109
|
$self->{current} = 0 if $checked; |
|
799
|
|
|
|
|
|
|
} |
|
800
|
|
|
|
|
|
|
} |
|
801
|
93
|
|
|
|
|
123
|
$self; |
|
802
|
|
|
|
|
|
|
} |
|
803
|
|
|
|
|
|
|
|
|
804
|
|
|
|
|
|
|
sub add_to_form |
|
805
|
|
|
|
|
|
|
{ |
|
806
|
93
|
|
|
93
|
|
144
|
my($self, $form) = @_; |
|
807
|
93
|
|
|
|
|
168
|
my $type = $self->type; |
|
808
|
|
|
|
|
|
|
|
|
809
|
93
|
100
|
|
|
|
177
|
return $self->SUPER::add_to_form($form) |
|
810
|
|
|
|
|
|
|
if $type eq "checkbox"; |
|
811
|
|
|
|
|
|
|
|
|
812
|
86
|
100
|
100
|
|
|
223
|
if ($type eq "option" && exists $self->{multiple}) { |
|
813
|
16
|
|
100
|
|
|
57
|
$self->{disabled} ||= delete $self->{option_disabled}; |
|
814
|
16
|
|
|
|
|
31
|
return $self->SUPER::add_to_form($form); |
|
815
|
|
|
|
|
|
|
} |
|
816
|
|
|
|
|
|
|
|
|
817
|
70
|
50
|
|
|
|
65
|
Carp::croak "Assert" if @{$self->{menu}} != 1; |
|
|
70
|
|
|
|
|
132
|
|
|
818
|
70
|
|
|
|
|
96
|
my $m = $self->{menu}[0]; |
|
819
|
70
|
100
|
|
|
|
110
|
$m->{disabled}++ if delete $self->{option_disabled}; |
|
820
|
|
|
|
|
|
|
|
|
821
|
|
|
|
|
|
|
# if there was no name we have to search for an input that explicitly has |
|
822
|
|
|
|
|
|
|
# no name either, because otherwise the name attribute would be ignored |
|
823
|
70
|
|
100
|
|
|
194
|
my $prev = $form->find_input($self->{name} || \undef, $self->{type}, $self->{idx}); |
|
824
|
70
|
100
|
|
|
|
154
|
return $self->SUPER::add_to_form($form) unless $prev; |
|
825
|
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
# merge menus |
|
827
|
38
|
100
|
|
|
|
71
|
$prev->{current} = @{$prev->{menu}} if exists $self->{current}; |
|
|
4
|
|
|
|
|
8
|
|
|
828
|
38
|
|
|
|
|
39
|
push(@{$prev->{menu}}, $m); |
|
|
38
|
|
|
|
|
210
|
|
|
829
|
|
|
|
|
|
|
} |
|
830
|
|
|
|
|
|
|
|
|
831
|
|
|
|
|
|
|
sub fixup |
|
832
|
|
|
|
|
|
|
{ |
|
833
|
55
|
|
|
55
|
|
58
|
my $self = shift; |
|
834
|
55
|
100
|
100
|
|
|
169
|
if ($self->{type} eq "option" && !(exists $self->{current})) { |
|
835
|
11
|
|
|
|
|
18
|
$self->{current} = 0; |
|
836
|
|
|
|
|
|
|
} |
|
837
|
55
|
100
|
|
|
|
155
|
$self->{menu}[$self->{current}]{seen}++ if exists $self->{current}; |
|
838
|
|
|
|
|
|
|
} |
|
839
|
|
|
|
|
|
|
|
|
840
|
|
|
|
|
|
|
sub disabled |
|
841
|
|
|
|
|
|
|
{ |
|
842
|
46
|
|
|
46
|
|
55
|
my $self = shift; |
|
843
|
46
|
|
|
|
|
73
|
my $type = $self->type; |
|
844
|
|
|
|
|
|
|
|
|
845
|
46
|
|
100
|
|
|
105
|
my $old = $self->{disabled} || _menu_all_disabled(@{$self->{menu}}); |
|
846
|
46
|
100
|
|
|
|
99
|
if (@_) { |
|
847
|
5
|
|
|
|
|
7
|
my $v = shift; |
|
848
|
5
|
|
|
|
|
6
|
$self->{disabled} = $v; |
|
849
|
5
|
|
|
|
|
9
|
for (@{$self->{menu}}) { |
|
|
5
|
|
|
|
|
8
|
|
|
850
|
11
|
|
|
|
|
14
|
$_->{disabled} = $v; |
|
851
|
|
|
|
|
|
|
} |
|
852
|
|
|
|
|
|
|
} |
|
853
|
46
|
|
|
|
|
110
|
return $old; |
|
854
|
|
|
|
|
|
|
} |
|
855
|
|
|
|
|
|
|
|
|
856
|
|
|
|
|
|
|
sub _menu_all_disabled { |
|
857
|
36
|
|
|
36
|
|
52
|
for (@_) { |
|
858
|
38
|
100
|
|
|
|
131
|
return 0 unless $_->{disabled}; |
|
859
|
|
|
|
|
|
|
} |
|
860
|
4
|
|
|
|
|
8
|
return 1; |
|
861
|
|
|
|
|
|
|
} |
|
862
|
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
sub value |
|
864
|
|
|
|
|
|
|
{ |
|
865
|
96
|
|
|
96
|
|
134
|
my $self = shift; |
|
866
|
96
|
|
|
|
|
102
|
my $old; |
|
867
|
96
|
100
|
|
|
|
206
|
$old = $self->{menu}[$self->{current}]{value} if exists $self->{current}; |
|
868
|
96
|
50
|
|
|
|
161
|
$old = $self->{value} if exists $self->{value}; |
|
869
|
96
|
100
|
|
|
|
149
|
if (@_) { |
|
870
|
41
|
|
|
|
|
46
|
my $i = 0; |
|
871
|
41
|
|
|
|
|
52
|
my $val = shift; |
|
872
|
41
|
|
|
|
|
50
|
my $cur; |
|
873
|
|
|
|
|
|
|
my $disabled; |
|
874
|
41
|
|
|
|
|
47
|
for (@{$self->{menu}}) { |
|
|
41
|
|
|
|
|
72
|
|
|
875
|
79
|
100
|
100
|
|
|
372
|
if ((defined($val) && defined($_->{value}) && $val eq $_->{value}) || |
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
876
|
|
|
|
|
|
|
(!defined($val) && !defined($_->{value})) |
|
877
|
|
|
|
|
|
|
) |
|
878
|
|
|
|
|
|
|
{ |
|
879
|
27
|
|
|
|
|
30
|
$cur = $i; |
|
880
|
27
|
|
|
|
|
31
|
$disabled = $_->{disabled}; |
|
881
|
27
|
100
|
|
|
|
41
|
last unless $disabled; |
|
882
|
|
|
|
|
|
|
} |
|
883
|
59
|
|
|
|
|
82
|
$i++; |
|
884
|
|
|
|
|
|
|
} |
|
885
|
41
|
100
|
100
|
|
|
106
|
if (!(defined $cur) || $disabled) { |
|
886
|
21
|
100
|
|
|
|
45
|
if (defined $val) { |
|
|
|
50
|
|
|
|
|
|
|
887
|
|
|
|
|
|
|
# try to search among the alternative names as well |
|
888
|
20
|
|
|
|
|
25
|
my $i = 0; |
|
889
|
20
|
|
|
|
|
22
|
my $cur_ignorecase; |
|
890
|
20
|
|
|
|
|
38
|
my $lc_val = lc($val); |
|
891
|
20
|
|
|
|
|
24
|
for (@{$self->{menu}}) { |
|
|
20
|
|
|
|
|
33
|
|
|
892
|
43
|
100
|
|
|
|
73
|
if (defined $_->{name}) { |
|
893
|
35
|
100
|
|
|
|
54
|
if ($val eq $_->{name}) { |
|
894
|
4
|
|
|
|
|
7
|
$disabled = $_->{disabled}; |
|
895
|
4
|
|
|
|
|
8
|
$cur = $i; |
|
896
|
4
|
100
|
|
|
|
9
|
last unless $disabled; |
|
897
|
|
|
|
|
|
|
} |
|
898
|
32
|
100
|
100
|
|
|
93
|
if (!defined($cur_ignorecase) && $lc_val eq lc($_->{name})) { |
|
899
|
3
|
|
|
|
|
4
|
$cur_ignorecase = $i; |
|
900
|
|
|
|
|
|
|
} |
|
901
|
|
|
|
|
|
|
} |
|
902
|
40
|
|
|
|
|
52
|
$i++; |
|
903
|
|
|
|
|
|
|
} |
|
904
|
20
|
100
|
|
|
|
38
|
unless (defined $cur) { |
|
905
|
10
|
|
|
|
|
14
|
$cur = $cur_ignorecase; |
|
906
|
10
|
100
|
|
|
|
30
|
if (defined $cur) { |
|
|
|
50
|
|
|
|
|
|
|
907
|
2
|
|
|
|
|
7
|
$disabled = $self->{menu}[$cur]{disabled}; |
|
908
|
|
|
|
|
|
|
} |
|
909
|
|
|
|
|
|
|
elsif ($self->{strict}) { |
|
910
|
8
|
|
|
|
|
15
|
my $n = $self->name; |
|
911
|
8
|
|
|
|
|
533
|
Carp::croak("Illegal value '$val' for field '$n'"); |
|
912
|
|
|
|
|
|
|
} |
|
913
|
|
|
|
|
|
|
} |
|
914
|
|
|
|
|
|
|
} |
|
915
|
|
|
|
|
|
|
elsif ($self->{strict}) { |
|
916
|
1
|
|
|
|
|
3
|
my $n = $self->name; |
|
917
|
1
|
|
|
|
|
72
|
Carp::croak("The '$n' field can't be unchecked"); |
|
918
|
|
|
|
|
|
|
} |
|
919
|
|
|
|
|
|
|
} |
|
920
|
32
|
100
|
100
|
|
|
97
|
if ($self->{strict} && $disabled) { |
|
921
|
7
|
|
|
|
|
11
|
my $n = $self->name; |
|
922
|
7
|
|
|
|
|
602
|
Carp::croak("The value '$val' has been disabled for field '$n'"); |
|
923
|
|
|
|
|
|
|
} |
|
924
|
25
|
50
|
|
|
|
47
|
if (defined $cur) { |
|
925
|
25
|
|
|
|
|
30
|
$self->{current} = $cur; |
|
926
|
25
|
|
|
|
|
44
|
$self->{menu}[$cur]{seen}++; |
|
927
|
25
|
|
|
|
|
40
|
delete $self->{value}; |
|
928
|
|
|
|
|
|
|
} |
|
929
|
|
|
|
|
|
|
else { |
|
930
|
0
|
|
|
|
|
0
|
$self->{value} = $val; |
|
931
|
0
|
|
|
|
|
0
|
delete $self->{current}; |
|
932
|
|
|
|
|
|
|
} |
|
933
|
|
|
|
|
|
|
} |
|
934
|
80
|
|
|
|
|
207
|
$old; |
|
935
|
|
|
|
|
|
|
} |
|
936
|
|
|
|
|
|
|
|
|
937
|
|
|
|
|
|
|
|
|
938
|
|
|
|
|
|
|
sub check |
|
939
|
|
|
|
|
|
|
{ |
|
940
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
|
941
|
1
|
|
|
|
|
2
|
$self->{current} = 1; |
|
942
|
1
|
|
|
|
|
3
|
$self->{menu}[1]{seen}++; |
|
943
|
|
|
|
|
|
|
} |
|
944
|
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
sub possible_values |
|
946
|
|
|
|
|
|
|
{ |
|
947
|
2
|
|
|
2
|
|
5
|
my $self = shift; |
|
948
|
2
|
|
|
|
|
4
|
map $_->{value}, grep !$_->{disabled}, @{$self->{menu}}; |
|
|
2
|
|
|
|
|
18
|
|
|
949
|
|
|
|
|
|
|
} |
|
950
|
|
|
|
|
|
|
|
|
951
|
|
|
|
|
|
|
sub other_possible_values |
|
952
|
|
|
|
|
|
|
{ |
|
953
|
3
|
|
|
3
|
|
5
|
my $self = shift; |
|
954
|
3
|
|
100
|
|
|
5
|
map $_->{value}, grep !$_->{seen} && !$_->{disabled}, @{$self->{menu}}; |
|
|
3
|
|
|
|
|
29
|
|
|
955
|
|
|
|
|
|
|
} |
|
956
|
|
|
|
|
|
|
|
|
957
|
|
|
|
|
|
|
sub value_names { |
|
958
|
7
|
|
|
7
|
|
13
|
my $self = shift; |
|
959
|
7
|
|
|
|
|
13
|
my @names; |
|
960
|
7
|
|
|
|
|
11
|
for (@{$self->{menu}}) { |
|
|
7
|
|
|
|
|
15
|
|
|
961
|
10
|
|
|
|
|
49
|
my $n = $_->{name}; |
|
962
|
10
|
100
|
|
|
|
20
|
$n = $_->{value} unless defined $n; |
|
963
|
10
|
|
|
|
|
26
|
push(@names, $n); |
|
964
|
|
|
|
|
|
|
} |
|
965
|
7
|
|
|
|
|
40
|
@names; |
|
966
|
|
|
|
|
|
|
} |
|
967
|
|
|
|
|
|
|
|
|
968
|
|
|
|
|
|
|
|
|
969
|
|
|
|
|
|
|
#--------------------------------------------------- |
|
970
|
|
|
|
|
|
|
package HTML::Form::SubmitInput; |
|
971
|
|
|
|
|
|
|
@HTML::Form::SubmitInput::ISA=qw(HTML::Form::Input); |
|
972
|
|
|
|
|
|
|
|
|
973
|
|
|
|
|
|
|
#input/image |
|
974
|
|
|
|
|
|
|
#input/submit |
|
975
|
|
|
|
|
|
|
|
|
976
|
|
|
|
|
|
|
|
|
977
|
|
|
|
|
|
|
sub click |
|
978
|
|
|
|
|
|
|
{ |
|
979
|
6
|
|
|
6
|
|
18
|
my($self,$form,$x,$y) = @_; |
|
980
|
6
|
50
|
|
|
|
31
|
for ($x, $y) { $_ = 1 unless defined; } |
|
|
12
|
|
|
|
|
24
|
|
|
981
|
6
|
|
|
|
|
20
|
local($self->{clicked}) = [$x,$y]; |
|
982
|
6
|
100
|
|
|
|
24
|
local($self->{value}) = "" unless defined $self->value; |
|
983
|
6
|
|
|
|
|
15
|
return $form->make_request; |
|
984
|
|
|
|
|
|
|
} |
|
985
|
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
sub form_name_value |
|
987
|
|
|
|
|
|
|
{ |
|
988
|
7
|
|
|
7
|
|
9
|
my $self = shift; |
|
989
|
7
|
100
|
|
|
|
22
|
return unless $self->{clicked}; |
|
990
|
4
|
|
|
|
|
16
|
return $self->SUPER::form_name_value(@_); |
|
991
|
|
|
|
|
|
|
} |
|
992
|
|
|
|
|
|
|
|
|
993
|
|
|
|
|
|
|
|
|
994
|
|
|
|
|
|
|
#--------------------------------------------------- |
|
995
|
|
|
|
|
|
|
package HTML::Form::ImageInput; |
|
996
|
|
|
|
|
|
|
@HTML::Form::ImageInput::ISA=qw(HTML::Form::SubmitInput); |
|
997
|
|
|
|
|
|
|
|
|
998
|
|
|
|
|
|
|
sub form_name_value |
|
999
|
|
|
|
|
|
|
{ |
|
1000
|
2
|
|
|
2
|
|
5
|
my $self = shift; |
|
1001
|
2
|
|
|
|
|
3
|
my $clicked = $self->{clicked}; |
|
1002
|
2
|
50
|
|
|
|
5
|
return unless $clicked; |
|
1003
|
2
|
50
|
|
|
|
6
|
return if $self->{disabled}; |
|
1004
|
2
|
|
|
|
|
5
|
my $name = $self->{name}; |
|
1005
|
2
|
100
|
66
|
|
|
19
|
$name = (defined($name) && length($name)) ? "$name." : ""; |
|
1006
|
2
|
|
|
|
|
12
|
return ("${name}x" => $clicked->[0], |
|
1007
|
|
|
|
|
|
|
"${name}y" => $clicked->[1] |
|
1008
|
|
|
|
|
|
|
); |
|
1009
|
|
|
|
|
|
|
} |
|
1010
|
|
|
|
|
|
|
|
|
1011
|
|
|
|
|
|
|
#--------------------------------------------------- |
|
1012
|
|
|
|
|
|
|
package HTML::Form::FileInput; |
|
1013
|
|
|
|
|
|
|
@HTML::Form::FileInput::ISA=qw(HTML::Form::TextInput); |
|
1014
|
|
|
|
|
|
|
|
|
1015
|
|
|
|
|
|
|
|
|
1016
|
|
|
|
|
|
|
sub file { |
|
1017
|
32
|
|
|
32
|
|
63
|
my $self = shift; |
|
1018
|
32
|
|
|
|
|
51
|
$self->value(@_); |
|
1019
|
|
|
|
|
|
|
} |
|
1020
|
|
|
|
|
|
|
|
|
1021
|
|
|
|
|
|
|
|
|
1022
|
|
|
|
|
|
|
sub filename { |
|
1023
|
16
|
|
|
16
|
|
28
|
my $self = shift; |
|
1024
|
16
|
|
|
|
|
20
|
my $old = $self->{filename}; |
|
1025
|
16
|
100
|
|
|
|
28
|
$self->{filename} = shift if @_; |
|
1026
|
16
|
100
|
|
|
|
35
|
$old = $self->file unless defined $old; |
|
1027
|
16
|
|
|
|
|
27
|
$old; |
|
1028
|
|
|
|
|
|
|
} |
|
1029
|
|
|
|
|
|
|
|
|
1030
|
|
|
|
|
|
|
|
|
1031
|
|
|
|
|
|
|
sub content { |
|
1032
|
15
|
|
|
15
|
|
25
|
my $self = shift; |
|
1033
|
15
|
|
|
|
|
21
|
my $old = $self->{content}; |
|
1034
|
15
|
100
|
|
|
|
53
|
$self->{content} = shift if @_; |
|
1035
|
15
|
|
|
|
|
25
|
$old; |
|
1036
|
|
|
|
|
|
|
} |
|
1037
|
|
|
|
|
|
|
|
|
1038
|
|
|
|
|
|
|
|
|
1039
|
|
|
|
|
|
|
sub headers { |
|
1040
|
13
|
|
|
13
|
|
20
|
my $self = shift; |
|
1041
|
13
|
|
50
|
|
|
42
|
my $old = $self->{headers} || []; |
|
1042
|
13
|
50
|
|
|
|
27
|
$self->{headers} = [@_] if @_; |
|
1043
|
13
|
|
|
|
|
27
|
@$old; |
|
1044
|
|
|
|
|
|
|
} |
|
1045
|
|
|
|
|
|
|
|
|
1046
|
|
|
|
|
|
|
sub form_name_value { |
|
1047
|
14
|
|
|
14
|
|
28
|
my($self, $form) = @_; |
|
1048
|
14
|
100
|
66
|
|
|
33
|
return $self->SUPER::form_name_value($form) |
|
1049
|
|
|
|
|
|
|
if $form->method ne "POST" || |
|
1050
|
|
|
|
|
|
|
$form->enctype ne "multipart/form-data"; |
|
1051
|
|
|
|
|
|
|
|
|
1052
|
13
|
|
|
|
|
39
|
my $name = $self->name; |
|
1053
|
13
|
50
|
|
|
|
25
|
return unless defined $name; |
|
1054
|
13
|
50
|
|
|
|
26
|
return if $self->{disabled}; |
|
1055
|
|
|
|
|
|
|
|
|
1056
|
13
|
|
|
|
|
26
|
my $file = $self->file; |
|
1057
|
13
|
|
|
|
|
29
|
my $filename = $self->filename; |
|
1058
|
13
|
|
|
|
|
29
|
my @headers = $self->headers; |
|
1059
|
13
|
|
|
|
|
23
|
my $content = $self->content; |
|
1060
|
13
|
|
|
|
|
24
|
my %headers = @headers; |
|
1061
|
13
|
100
|
66
|
|
|
95
|
if (defined $content || grep m/^Content$/i, keys %headers) { |
|
|
|
100
|
66
|
|
|
|
|
|
1062
|
2
|
50
|
|
|
|
4
|
$filename = $file unless defined $filename; |
|
1063
|
2
|
|
|
|
|
3
|
$file = undef; |
|
1064
|
2
|
|
|
|
|
4
|
unshift(@headers, "Content" => $content); |
|
1065
|
|
|
|
|
|
|
} |
|
1066
|
|
|
|
|
|
|
elsif (!defined($file) || length($file) == 0) { |
|
1067
|
1
|
|
|
|
|
4
|
return; |
|
1068
|
|
|
|
|
|
|
} |
|
1069
|
|
|
|
|
|
|
|
|
1070
|
|
|
|
|
|
|
# legacy (this used to be the way to do it) |
|
1071
|
12
|
100
|
|
|
|
32
|
if (ref($file) eq "ARRAY") { |
|
1072
|
7
|
|
|
|
|
12
|
my $f = shift @$file; |
|
1073
|
7
|
|
|
|
|
7
|
my $fn = shift @$file; |
|
1074
|
7
|
|
|
|
|
10
|
push(@headers, @$file); |
|
1075
|
7
|
|
|
|
|
10
|
$file = $f; |
|
1076
|
7
|
|
|
|
|
8
|
$filename = $fn; |
|
1077
|
|
|
|
|
|
|
} |
|
1078
|
|
|
|
|
|
|
|
|
1079
|
12
|
|
|
|
|
57
|
return ($name => [$file, $filename, @headers]); |
|
1080
|
|
|
|
|
|
|
} |
|
1081
|
|
|
|
|
|
|
|
|
1082
|
|
|
|
|
|
|
package HTML::Form::KeygenInput; |
|
1083
|
|
|
|
|
|
|
@HTML::Form::KeygenInput::ISA=qw(HTML::Form::Input); |
|
1084
|
|
|
|
|
|
|
|
|
1085
|
|
|
|
|
|
|
sub challenge { |
|
1086
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
|
1087
|
1
|
|
|
|
|
4
|
return $self->{challenge}; |
|
1088
|
|
|
|
|
|
|
} |
|
1089
|
|
|
|
|
|
|
|
|
1090
|
|
|
|
|
|
|
sub keytype { |
|
1091
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
|
1092
|
1
|
|
50
|
|
|
10
|
return lc($self->{keytype} || 'rsa'); |
|
1093
|
|
|
|
|
|
|
} |
|
1094
|
|
|
|
|
|
|
|
|
1095
|
|
|
|
|
|
|
1; |
|
1096
|
|
|
|
|
|
|
|
|
1097
|
|
|
|
|
|
|
__END__ |