| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTTP::Request::Form; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4745
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
170
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
68
|
|
|
5
|
1
|
|
|
1
|
|
1128
|
use URI::URL; |
|
|
1
|
|
|
|
|
36034
|
|
|
|
1
|
|
|
|
|
69
|
|
|
6
|
1
|
|
|
1
|
|
1009
|
use HTTP::Request::Common; |
|
|
1
|
|
|
|
|
23976
|
|
|
|
1
|
|
|
|
|
4900
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = "0.952"; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
0
|
|
|
0
|
1
|
|
my ($class, $form, $base, $debug) = @_; |
|
12
|
0
|
|
|
|
|
|
my @allfields; |
|
13
|
|
|
|
|
|
|
my @fields; |
|
14
|
0
|
|
|
|
|
|
my %fieldvals; |
|
15
|
0
|
|
|
|
|
|
my %fieldtypes; |
|
16
|
0
|
|
|
|
|
|
my %checkboxstate; |
|
17
|
0
|
|
|
|
|
|
my @buttons; |
|
18
|
0
|
|
|
|
|
|
my %buttonvals; |
|
19
|
0
|
|
|
|
|
|
my %buttontypes; |
|
20
|
0
|
|
|
|
|
|
my %selections; |
|
21
|
0
|
|
|
|
|
|
my $upload = 0; |
|
22
|
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my $self = {}; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
($form->tag eq 'isindex') |
|
26
|
|
|
|
|
|
|
? do { |
|
27
|
0
|
|
|
|
|
|
$self->{'isindex'} = 1; |
|
28
|
0
|
|
|
|
|
|
push @allfields, 'keywords'; # fake name. Same as CGI.pm uses. |
|
29
|
0
|
|
|
|
|
|
push @fields, 'keywords'; |
|
30
|
0
|
|
|
|
|
|
$fieldvals{'keywords'} = ''; # fake value |
|
31
|
0
|
|
|
|
|
|
$fieldtypes{'keywords'} = 'input/text'; # fake type |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
: $form->traverse( |
|
34
|
|
|
|
|
|
|
sub { |
|
35
|
0
|
|
|
0
|
|
|
my ($self, $start, $depth) = @_; |
|
36
|
0
|
0
|
|
|
|
|
if (ref $self) { |
|
37
|
0
|
|
|
|
|
|
my $tag = $self->tag; |
|
38
|
0
|
0
|
0
|
|
|
|
if (($tag eq 'input') || |
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
39
|
|
|
|
|
|
|
(($tag eq 'button') && $start)) { |
|
40
|
0
|
|
|
|
|
|
my $type = lc($self->attr('type')); |
|
41
|
0
|
0
|
|
|
|
|
$type = "text" if (!defined($type)); |
|
42
|
0
|
0
|
0
|
|
|
|
if ($type eq 'hidden') { |
|
|
|
0
|
0
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $name = $self->attr('name'); |
|
44
|
0
|
|
|
|
|
|
my $value = $self->attr('value'); |
|
45
|
0
|
|
|
|
|
|
push @allfields, $name; |
|
46
|
0
|
|
|
|
|
|
$fieldvals{$name} = $value; |
|
47
|
0
|
|
|
|
|
|
$fieldtypes{$name} = "$tag/$type"; |
|
48
|
|
|
|
|
|
|
} elsif (($type eq 'submit') || |
|
49
|
|
|
|
|
|
|
($type eq 'reset') || |
|
50
|
|
|
|
|
|
|
($type eq 'image')) { |
|
51
|
0
|
|
0
|
|
|
|
my $name = $self->attr('name') || $type; |
|
52
|
0
|
|
0
|
|
|
|
my $value = $self->attr('value') || $type; |
|
53
|
0
|
0
|
|
|
|
|
if (defined($name)) { |
|
54
|
0
|
0
|
|
|
|
|
if (!defined($buttonvals{$name})) { |
|
55
|
0
|
|
|
|
|
|
push @buttons, $name; |
|
56
|
0
|
|
|
|
|
|
$buttonvals{$name} = [$value]; |
|
57
|
0
|
|
|
|
|
|
$buttontypes{$name} = [$type]; |
|
58
|
|
|
|
|
|
|
} else { |
|
59
|
0
|
|
|
|
|
|
push @{$buttonvals{$name}}, $value; |
|
|
0
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
push @{$buttontypes{$name}}, $type; |
|
|
0
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
} else { |
|
64
|
0
|
|
|
|
|
|
my $name = $self->attr('name'); |
|
65
|
0
|
|
|
|
|
|
my $value = $self->attr('value'); |
|
66
|
0
|
0
|
|
|
|
|
if ($type eq 'radio') { |
|
|
|
0
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
if (!defined($fieldtypes{$name})) { |
|
68
|
0
|
|
|
|
|
|
push @allfields, $name; |
|
69
|
0
|
|
|
|
|
|
push @fields, $name; |
|
70
|
0
|
|
|
|
|
|
$fieldtypes{$name} = "$tag/$type"; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
0
|
0
|
|
|
|
|
if (!defined($selections{$name})) { |
|
73
|
0
|
|
|
|
|
|
$selections{$name} = [$value]; |
|
74
|
|
|
|
|
|
|
} else { |
|
75
|
0
|
|
|
|
|
|
push @{$selections{$name}}, $value; |
|
|
0
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
|
77
|
0
|
0
|
|
|
|
|
$fieldvals{$name} = $value if ($self->attr('checked')); |
|
78
|
|
|
|
|
|
|
} elsif ($type eq 'checkbox') { |
|
79
|
0
|
|
|
|
|
|
push @allfields, $name; |
|
80
|
0
|
|
|
|
|
|
push @fields, $name; |
|
81
|
0
|
|
|
|
|
|
$fieldvals{$name} = $value; |
|
82
|
0
|
|
|
|
|
|
$fieldtypes{$name} = "$tag/$type"; |
|
83
|
0
|
0
|
|
|
|
|
if ($self->attr('checked')) { |
|
84
|
0
|
|
|
|
|
|
$checkboxstate{$name} = 1; |
|
85
|
|
|
|
|
|
|
} else { |
|
86
|
0
|
|
|
|
|
|
$checkboxstate{$name} = 0; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
} else { |
|
89
|
0
|
|
|
|
|
|
push @allfields, $name; |
|
90
|
0
|
|
|
|
|
|
push @fields, $name; |
|
91
|
0
|
|
|
|
|
|
$fieldvals{$name} = $value; |
|
92
|
0
|
|
|
|
|
|
$fieldtypes{$name} = "$tag/$type"; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
0
|
0
|
|
|
|
|
if ($type eq 'file') { |
|
95
|
0
|
|
|
|
|
|
$upload = 1; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} elsif (($tag eq 'textarea') && $start) { |
|
99
|
0
|
|
|
|
|
|
my $name = $self->attr('name'); |
|
100
|
0
|
|
|
|
|
|
push @allfields, $name; |
|
101
|
0
|
|
|
|
|
|
push @fields, $name; |
|
102
|
0
|
|
|
|
|
|
$fieldvals{$name} = ""; |
|
103
|
0
|
0
|
|
|
|
|
if ($self->content) { |
|
104
|
0
|
|
|
|
|
|
foreach my $o (@{$self->content}) { |
|
|
0
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
$fieldvals{$name} .= ref($o) ? $o->as_HTML : $o; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
0
|
|
|
|
|
|
$fieldtypes{$name} = $tag; |
|
109
|
|
|
|
|
|
|
} elsif (($tag eq 'select') && $start) { |
|
110
|
0
|
|
|
|
|
|
my $name = $self->attr('name'); |
|
111
|
0
|
|
|
|
|
|
push @allfields, $name; |
|
112
|
0
|
|
|
|
|
|
push @fields, $name; |
|
113
|
0
|
0
|
|
|
|
|
foreach my $o (@{$self->content || []}) { |
|
|
0
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
if (ref $o) { |
|
115
|
0
|
|
|
|
|
|
my $tag = $o->tag; |
|
116
|
0
|
0
|
|
|
|
|
if ($tag eq 'option') { |
|
117
|
0
|
0
|
|
|
|
|
if ($o->attr('selected')) { |
|
118
|
0
|
|
|
|
|
|
$fieldvals{$name} = $o->attr('value'); |
|
119
|
|
|
|
|
|
|
} |
|
120
|
0
|
0
|
|
|
|
|
if (!defined($selections{$name})) { |
|
121
|
0
|
|
|
|
|
|
$selections{$name} = [$o->attr('value')]; |
|
122
|
|
|
|
|
|
|
} else { |
|
123
|
0
|
|
|
|
|
|
push @{$selections{$name}}, $o->attr('value'); |
|
|
0
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
0
|
|
|
|
|
|
$fieldtypes{$name} = $tag; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
} |
|
131
|
0
|
|
|
|
|
|
1; |
|
132
|
0
|
0
|
|
|
|
|
}, 0 |
|
133
|
|
|
|
|
|
|
); |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
$self->{'debug'} = $debug; |
|
136
|
0
|
0
|
|
|
|
|
if (defined($form->attr('method'))) { |
|
137
|
0
|
|
|
|
|
|
$self->{'method'} = $form->attr('method'); |
|
138
|
|
|
|
|
|
|
} else { |
|
139
|
0
|
|
|
|
|
|
$self->{'method'} = 'GET'; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
0
|
|
|
|
|
|
$self->{'name'} = $form->attr('name'); |
|
142
|
0
|
|
|
|
|
|
$self->{'link'} = $form->attr('action'); |
|
143
|
0
|
|
|
|
|
|
$self->{'base'} = $base; |
|
144
|
0
|
|
|
|
|
|
$self->{'allfields'} = \@allfields; |
|
145
|
0
|
|
|
|
|
|
$self->{'fields'} = \@fields; |
|
146
|
0
|
|
|
|
|
|
$self->{'fieldvals'} = \%fieldvals; |
|
147
|
0
|
|
|
|
|
|
$self->{'fieldtypes'} = \%fieldtypes; |
|
148
|
0
|
|
|
|
|
|
$self->{'buttons'} = \@buttons; |
|
149
|
0
|
|
|
|
|
|
$self->{'buttonvals'} = \%buttonvals; |
|
150
|
0
|
|
|
|
|
|
$self->{'buttontypes'} = \%buttontypes; |
|
151
|
0
|
|
|
|
|
|
$self->{'selections'} = \%selections; |
|
152
|
0
|
|
|
|
|
|
$self->{'upload'} = $upload; |
|
153
|
0
|
|
|
|
|
|
$self->{'checkboxstate'} = \%checkboxstate; |
|
154
|
0
|
|
|
|
|
|
bless $self, $class; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub new_many { |
|
158
|
0
|
|
|
0
|
1
|
|
my ($class, $tree, $base, $debug) = @_; |
|
159
|
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
my (@to_return, @form_stack); |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# start off with throwaway pointers |
|
163
|
0
|
|
|
|
|
|
my $F = {}; |
|
164
|
0
|
|
|
|
|
|
my $allfields = []; |
|
165
|
0
|
|
|
|
|
|
my $fields = []; |
|
166
|
0
|
|
|
|
|
|
my $fieldvals = {}; |
|
167
|
0
|
|
|
|
|
|
my $fieldtypes = {}; |
|
168
|
0
|
|
|
|
|
|
my $buttons = []; |
|
169
|
0
|
|
|
|
|
|
my $buttonvals = {}; |
|
170
|
0
|
|
|
|
|
|
my $buttontypes = {}; |
|
171
|
0
|
|
|
|
|
|
my $selections = {}; |
|
172
|
0
|
|
|
|
|
|
my $checkboxstate = {}; |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
$tree->traverse( |
|
175
|
|
|
|
|
|
|
sub { # pre-order callback: |
|
176
|
0
|
|
|
0
|
|
|
my ($self, $start, $depth) = @_; |
|
177
|
0
|
0
|
|
|
|
|
if (ref $self) { |
|
178
|
0
|
|
|
|
|
|
my $tag = $self->tag; |
|
179
|
0
|
0
|
0
|
|
|
|
if ($tag eq 'form' or $tag eq 'isindex') { |
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
180
|
0
|
0
|
|
|
|
|
if($start) { |
|
181
|
0
|
|
|
|
|
|
my $new = {}; |
|
182
|
0
|
|
|
|
|
|
$new->{'debug'} = $debug; |
|
183
|
0
|
0
|
|
|
|
|
if (defined($self->attr('method'))) { |
|
184
|
0
|
|
|
|
|
|
$new->{'method'} = $self->attr('method'); |
|
185
|
|
|
|
|
|
|
} else { |
|
186
|
0
|
|
|
|
|
|
$new->{'method'} = 'GET'; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
0
|
|
|
|
|
|
$new->{'link'} = $self->attr('action'); |
|
189
|
0
|
|
|
|
|
|
$new->{'name'} = $self->attr('name'); |
|
190
|
0
|
|
|
|
|
|
$new->{'base'} = $base; |
|
191
|
0
|
|
|
|
|
|
$new->{'allfields'} = $allfields = []; |
|
192
|
0
|
|
|
|
|
|
$new->{'fields'} = $fields = []; |
|
193
|
0
|
|
|
|
|
|
$new->{'fieldvals'} = $fieldvals = {}; |
|
194
|
0
|
|
|
|
|
|
$new->{'fieldtypes'} = $fieldtypes = {}; |
|
195
|
0
|
|
|
|
|
|
$new->{'buttons'} = $buttons = []; |
|
196
|
0
|
|
|
|
|
|
$new->{'buttonvals'} = $buttonvals = {}; |
|
197
|
0
|
|
|
|
|
|
$new->{'buttontypes'} = $buttontypes = {}; |
|
198
|
0
|
|
|
|
|
|
$new->{'selections'} = $selections = {}; |
|
199
|
0
|
|
|
|
|
|
$new->{'checkboxstate'} = $checkboxstate = {}; |
|
200
|
0
|
|
|
|
|
|
$new->{'upload'} = 0; |
|
201
|
0
|
|
|
|
|
|
bless $new, $class; |
|
202
|
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
$F = $new; |
|
204
|
0
|
|
|
|
|
|
push @to_return, $new; |
|
205
|
0
|
|
|
|
|
|
push @form_stack, $new; |
|
206
|
|
|
|
|
|
|
|
|
207
|
0
|
0
|
|
|
|
|
if($tag eq 'isindex') { |
|
208
|
0
|
|
|
|
|
|
$new->{'isindex'} = 1; |
|
209
|
0
|
|
|
|
|
|
push @$allfields, 'keywords'; # fake name. Same as CGI.pm uses. |
|
210
|
0
|
|
|
|
|
|
push @$fields, 'keywords'; # fake name |
|
211
|
0
|
|
|
|
|
|
$$fieldvals{'keywords'} = ''; # fake value |
|
212
|
0
|
|
|
|
|
|
$$fieldtypes{'keywords'} = "input/text"; # fake type |
|
213
|
0
|
|
|
|
|
|
$start = 0; # so we'll pop it in the next block. |
|
214
|
|
|
|
|
|
|
# (since ISINDEX is an empty element, we'd never |
|
215
|
|
|
|
|
|
|
# visit it in post-order for real) |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# In theory, this could mean that subsequent stranded form |
|
218
|
|
|
|
|
|
|
# elements would end up being put into this fake-o |
|
219
|
|
|
|
|
|
|
# Form object we made from the ISINDEX. But hey, ISINDEX |
|
220
|
|
|
|
|
|
|
# is rare (and deprecated) these days, and is very unlikely |
|
221
|
|
|
|
|
|
|
# to co-occur with stranded form elements. Moreover, the |
|
222
|
|
|
|
|
|
|
# added form elements would be basically ignored, unless |
|
223
|
|
|
|
|
|
|
# they actually had the field name "keywords". |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
0
|
0
|
|
|
|
|
unless($start) { |
|
228
|
|
|
|
|
|
|
# We're leaving a FORM or ISINDEX element. |
|
229
|
0
|
|
|
|
|
|
pop @form_stack; |
|
230
|
0
|
0
|
|
|
|
|
$F = $form_stack[-1] if @form_stack; |
|
231
|
|
|
|
|
|
|
# otherwise, the old one lingers. |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
# reset pointers: |
|
234
|
0
|
|
|
|
|
|
$allfields = $F->{'allfields'}; |
|
235
|
0
|
|
|
|
|
|
$fields = $F->{'fields'}; |
|
236
|
0
|
|
|
|
|
|
$fieldvals = $F->{'fieldvals'}; |
|
237
|
0
|
|
|
|
|
|
$fieldtypes = $F->{'fieldtypes'}; |
|
238
|
0
|
|
|
|
|
|
$buttons = $F->{'buttons'}; |
|
239
|
0
|
|
|
|
|
|
$buttonvals = $F->{'buttonvals'}; |
|
240
|
0
|
|
|
|
|
|
$buttontypes = $F->{'buttontypes'}; |
|
241
|
0
|
|
|
|
|
|
$selections = $F->{'selections'}; |
|
242
|
0
|
|
|
|
|
|
$checkboxstate = $F->{'checkboxstate'}; |
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
} elsif (($tag eq 'input') || |
|
246
|
|
|
|
|
|
|
(($tag eq 'button') && $start)) { |
|
247
|
0
|
|
|
|
|
|
my $type = lc($self->attr('type')); |
|
248
|
0
|
0
|
|
|
|
|
$type = "text" if (!defined($type)); |
|
249
|
0
|
0
|
0
|
|
|
|
if ($type eq 'hidden') { |
|
|
|
0
|
0
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
my $name = $self->attr('name'); |
|
251
|
0
|
|
|
|
|
|
my $value = $self->attr('value'); |
|
252
|
0
|
|
|
|
|
|
push @$allfields, $name; |
|
253
|
0
|
|
|
|
|
|
$$fieldvals{$name} = $value; |
|
254
|
0
|
|
|
|
|
|
$$fieldtypes{$name} = "$tag/$type"; |
|
255
|
|
|
|
|
|
|
} elsif (($type eq 'submit') || |
|
256
|
|
|
|
|
|
|
($type eq 'reset') || |
|
257
|
|
|
|
|
|
|
($type eq 'image')) { |
|
258
|
0
|
|
0
|
|
|
|
my $name = $self->attr('name') || $type; |
|
259
|
0
|
|
0
|
|
|
|
my $value = $self->attr('value') || $type; |
|
260
|
0
|
0
|
|
|
|
|
if (defined($name)) { |
|
261
|
0
|
0
|
|
|
|
|
if (!defined($$buttonvals{$name})) { |
|
262
|
0
|
|
|
|
|
|
push @$buttons, $name; |
|
263
|
0
|
|
|
|
|
|
$$buttonvals{$name} = [$value]; |
|
264
|
0
|
|
|
|
|
|
$$buttontypes{$name} = [$type]; |
|
265
|
|
|
|
|
|
|
} else { |
|
266
|
0
|
|
|
|
|
|
push @{$$buttonvals{$name}}, $value; |
|
|
0
|
|
|
|
|
|
|
|
267
|
0
|
|
|
|
|
|
push @{$$buttontypes{$name}}, $type; |
|
|
0
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
} |
|
269
|
|
|
|
|
|
|
} |
|
270
|
|
|
|
|
|
|
} else { |
|
271
|
0
|
|
|
|
|
|
my $name = $self->attr('name'); |
|
272
|
0
|
|
|
|
|
|
my $value = $self->attr('value'); |
|
273
|
0
|
0
|
|
|
|
|
if ($type eq 'radio') { |
|
|
|
0
|
|
|
|
|
|
|
274
|
0
|
0
|
|
|
|
|
if (!defined($$fieldtypes{$name})) { |
|
275
|
0
|
|
|
|
|
|
push @$allfields, $name; |
|
276
|
0
|
|
|
|
|
|
push @$fields, $name; |
|
277
|
0
|
|
|
|
|
|
$$fieldtypes{$name} = "$tag/$type"; |
|
278
|
|
|
|
|
|
|
} |
|
279
|
0
|
0
|
|
|
|
|
if (!defined($$selections{$name})) { |
|
280
|
0
|
|
|
|
|
|
$$selections{$name} = [$value]; |
|
281
|
|
|
|
|
|
|
} else { |
|
282
|
0
|
|
|
|
|
|
push @{$$selections{$name}}, $value; |
|
|
0
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
} |
|
284
|
0
|
0
|
|
|
|
|
$$fieldvals{$name} = $value if ($self->attr('checked')); |
|
285
|
|
|
|
|
|
|
} elsif ($type eq 'checkbox') { |
|
286
|
0
|
|
|
|
|
|
push @$allfields, $name; |
|
287
|
0
|
|
|
|
|
|
push @$fields, $name; |
|
288
|
0
|
|
|
|
|
|
$$fieldvals{$name} = $value; |
|
289
|
0
|
|
|
|
|
|
$$fieldtypes{$name} = "$tag/$type"; |
|
290
|
0
|
0
|
|
|
|
|
if ($self->attr('checked')) { |
|
291
|
0
|
|
|
|
|
|
$$checkboxstate{$name} = 1; |
|
292
|
|
|
|
|
|
|
} else { |
|
293
|
0
|
|
|
|
|
|
$$checkboxstate{$name} = 0; |
|
294
|
|
|
|
|
|
|
} |
|
295
|
|
|
|
|
|
|
} else { |
|
296
|
0
|
|
|
|
|
|
push @$allfields, $name; |
|
297
|
0
|
|
|
|
|
|
push @$fields, $name; |
|
298
|
0
|
|
|
|
|
|
$$fieldvals{$name} = $value; |
|
299
|
0
|
|
|
|
|
|
$$fieldtypes{$name} = "$tag/$type"; |
|
300
|
|
|
|
|
|
|
} |
|
301
|
0
|
0
|
|
|
|
|
if ($type eq 'file') { |
|
302
|
0
|
|
|
|
|
|
$F->{'upload'} = 1; |
|
303
|
|
|
|
|
|
|
} |
|
304
|
|
|
|
|
|
|
} |
|
305
|
|
|
|
|
|
|
} elsif (($tag eq 'textarea') && $start) { |
|
306
|
0
|
|
|
|
|
|
my $name = $self->attr('name'); |
|
307
|
0
|
|
|
|
|
|
push @$allfields, $name; |
|
308
|
0
|
|
|
|
|
|
push @$fields, $name; |
|
309
|
0
|
|
|
|
|
|
$$fieldvals{$name} = ""; |
|
310
|
0
|
|
|
|
|
|
foreach my $o (@{$self->content}) { |
|
|
0
|
|
|
|
|
|
|
|
311
|
0
|
0
|
|
|
|
|
if ($o->can('as_HTML')) { |
|
312
|
0
|
|
|
|
|
|
$$fieldvals{$name} .= $o->as_HTML; |
|
313
|
|
|
|
|
|
|
} else { |
|
314
|
0
|
|
|
|
|
|
$$fieldvals{$name} .= $o; |
|
315
|
|
|
|
|
|
|
} |
|
316
|
|
|
|
|
|
|
} |
|
317
|
0
|
|
|
|
|
|
$$fieldtypes{$name} = $tag; |
|
318
|
|
|
|
|
|
|
} elsif (($tag eq 'select') && $start) { |
|
319
|
0
|
|
|
|
|
|
my $name = $self->attr('name'); |
|
320
|
0
|
|
|
|
|
|
push @$allfields, $name; |
|
321
|
0
|
|
|
|
|
|
push @$fields, $name; |
|
322
|
0
|
|
|
|
|
|
foreach my $o (@{$self->content}) { |
|
|
0
|
|
|
|
|
|
|
|
323
|
0
|
0
|
|
|
|
|
if (ref $o) { |
|
324
|
0
|
|
|
|
|
|
my $tag = $o->tag; |
|
325
|
0
|
0
|
|
|
|
|
if ($tag eq 'option') { |
|
326
|
0
|
0
|
|
|
|
|
if ($o->attr('selected')) { |
|
327
|
0
|
|
|
|
|
|
$$fieldvals{$name} = $o->attr('value'); |
|
328
|
|
|
|
|
|
|
} |
|
329
|
0
|
0
|
|
|
|
|
if (!defined($$selections{$name})) { |
|
330
|
0
|
|
|
|
|
|
$$selections{$name} = [$o->attr('value')]; |
|
331
|
|
|
|
|
|
|
} else { |
|
332
|
0
|
|
|
|
|
|
push @{$$selections{$name}}, $o->attr('value'); |
|
|
0
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
} |
|
334
|
|
|
|
|
|
|
} |
|
335
|
|
|
|
|
|
|
} |
|
336
|
|
|
|
|
|
|
} |
|
337
|
0
|
|
|
|
|
|
$$fieldtypes{$name} = $tag; |
|
338
|
|
|
|
|
|
|
} |
|
339
|
|
|
|
|
|
|
} |
|
340
|
0
|
|
|
|
|
|
1; |
|
341
|
0
|
|
|
|
|
|
}, 0 |
|
342
|
|
|
|
|
|
|
); |
|
343
|
|
|
|
|
|
|
|
|
344
|
0
|
|
|
|
|
|
return @to_return; |
|
345
|
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
} |
|
347
|
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
sub fields { |
|
349
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
350
|
0
|
|
|
|
|
|
return @{$self->{'fields'}}; |
|
|
0
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
} |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
sub name { |
|
354
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
355
|
0
|
|
|
|
|
|
return $self->{'name'}; |
|
356
|
|
|
|
|
|
|
} |
|
357
|
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
sub isindex { |
|
359
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
360
|
0
|
|
|
|
|
|
return $self->{'isindex'}; |
|
361
|
|
|
|
|
|
|
} |
|
362
|
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
sub allfields { |
|
364
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
365
|
0
|
|
|
|
|
|
return @{$self->{'allfields'}}; |
|
|
0
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
} |
|
367
|
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
sub base { |
|
369
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
370
|
0
|
|
|
|
|
|
return $self->{'base'}; |
|
371
|
|
|
|
|
|
|
} |
|
372
|
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
sub method { |
|
374
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
375
|
0
|
|
|
|
|
|
return $self->{'method'}; |
|
376
|
|
|
|
|
|
|
} |
|
377
|
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
sub link { |
|
379
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
380
|
0
|
|
|
|
|
|
return $self->{'link'}; |
|
381
|
|
|
|
|
|
|
} |
|
382
|
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
sub field { |
|
384
|
0
|
|
|
0
|
1
|
|
my ($self, $name, $value) = @_; |
|
385
|
0
|
0
|
|
|
|
|
if (defined($value)) { |
|
386
|
0
|
|
|
|
|
|
$self->{'fieldvals'}->{$name} = $value; |
|
387
|
|
|
|
|
|
|
} else { |
|
388
|
0
|
|
|
|
|
|
return $self->{'fieldvals'}->{$name}; |
|
389
|
|
|
|
|
|
|
} |
|
390
|
|
|
|
|
|
|
} |
|
391
|
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
sub field_selection { |
|
393
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
|
394
|
0
|
|
|
|
|
|
return $self->{'selections'}->{$name}; |
|
395
|
|
|
|
|
|
|
} |
|
396
|
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
sub field_type { |
|
398
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
|
399
|
0
|
|
|
|
|
|
return $self->{'fieldtypes'}->{$name}; |
|
400
|
|
|
|
|
|
|
} |
|
401
|
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
sub is_selection { |
|
403
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
|
404
|
0
|
0
|
|
|
|
|
if (defined($self->field_selection($name))) { |
|
405
|
0
|
|
|
|
|
|
return 1; |
|
406
|
|
|
|
|
|
|
} else { |
|
407
|
0
|
|
|
|
|
|
return undef; |
|
408
|
|
|
|
|
|
|
} |
|
409
|
|
|
|
|
|
|
} |
|
410
|
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
sub checkbox_check { |
|
412
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
|
413
|
0
|
0
|
|
|
|
|
return if (!defined($self->{'checkboxstate'}->{$name})); |
|
414
|
0
|
|
|
|
|
|
$self->{'checkboxstate'}->{$name} = 1; |
|
415
|
|
|
|
|
|
|
} |
|
416
|
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
sub checkbox_uncheck { |
|
418
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
|
419
|
0
|
0
|
|
|
|
|
return if (!defined($self->{'checkboxstate'}->{$name})); |
|
420
|
0
|
|
|
|
|
|
$self->{'checkboxstate'}->{$name} = 0; |
|
421
|
|
|
|
|
|
|
} |
|
422
|
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
sub checkbox_toggle { |
|
424
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
|
425
|
0
|
0
|
|
|
|
|
return if (!defined($self->{'checkboxstate'}->{$name})); |
|
426
|
0
|
0
|
|
|
|
|
if ($self->{'checkboxstate'}->{$name}) { |
|
427
|
0
|
|
|
|
|
|
$self->{'checkboxstate'}->{$name} = 0; |
|
428
|
|
|
|
|
|
|
} else { |
|
429
|
0
|
|
|
|
|
|
$self->{'checkboxstate'}->{$name} = 1; |
|
430
|
|
|
|
|
|
|
} |
|
431
|
|
|
|
|
|
|
} |
|
432
|
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
sub checkbox_ischecked { |
|
434
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
|
435
|
0
|
|
|
|
|
|
return $self->{'checkboxstate'}->{$name}; |
|
436
|
|
|
|
|
|
|
} |
|
437
|
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
sub is_checkbox { |
|
439
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
|
440
|
0
|
0
|
|
|
|
|
if (defined($self->{'checkboxstate'}->($name))) { |
|
441
|
0
|
|
|
|
|
|
return 1; |
|
442
|
|
|
|
|
|
|
} else { |
|
443
|
0
|
|
|
|
|
|
return undef; |
|
444
|
|
|
|
|
|
|
} |
|
445
|
|
|
|
|
|
|
} |
|
446
|
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
sub checkboxes { |
|
448
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
449
|
0
|
|
|
|
|
|
return keys %{$self->{'checkboxstate'}} |
|
|
0
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
} |
|
451
|
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
sub buttons { |
|
453
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
454
|
0
|
|
|
|
|
|
return @{$self->{'buttons'}}; |
|
|
0
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
} |
|
456
|
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
sub button { |
|
458
|
0
|
|
|
0
|
1
|
|
my ($self, $button, $value) = @_; |
|
459
|
0
|
0
|
|
|
|
|
if (defined($value)) { |
|
460
|
0
|
|
|
|
|
|
$self->{'buttonvals'}->{$button} = $value; |
|
461
|
|
|
|
|
|
|
} else { |
|
462
|
0
|
|
|
|
|
|
return $self->{'buttonvals'}->{$button}; |
|
463
|
|
|
|
|
|
|
} |
|
464
|
|
|
|
|
|
|
} |
|
465
|
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
sub button_type { |
|
467
|
0
|
|
|
0
|
1
|
|
my ($self, $button) = @_; |
|
468
|
0
|
|
|
|
|
|
return $self->{'buttontypes'}->{$button}; |
|
469
|
|
|
|
|
|
|
} |
|
470
|
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
sub button_exists { |
|
472
|
0
|
|
|
0
|
1
|
|
my ($self, $button) = @_; |
|
473
|
0
|
0
|
|
|
|
|
if (defined($self->button($button))) { |
|
474
|
0
|
|
|
|
|
|
return 1; |
|
475
|
|
|
|
|
|
|
} else { |
|
476
|
0
|
|
|
|
|
|
return undef; |
|
477
|
|
|
|
|
|
|
} |
|
478
|
|
|
|
|
|
|
} |
|
479
|
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
sub referer { |
|
481
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
|
482
|
0
|
0
|
|
|
|
|
if (defined($value)) { |
|
483
|
0
|
|
|
|
|
|
$self->{'referer'} = $value; |
|
484
|
|
|
|
|
|
|
} else { |
|
485
|
0
|
|
|
|
|
|
return $self->{'referer'}; |
|
486
|
|
|
|
|
|
|
} |
|
487
|
|
|
|
|
|
|
} |
|
488
|
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
sub press { |
|
490
|
0
|
|
|
0
|
1
|
|
my ($self, $button, $bnum, $bnum2) = @_; |
|
491
|
0
|
|
|
|
|
|
my $x = 2; |
|
492
|
0
|
|
|
|
|
|
my $y = 2; |
|
493
|
0
|
0
|
|
|
|
|
if (ref $bnum) { |
|
494
|
0
|
|
|
|
|
|
$x = $bnum->[0]; |
|
495
|
0
|
|
|
|
|
|
$y = $bnum->[1]; |
|
496
|
0
|
|
|
|
|
|
$bnum = $bnum2; |
|
497
|
|
|
|
|
|
|
} |
|
498
|
0
|
|
|
|
|
|
my @array = (); |
|
499
|
0
|
|
|
|
|
|
foreach my $i ($self->allfields) { |
|
500
|
0
|
0
|
|
|
|
|
if ($self->field_type($i) eq "input/checkbox") { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
501
|
0
|
0
|
|
|
|
|
if ($self->checkbox_ischecked($i)) { |
|
502
|
0
|
|
|
|
|
|
push @array, $i; |
|
503
|
0
|
|
|
|
|
|
push @array, $self->field($i); |
|
504
|
|
|
|
|
|
|
} |
|
505
|
|
|
|
|
|
|
} elsif ($self->field_type($i) eq "select") { |
|
506
|
0
|
0
|
|
|
|
|
if (defined($self->field($i))) { |
|
507
|
0
|
|
|
|
|
|
push @array, $i; |
|
508
|
0
|
|
|
|
|
|
push @array, $self->field($i); |
|
509
|
|
|
|
|
|
|
} |
|
510
|
|
|
|
|
|
|
} elsif ($self->field_type($i) eq "input/file") { |
|
511
|
0
|
|
|
|
|
|
push @array, $i; |
|
512
|
0
|
|
|
|
|
|
push @array, [ $self->field($i) ]; |
|
513
|
|
|
|
|
|
|
} else { |
|
514
|
0
|
|
|
|
|
|
push @array, $i; |
|
515
|
0
|
|
|
|
|
|
push @array, $self->field($i); |
|
516
|
|
|
|
|
|
|
} |
|
517
|
|
|
|
|
|
|
} |
|
518
|
0
|
0
|
|
|
|
|
if (defined($button)) { |
|
519
|
0
|
0
|
|
|
|
|
die "Button $button not included in form" |
|
520
|
|
|
|
|
|
|
if (!defined($self->button($button))); |
|
521
|
0
|
0
|
|
|
|
|
if (defined($bnum)) { |
|
522
|
0
|
0
|
|
|
|
|
if (@{$self->button_type($button)}[$bnum] eq "image") { |
|
|
0
|
|
|
|
|
|
|
|
523
|
0
|
|
|
|
|
|
push @array, $button . '.x', $x; |
|
524
|
0
|
|
|
|
|
|
push @array, $button . '.y', $y; |
|
525
|
|
|
|
|
|
|
} else { |
|
526
|
0
|
|
|
|
|
|
push @array, $button, @{$self->button($button)}[$bnum]; |
|
|
0
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
} |
|
528
|
|
|
|
|
|
|
} else { |
|
529
|
0
|
0
|
|
|
|
|
if (@{$self->button_type($button)}[0] eq "image") { |
|
|
0
|
|
|
|
|
|
|
|
530
|
0
|
|
|
|
|
|
push @array, $button . '.x', $x; |
|
531
|
0
|
|
|
|
|
|
push @array, $button . '.y', $y; |
|
532
|
|
|
|
|
|
|
} else { |
|
533
|
0
|
|
|
|
|
|
push @array, $button, @{$self->button($button)}[0]; |
|
|
0
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
} |
|
535
|
|
|
|
|
|
|
} |
|
536
|
|
|
|
|
|
|
} |
|
537
|
0
|
|
|
|
|
|
my $url = url $self->link; |
|
538
|
0
|
0
|
|
|
|
|
if (defined($self->base)) { |
|
539
|
0
|
|
|
|
|
|
$url = $url->abs($self->base); |
|
540
|
|
|
|
|
|
|
} |
|
541
|
0
|
0
|
|
|
|
|
if ($self->{'debug'}) { |
|
542
|
0
|
|
|
|
|
|
print $self->method, " $url ", join(' - ', @array), "\n"; |
|
543
|
|
|
|
|
|
|
} |
|
544
|
0
|
0
|
|
|
|
|
if ($self->{'isindex'}) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
545
|
0
|
|
|
|
|
|
$url->query_keywords( $self->{'fieldvals'}->{'keywords'} ); |
|
546
|
0
|
|
|
|
|
|
return GET $url; |
|
547
|
|
|
|
|
|
|
} elsif (uc($self->method) eq "POST") { |
|
548
|
0
|
|
|
|
|
|
my $referer = $self->referer; |
|
549
|
0
|
0
|
|
|
|
|
if ($self->{'upload'}) { |
|
550
|
0
|
0
|
|
|
|
|
if (defined($referer)) { |
|
551
|
0
|
|
|
|
|
|
return POST $url, Content_Type => 'form-data', |
|
552
|
|
|
|
|
|
|
'referer' => $referer, |
|
553
|
|
|
|
|
|
|
Content => \@array; |
|
554
|
|
|
|
|
|
|
} else { |
|
555
|
0
|
|
|
|
|
|
return POST $url, Content_Type => 'form-data', |
|
556
|
|
|
|
|
|
|
Content => \@array; |
|
557
|
|
|
|
|
|
|
} |
|
558
|
|
|
|
|
|
|
} else { |
|
559
|
0
|
0
|
|
|
|
|
if (defined($referer)) { |
|
560
|
0
|
|
|
|
|
|
return POST $url, 'referer' => $referer, |
|
561
|
|
|
|
|
|
|
Content => \@array; |
|
562
|
|
|
|
|
|
|
} else { |
|
563
|
0
|
|
|
|
|
|
return POST $url, \@array; |
|
564
|
|
|
|
|
|
|
} |
|
565
|
|
|
|
|
|
|
} |
|
566
|
|
|
|
|
|
|
} elsif (uc($self->method) eq "GET") { |
|
567
|
0
|
|
|
|
|
|
$url->query_form(@array); |
|
568
|
0
|
|
|
|
|
|
return GET $url; |
|
569
|
|
|
|
|
|
|
} |
|
570
|
|
|
|
|
|
|
} |
|
571
|
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
sub dump { |
|
573
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
574
|
0
|
|
|
|
|
|
print "FORM METHOD=", $self->method, "\n ACTION=", $self->link, "\n BASE=", $self->base, "\n"; |
|
575
|
0
|
|
|
|
|
|
foreach my $i ($self->allfields) { |
|
576
|
0
|
0
|
|
|
|
|
if (defined($self->field($i))) { |
|
577
|
0
|
|
|
|
|
|
print "FIELD{", $self->field_type($i), "} $i=", $self->field($i), "\n"; |
|
578
|
|
|
|
|
|
|
} else { |
|
579
|
0
|
|
|
|
|
|
print "FIELD{", $self->field_type($i), "} $i\n"; |
|
580
|
|
|
|
|
|
|
} |
|
581
|
0
|
0
|
|
|
|
|
if ($self->is_selection($i)) { |
|
582
|
0
|
|
|
|
|
|
print " [", join(", ", @{$self->field_selection($i)}), "]\n"; |
|
|
0
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
} |
|
584
|
|
|
|
|
|
|
} |
|
585
|
0
|
|
|
|
|
|
foreach my $i ($self->buttons) { |
|
586
|
0
|
0
|
|
|
|
|
if (defined($self->button($i))) { |
|
587
|
0
|
0
|
|
|
|
|
print "BUTTON $i=[", join(", ", map {$_ ? $_ : "<undef>"} @{$self->button($i)}), "]\n"; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
} else { |
|
589
|
0
|
|
|
|
|
|
print "BUTTON $i\n"; |
|
590
|
|
|
|
|
|
|
} |
|
591
|
0
|
0
|
|
|
|
|
if (defined($self->button_type($i))) { |
|
592
|
0
|
|
|
|
|
|
print " $i={", join(", ", @{$self->button_type($i)}), "}\n"; |
|
|
0
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
} |
|
594
|
|
|
|
|
|
|
} |
|
595
|
0
|
|
|
|
|
|
print "\n"; |
|
596
|
|
|
|
|
|
|
} |
|
597
|
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
1; |
|
599
|
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
__END__ |
|
601
|
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
=head1 NAME |
|
603
|
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
HTTP::Request::Form - Construct HTTP::Request objects for form processing |
|
605
|
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
607
|
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
use the following as a tool to query Altavista for "perl" from the commandline: |
|
609
|
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
use URI::URL; |
|
611
|
|
|
|
|
|
|
use LWP::UserAgent; |
|
612
|
|
|
|
|
|
|
use HTTP::Request; |
|
613
|
|
|
|
|
|
|
use HTTP::Request::Common; |
|
614
|
|
|
|
|
|
|
use HTTP::Request::Form; |
|
615
|
|
|
|
|
|
|
use HTML::TreeBuilder 3.0; |
|
616
|
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
|
618
|
|
|
|
|
|
|
my $url = url 'http://www.altavista.digital.com/'; |
|
619
|
|
|
|
|
|
|
my $res = $ua->request(GET $url); |
|
620
|
|
|
|
|
|
|
my $tree = HTML::TreeBuilder->new; |
|
621
|
|
|
|
|
|
|
$tree->parse($res->content); |
|
622
|
|
|
|
|
|
|
$tree->eof(); |
|
623
|
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
my @forms = $tree->find_by_tag_name('FORM'); |
|
625
|
|
|
|
|
|
|
die "What, no forms in $url?" unless @forms; |
|
626
|
|
|
|
|
|
|
my $f = HTTP::Request::Form->new($forms[0], $url); |
|
627
|
|
|
|
|
|
|
$f->field("q", "perl"); |
|
628
|
|
|
|
|
|
|
my $response = $ua->request($f->press("search")); |
|
629
|
|
|
|
|
|
|
print $response->content if $response->is_success; |
|
630
|
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
632
|
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
This is an extension of the HTTP::Request suite. It allows easy processing |
|
634
|
|
|
|
|
|
|
of forms in a user agent by filling out fields, querying fields, selections |
|
635
|
|
|
|
|
|
|
and buttons and pressing buttons. It uses HTML::TreeBuilder generated parse |
|
636
|
|
|
|
|
|
|
trees of documents (especially the forms parts extracted with extract_links) |
|
637
|
|
|
|
|
|
|
and generates it's own internal representation of forms from which it then |
|
638
|
|
|
|
|
|
|
generates the request objects to process the form application. |
|
639
|
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
=head1 CLASS METHODS |
|
641
|
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
=over 4 |
|
643
|
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
=item new($form [, $base [, $debug]]) |
|
645
|
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
The C<new-method> constructs a new form processor. It get's an HTML::Element |
|
647
|
|
|
|
|
|
|
object that contains a FORM element or ISINDEX element as the single parameter. |
|
648
|
|
|
|
|
|
|
If an base-url is given as an additional parameter, this is used to make the |
|
649
|
|
|
|
|
|
|
form-url absolute in regard to the given URL. |
|
650
|
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
If debugging is true, the following functions will be a bit "talky" on stdio. |
|
652
|
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
=item new_many($tree_part [, $base [, $debug]]) |
|
654
|
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
The C<new_many> method returns a list of newly constructed form processors. |
|
656
|
|
|
|
|
|
|
It's just like the C<new> method except that it can apply to any part of an |
|
657
|
|
|
|
|
|
|
HTML::Element tree, including the root; it constructs a new form processor |
|
658
|
|
|
|
|
|
|
for each FORM element at or under C<$tree_part>. |
|
659
|
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
Note that the return list might have zero, one or many new objects in it, |
|
661
|
|
|
|
|
|
|
depending on how many FORM (or ISINDEX) elements were found. |
|
662
|
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
Form elements (like INPUT, etc.) found outside of FORM elements are counted |
|
664
|
|
|
|
|
|
|
as being part of the preceding FORM element. (And if there is no preceding |
|
665
|
|
|
|
|
|
|
FORM element, they are ignored.) This feature is useful with the odd parse |
|
666
|
|
|
|
|
|
|
trees that can result from basd HTML in or around FORM elements. If you need |
|
667
|
|
|
|
|
|
|
to override that feature, then instead call: |
|
668
|
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
map HTTP::Request::Form->new($_), $tree->find_by_tag_name('FORM'); |
|
670
|
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
=back |
|
672
|
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
=head1 INSTANCE METHODS |
|
674
|
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
=over 4 |
|
676
|
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
=item base() |
|
678
|
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
This returns the parameter $base to the "new" constructor. |
|
680
|
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
=item link() |
|
682
|
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
This returns the action attribute of the original form structure. This value |
|
684
|
|
|
|
|
|
|
is cached within the form processor, so you can safely delete the form |
|
685
|
|
|
|
|
|
|
structure after you created the form processor. |
|
686
|
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
=item method() |
|
688
|
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
This returns the method attribute of the original form structure. This value |
|
690
|
|
|
|
|
|
|
is cached within the form processor, so you can safely delete the form |
|
691
|
|
|
|
|
|
|
structure as soon as you created the form processor. |
|
692
|
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
=item isindex() |
|
694
|
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
This returns true if this came from an original form structure that was |
|
696
|
|
|
|
|
|
|
actually an ISINDEX element. In that case, the form will hagve only |
|
697
|
|
|
|
|
|
|
one field, an input/text field named "keywords". |
|
698
|
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
=item name() |
|
700
|
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
This returns the name attribute of the original form structure. This value |
|
702
|
|
|
|
|
|
|
is cached within the form processor, so you can safely delete the form |
|
703
|
|
|
|
|
|
|
structure after you created the form processor. |
|
704
|
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
=item fields() |
|
706
|
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
This method delivers a list of fieldnames that are of "open" type. This |
|
708
|
|
|
|
|
|
|
excludes the "hidden" and "submit" elements, because they are already filled |
|
709
|
|
|
|
|
|
|
with a value (and as such declared as "closed") or as in the case of "submit" |
|
710
|
|
|
|
|
|
|
are buttons, of which only one must be used. |
|
711
|
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
=item allfields() |
|
713
|
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
This delivers a list of all fieldnames in the order as they occured in the |
|
715
|
|
|
|
|
|
|
form-source excluding the submit fields. |
|
716
|
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
=item field($name [, $value]) |
|
718
|
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
This method retrieves or sets a field-value. The field is identified by |
|
720
|
|
|
|
|
|
|
its name. You have to be sure that you only put a allowed value into the |
|
721
|
|
|
|
|
|
|
field. |
|
722
|
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
=item field_type($name) |
|
724
|
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
This method gives you the type of the named field, so that you can |
|
726
|
|
|
|
|
|
|
distinguish on this type. (this is the only way to distinguish |
|
727
|
|
|
|
|
|
|
selections and radio buttons). |
|
728
|
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
=item is_selection($name) |
|
730
|
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
This tests if a field is a selection or an input. Radio-Buttons are |
|
732
|
|
|
|
|
|
|
used in the same way as standard selection fields, so is_selection |
|
733
|
|
|
|
|
|
|
returns a true value for radio buttons, too! (Of course, only one |
|
734
|
|
|
|
|
|
|
value is submitted for a radio button) |
|
735
|
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
=item field_selection($name) |
|
737
|
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
This delivers the array of the options of a selection. The element that is |
|
739
|
|
|
|
|
|
|
marked with selected in the source is given as the default value. This |
|
740
|
|
|
|
|
|
|
works in the same way for radio buttons, as they are just handled |
|
741
|
|
|
|
|
|
|
as a special case of selections! |
|
742
|
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
=item is_checkbox($name) |
|
744
|
|
|
|
|
|
|
|
|
745
|
|
|
|
|
|
|
This tells you if a field is a checkbox. If it is, there are several support |
|
746
|
|
|
|
|
|
|
methods to make use of the special features of checkboxes, for example the |
|
747
|
|
|
|
|
|
|
fact that it is only sent if it is checked. |
|
748
|
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
=item checkboxes() |
|
750
|
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
This method delivers a list of all checkbox fields much in the same way as |
|
752
|
|
|
|
|
|
|
the buttons method. |
|
753
|
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
=item checkbox_check($name) |
|
755
|
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
=item checkbox_uncheck($name) |
|
757
|
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
=item checkbox_toggle($name) |
|
759
|
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
These methods set, unset or toggle the checkbox checked state. Checkbox |
|
761
|
|
|
|
|
|
|
values are only added to the result if they are checked. |
|
762
|
|
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
=item checkbox_ischecked($name) |
|
764
|
|
|
|
|
|
|
|
|
765
|
|
|
|
|
|
|
This methods tells you wether a checkbox is checked or not. This is important |
|
766
|
|
|
|
|
|
|
if you want to analyze the state of fields directly after the parse. |
|
767
|
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
=item buttons() |
|
769
|
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
This delivers a list of all defined and named buttons of a form. |
|
771
|
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
=item button($button [, $value]) |
|
773
|
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
This gets or sets the value of a button. Normally only getting a button value |
|
775
|
|
|
|
|
|
|
is needed. The value of a button is a reference to an array of values (because |
|
776
|
|
|
|
|
|
|
a button can exist multiple times). |
|
777
|
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
=item button_type($button) |
|
779
|
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
This gives you the type of a button (submit/reset/image). The result |
|
781
|
|
|
|
|
|
|
is an array of type names, as a button with one name can exist |
|
782
|
|
|
|
|
|
|
multiple times. |
|
783
|
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
=item button_exists($button) |
|
785
|
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
This gives true if the named button exists, false (undef) otherwise. |
|
787
|
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
=item referer([$value]) |
|
789
|
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
This returns or sets the referer header for an request. This is useful if |
|
791
|
|
|
|
|
|
|
a CGI needs a set referer for authentication. |
|
792
|
|
|
|
|
|
|
|
|
793
|
|
|
|
|
|
|
=item press([$name [, $coord ] [, $number]]) |
|
794
|
|
|
|
|
|
|
|
|
795
|
|
|
|
|
|
|
This method creates a HTTP::Request object (via HTTP::Request::Common) that |
|
796
|
|
|
|
|
|
|
sends the formdata to the server with the requested method. If you give a |
|
797
|
|
|
|
|
|
|
button-name, that button is used. If you give no button name, it assumes a |
|
798
|
|
|
|
|
|
|
button without a name and just leaves out this last parameter. If the number |
|
799
|
|
|
|
|
|
|
of the button is given, that button value is delivered. If the number is not |
|
800
|
|
|
|
|
|
|
given, 0 (the first button of this name) is assumed. |
|
801
|
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
The "coord" parameter comes in handy if you have an image button. If this |
|
803
|
|
|
|
|
|
|
is the case, the button press will simulate a press at coordinates [2,2] |
|
804
|
|
|
|
|
|
|
unless you provide an anonymous array with different coordinates. |
|
805
|
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
=item dump() |
|
807
|
|
|
|
|
|
|
|
|
808
|
|
|
|
|
|
|
This method dumps the form-data on stdio for debugging purpose. |
|
809
|
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
=back |
|
811
|
|
|
|
|
|
|
|
|
812
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
813
|
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
L<HTTP::Request>, L<HTTP::Request::Common>, L<LWP::UserAgent>, |
|
815
|
|
|
|
|
|
|
L<HTML::Element>, L<URI::URL> |
|
816
|
|
|
|
|
|
|
|
|
817
|
|
|
|
|
|
|
=head1 INSTALLATION |
|
818
|
|
|
|
|
|
|
|
|
819
|
|
|
|
|
|
|
perl Makefile.PL |
|
820
|
|
|
|
|
|
|
make install |
|
821
|
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
or see L<perlmodinstall> |
|
823
|
|
|
|
|
|
|
|
|
824
|
|
|
|
|
|
|
=head1 REQUIRES |
|
825
|
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
Perl version 5.004 or later |
|
827
|
|
|
|
|
|
|
|
|
828
|
|
|
|
|
|
|
HTTP::Request::Common |
|
829
|
|
|
|
|
|
|
HTML::TreeBuilder |
|
830
|
|
|
|
|
|
|
LWP::UserAgent |
|
831
|
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
=head1 VERSION |
|
833
|
|
|
|
|
|
|
|
|
834
|
|
|
|
|
|
|
HTTP::Request::Form version 0.9, February 8th, 2001 |
|
835
|
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
=head1 RESTRICTIONS |
|
837
|
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
Only a subset of all possible form elements are currently supported. The list |
|
839
|
|
|
|
|
|
|
of supported tags as of this version includes: |
|
840
|
|
|
|
|
|
|
|
|
841
|
|
|
|
|
|
|
INPUT/CHECKBOX |
|
842
|
|
|
|
|
|
|
INPUT/HIDDEN |
|
843
|
|
|
|
|
|
|
INPUT/IMAGE |
|
844
|
|
|
|
|
|
|
INPUT/RADIO |
|
845
|
|
|
|
|
|
|
INPUT/RESET |
|
846
|
|
|
|
|
|
|
INPUT/SUBMIT |
|
847
|
|
|
|
|
|
|
INPUT/FILE |
|
848
|
|
|
|
|
|
|
INPUT/* (are all handled as simple text entry) |
|
849
|
|
|
|
|
|
|
OPTION |
|
850
|
|
|
|
|
|
|
SELECT |
|
851
|
|
|
|
|
|
|
TEXTAREA |
|
852
|
|
|
|
|
|
|
ISINDEX |
|
853
|
|
|
|
|
|
|
|
|
854
|
|
|
|
|
|
|
=head1 BUGS |
|
855
|
|
|
|
|
|
|
|
|
856
|
|
|
|
|
|
|
There is currently no support for multiple selections (you can do |
|
857
|
|
|
|
|
|
|
them yourself by setting a selection to a comma-delimited list of |
|
858
|
|
|
|
|
|
|
values). |
|
859
|
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
Multiple fields are not properly handled, only the last value is |
|
861
|
|
|
|
|
|
|
available. Exception are buttons, they are handled in the right way. |
|
862
|
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
If there are several fields with the same name, you can only set |
|
864
|
|
|
|
|
|
|
the value of the first of this fields (this is especially problematic |
|
865
|
|
|
|
|
|
|
with checkboxes). This does work with buttons that have the same |
|
866
|
|
|
|
|
|
|
name, though (you can press each instance identified by number). |
|
867
|
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
Error-Checking is currently very limited (not to say nonexistant). |
|
869
|
|
|
|
|
|
|
|
|
870
|
|
|
|
|
|
|
Support for HTML 4.0 optgroup tags is missing (as is with allmost |
|
871
|
|
|
|
|
|
|
all current browsers, so that is not a great loss). |
|
872
|
|
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
The button tag (HTML 4.0) is just handled as an alias for the input |
|
874
|
|
|
|
|
|
|
tag - this is of course incorrect, but sufficient for support of |
|
875
|
|
|
|
|
|
|
the usual button types. |
|
876
|
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
878
|
|
|
|
|
|
|
|
|
879
|
|
|
|
|
|
|
Copyright 1998, 1999, 2000 Georg Bauer E<lt>Georg_Bauer@muensterland.orgE<gt> |
|
880
|
|
|
|
|
|
|
|
|
881
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or |
|
882
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
|
883
|
|
|
|
|
|
|
|
|
884
|
|
|
|
|
|
|
=head1 MAJOR CONTRIBUTORS |
|
885
|
|
|
|
|
|
|
|
|
886
|
|
|
|
|
|
|
Sean M. Burke (ISINDEX, new_many) |
|
887
|
|
|
|
|
|
|
|
|
888
|
|
|
|
|
|
|
=cut |
|
889
|
|
|
|
|
|
|
|