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