line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Test::Form::Widget::Button; |
2
|
14
|
|
|
14
|
|
58
|
use strict; |
|
14
|
|
|
|
|
20
|
|
|
14
|
|
|
|
|
329
|
|
3
|
14
|
|
|
14
|
|
43
|
use warnings; |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
242
|
|
4
|
|
|
|
|
|
|
################################################################## |
5
|
|
|
|
|
|
|
# $Id: Button.pm 411 2011-09-26 11:19:30Z nohuhu@nohuhu.org $ |
6
|
|
|
|
|
|
|
# $Name: cgi-test_0-104_t1 $ |
7
|
|
|
|
|
|
|
################################################################## |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Copyright (c) 2001, Raphael Manfredi |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# You may redistribute only under the terms of the Artistic License, |
12
|
|
|
|
|
|
|
# as specified in the README file that comes with the distribution. |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
|
15
|
14
|
|
|
14
|
|
33
|
use Carp; |
|
14
|
|
|
|
|
21
|
|
|
14
|
|
|
|
|
536
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
# This class models a FORM button. |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
|
21
|
14
|
|
|
14
|
|
42
|
use base qw(CGI::Test::Form::Widget); |
|
14
|
|
|
|
|
22
|
|
|
14
|
|
|
|
|
4771
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
############################################################ |
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
# ->new |
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
# Creation routine for |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
############################################################ |
30
|
|
|
|
|
|
|
sub new |
31
|
|
|
|
|
|
|
{ |
32
|
64
|
|
|
64
|
0
|
139
|
my $this = bless {}, shift; |
33
|
64
|
|
|
|
|
67
|
my ($node, $form) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# Can't create a CGI::Test::Form::Widget::Button object, only heirs. |
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
|
39
|
64
|
50
|
|
|
|
192
|
confess "%s is a deferred class", __PACKAGE__ |
40
|
|
|
|
|
|
|
if ref $this eq __PACKAGE__; |
41
|
|
|
|
|
|
|
|
42
|
64
|
|
|
|
|
207
|
$this->_common_init($form); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# |
45
|
|
|
|
|
|
|
# We don't keep any reference on the node. |
46
|
|
|
|
|
|
|
# Analyze the HTML tree to determine some parameters. |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
|
49
|
64
|
|
|
|
|
257
|
$this->_init_button($node); |
50
|
|
|
|
|
|
|
|
51
|
64
|
|
|
|
|
83
|
return $this; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
############################################################ |
55
|
|
|
|
|
|
|
# |
56
|
|
|
|
|
|
|
# %attr |
57
|
|
|
|
|
|
|
# %attr_button |
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
# Defines which HTML attributes we should look at within the node, and how |
60
|
|
|
|
|
|
|
# to translate that into class attributes. The %attr_button is specific |
61
|
|
|
|
|
|
|
# to the |
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
############################################################ |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my %attr = ('name' => 'name', |
66
|
|
|
|
|
|
|
'value' => 'value', |
67
|
|
|
|
|
|
|
'disabled' => 'is_disabled', |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my %attr_button = (%attr,); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
############################################################ |
73
|
|
|
|
|
|
|
# |
74
|
|
|
|
|
|
|
# ->_init |
75
|
|
|
|
|
|
|
# |
76
|
|
|
|
|
|
|
# Per-widget initialization routine, for . |
77
|
|
|
|
|
|
|
# Parse HTML node to determine our specific parameters. |
78
|
|
|
|
|
|
|
# |
79
|
|
|
|
|
|
|
############################################################ |
80
|
|
|
|
|
|
|
sub _init |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
0
|
|
0
|
my $this = shift; |
83
|
0
|
|
|
|
|
0
|
my ($node) = shift; |
84
|
0
|
|
|
|
|
0
|
$this->_parse_attr($node, \%attr); |
85
|
0
|
|
|
|
|
0
|
$this->{is_enhanced} = 0; |
86
|
0
|
|
|
|
|
0
|
$this->{is_pressed} = 0; |
87
|
0
|
|
|
|
|
0
|
return; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
############################################################ |
91
|
|
|
|
|
|
|
# |
92
|
|
|
|
|
|
|
# ->_init_button |
93
|
|
|
|
|
|
|
# |
94
|
|
|
|
|
|
|
# Per-widget initialization routine, for |
95
|
|
|
|
|
|
|
# Parse HTML node to determine our specific parameters. |
96
|
|
|
|
|
|
|
# |
97
|
|
|
|
|
|
|
############################################################ |
98
|
|
|
|
|
|
|
sub _init_button |
99
|
|
|
|
|
|
|
{ |
100
|
64
|
|
|
64
|
|
38
|
my $this = shift; |
101
|
64
|
|
|
|
|
65
|
my ($node) = shift; |
102
|
64
|
|
|
|
|
212
|
$this->_parse_attr($node, \%attr_button); |
103
|
64
|
|
|
|
|
80
|
$this->{is_enhanced} = 1; |
104
|
64
|
|
|
|
|
70
|
$this->{is_pressed} = 0; |
105
|
64
|
|
|
|
|
58
|
return; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
############################################################ |
109
|
|
|
|
|
|
|
# |
110
|
|
|
|
|
|
|
# ->_is_successful -- defined |
111
|
|
|
|
|
|
|
# |
112
|
|
|
|
|
|
|
# Is the enabled widget "successful", according to W3C's specs? |
113
|
|
|
|
|
|
|
# Any pressed button is. |
114
|
|
|
|
|
|
|
# |
115
|
|
|
|
|
|
|
############################################################ |
116
|
|
|
|
|
|
|
sub _is_successful |
117
|
|
|
|
|
|
|
{ |
118
|
76
|
|
|
76
|
|
68
|
my $this = shift; |
119
|
76
|
|
|
|
|
183
|
return $this->is_pressed(); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# |
123
|
|
|
|
|
|
|
# Attribute access |
124
|
|
|
|
|
|
|
# |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
############################################################ |
127
|
|
|
|
|
|
|
sub is_enhanced |
128
|
|
|
|
|
|
|
{ |
129
|
0
|
|
|
0
|
0
|
0
|
my $this = shift; |
130
|
0
|
|
|
|
|
0
|
return $this->{is_enhanced}; |
131
|
|
|
|
|
|
|
} # True for |
132
|
|
|
|
|
|
|
############################################################ |
133
|
|
|
|
|
|
|
sub is_pressed |
134
|
|
|
|
|
|
|
{ |
135
|
76
|
|
|
76
|
1
|
56
|
my $this = shift; |
136
|
76
|
|
|
|
|
144
|
return $this->{is_pressed}; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
############################################################ |
140
|
|
|
|
|
|
|
# |
141
|
|
|
|
|
|
|
# ->press |
142
|
|
|
|
|
|
|
# |
143
|
|
|
|
|
|
|
# Press button. |
144
|
|
|
|
|
|
|
# |
145
|
|
|
|
|
|
|
# Has immediate effect: |
146
|
|
|
|
|
|
|
# * If it's a reset button, all widgets are reset to their initial state. |
147
|
|
|
|
|
|
|
# * If it's a submit button, a GET/POST request is issued. |
148
|
|
|
|
|
|
|
# * By default, a warning is issued that the action is ignored. |
149
|
|
|
|
|
|
|
# |
150
|
|
|
|
|
|
|
# Returns undef if no submit is done, a new CGI::Test::Page otherwise. |
151
|
|
|
|
|
|
|
# |
152
|
|
|
|
|
|
|
############################################################ |
153
|
|
|
|
|
|
|
sub press |
154
|
|
|
|
|
|
|
{ |
155
|
0
|
|
|
0
|
1
|
0
|
my $this = shift; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# |
158
|
|
|
|
|
|
|
# Default action: do nothing |
159
|
|
|
|
|
|
|
# Routine is redefined in heirs when processing required. |
160
|
|
|
|
|
|
|
# |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
0
|
warn 'ignoring button press: name="%s", value="%s"', $this->name(), |
163
|
|
|
|
|
|
|
$this->value(); |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
0
|
return undef; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
############################################################ |
169
|
|
|
|
|
|
|
# |
170
|
|
|
|
|
|
|
# ->set_is_pressed |
171
|
|
|
|
|
|
|
# |
172
|
|
|
|
|
|
|
# Press or unpress button. |
173
|
|
|
|
|
|
|
# |
174
|
|
|
|
|
|
|
############################################################ |
175
|
|
|
|
|
|
|
sub set_is_pressed |
176
|
|
|
|
|
|
|
{ |
177
|
19
|
|
|
19
|
1
|
31
|
my $this = shift; |
178
|
19
|
|
|
|
|
30
|
my ($pressed) = @_; |
179
|
19
|
|
|
|
|
30
|
$this->{is_pressed} = $pressed; |
180
|
19
|
|
|
|
|
36
|
return; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
############################################################ |
184
|
|
|
|
|
|
|
# |
185
|
|
|
|
|
|
|
# ->reset_state -- redefined |
186
|
|
|
|
|
|
|
# |
187
|
|
|
|
|
|
|
# Called when a "Reset" button is pressed to restore the value the widget |
188
|
|
|
|
|
|
|
# had upon form entry. |
189
|
|
|
|
|
|
|
# |
190
|
|
|
|
|
|
|
############################################################ |
191
|
|
|
|
|
|
|
sub reset_state |
192
|
|
|
|
|
|
|
{ |
193
|
0
|
|
|
0
|
1
|
0
|
my $this = shift; |
194
|
0
|
|
|
|
|
0
|
$this->{is_pressed} = 0; |
195
|
0
|
|
|
|
|
0
|
return; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
############################################################ |
199
|
|
|
|
|
|
|
# |
200
|
|
|
|
|
|
|
# |
201
|
|
|
|
|
|
|
# Global widget predicates |
202
|
|
|
|
|
|
|
# |
203
|
|
|
|
|
|
|
############################################################ |
204
|
|
|
|
|
|
|
sub is_read_only |
205
|
|
|
|
|
|
|
{ |
206
|
0
|
|
|
0
|
1
|
0
|
return 1; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
# |
210
|
|
|
|
|
|
|
# Button predicates |
211
|
|
|
|
|
|
|
# |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
############################################################ |
214
|
|
|
|
|
|
|
sub is_reset |
215
|
|
|
|
|
|
|
{ |
216
|
0
|
|
|
0
|
1
|
0
|
return 0; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
############################################################ |
219
|
|
|
|
|
|
|
sub is_submit |
220
|
|
|
|
|
|
|
{ |
221
|
16
|
|
|
16
|
1
|
35
|
return 0; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
############################################################ |
224
|
|
|
|
|
|
|
sub is_plain |
225
|
|
|
|
|
|
|
{ |
226
|
0
|
|
|
0
|
1
|
|
return 0; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# |
230
|
|
|
|
|
|
|
# High-level classification predicates |
231
|
|
|
|
|
|
|
# |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
############################################################ |
234
|
|
|
|
|
|
|
sub is_button |
235
|
|
|
|
|
|
|
{ |
236
|
0
|
|
|
0
|
1
|
|
return 1; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
1; |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 NAME |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
CGI::Test::Form::Widget::Button - Abstract representation of a button |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 SYNOPSIS |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
# Inherits from CGI::Test::Form::Widget |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head1 DESCRIPTION |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
This class is the abstract representation of a button, i.e. a submit |
252
|
|
|
|
|
|
|
button, an image button, a reset button or a plain button. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Pressing a button is achieved by calling C on it, which returns a |
255
|
|
|
|
|
|
|
new page, as a C object, or C if pressing had |
256
|
|
|
|
|
|
|
no round-trip effect. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 INTERFACE |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
The interface is the same as the one described in L, |
261
|
|
|
|
|
|
|
with the following additions: |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head2 Attributes |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=over 4 |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item C |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
True when the button is pressed. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=back |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head2 Attribute Setting |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=over 4 |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=item C |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
Press the button, setting C to true. |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
If the button is a reset button (C is true), all widgets |
282
|
|
|
|
|
|
|
are reset to their initial state, and C is returned. |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
If the button is a submit button (C is true), then a GET/POST |
285
|
|
|
|
|
|
|
request is issued as appropriate and the reply is made available through |
286
|
|
|
|
|
|
|
a C object. |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
Otherwise, the button pressing is ignored, a warning is issued from the |
289
|
|
|
|
|
|
|
perspective of the caller, via C, and C is returned. |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=back |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=head2 Widget Classification Predicates |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
There is an additional set of predicates to distinguish between the various |
296
|
|
|
|
|
|
|
buttons: |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=over 4 |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=item C |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
Returns I for a plain button, i.e. a button that has no submit/reset |
303
|
|
|
|
|
|
|
effects. Usually, those buttons are linked to a script, but C |
304
|
|
|
|
|
|
|
does not support scripting yet. |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=item C |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
Returns I for reset buttons. |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=item C |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
Returns I for submit buttons, whether they are really shown as |
313
|
|
|
|
|
|
|
buttons or as images. A submit button will cause an HTTP request to be |
314
|
|
|
|
|
|
|
issued in response to its being pressed. |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=back |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=head2 Miscellaneous Features |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
Although documented, those features are more targetted for |
321
|
|
|
|
|
|
|
internal use... |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=over 4 |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=item C I |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
Change the pressed status of the button, to the value of I. |
328
|
|
|
|
|
|
|
It does not raise any other side effect, like submitting an HTTP request |
329
|
|
|
|
|
|
|
if the button is a submit button. |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
You should probably use the C convenience routine instead of calling |
332
|
|
|
|
|
|
|
this feature directly. |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
=back |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
=head1 AUTHORS |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
The original author is Raphael Manfredi. |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
Steven Hilton was long time maintainer of this module. |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
Current maintainer is Alexander Tokarev Ftokarev@cpan.orgE>. |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
=head1 SEE ALSO |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
CGI::Test::Form::Widget(3), |
347
|
|
|
|
|
|
|
CGI::Test::Form::Widget::Button::Image(3), |
348
|
|
|
|
|
|
|
CGI::Test::Form::Widget::Button::Plain(3), |
349
|
|
|
|
|
|
|
CGI::Test::Form::Widget::Button::Reset(3), |
350
|
|
|
|
|
|
|
CGI::Test::Form::Widget::Button::Submit(3). |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
=cut |
353
|
|
|
|
|
|
|
|