line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Test::Form::Widget::Input; |
2
|
14
|
|
|
14
|
|
59
|
use strict; |
|
14
|
|
|
|
|
14
|
|
|
14
|
|
|
|
|
338
|
|
3
|
14
|
|
|
14
|
|
39
|
use warnings; |
|
14
|
|
|
|
|
11
|
|
|
14
|
|
|
|
|
286
|
|
4
|
|
|
|
|
|
|
################################################################## |
5
|
|
|
|
|
|
|
# $Id: Input.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
|
|
36
|
use Carp; |
|
14
|
|
|
|
|
14
|
|
|
14
|
|
|
|
|
582
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
# This class models a FORM input field. |
19
|
|
|
|
|
|
|
# It factorizes the interface of our heirs: Text_Area and Text_Field |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
|
22
|
14
|
|
|
14
|
|
37
|
use base qw(CGI::Test::Form::Widget); |
|
14
|
|
|
|
|
14
|
|
|
14
|
|
|
|
|
3730
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
# ->_is_successful -- defined |
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
# Is the enabled widget "successful", according to W3C's specs? |
28
|
|
|
|
|
|
|
# Any input is. |
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
sub _is_successful |
31
|
|
|
|
|
|
|
{ |
32
|
76
|
|
|
76
|
|
61
|
my $this = shift; |
33
|
76
|
|
|
|
|
100
|
return 1; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# Editing shortcuts |
38
|
|
|
|
|
|
|
# |
39
|
|
|
|
|
|
|
# The set_value() routine from the Widget class is protected against |
40
|
|
|
|
|
|
|
# disabled and read-only fields, so don't duplicate checks within these |
41
|
|
|
|
|
|
|
# shortcut routines. |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
# All are obvious, excepted filter perhaps, which runs a filtering subroutine |
44
|
|
|
|
|
|
|
# on the field's value, preset in $_: |
45
|
|
|
|
|
|
|
# |
46
|
|
|
|
|
|
|
# $i->filter(sub { s/this/that/ }); |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
# In the traditional Perl way... |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub prepend |
52
|
|
|
|
|
|
|
{ |
53
|
6
|
|
|
6
|
1
|
40
|
my $this = shift; |
54
|
6
|
|
|
|
|
10
|
my $prepend = shift; |
55
|
6
|
|
|
|
|
16
|
$this->set_value($prepend . $this->value()); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub append |
59
|
|
|
|
|
|
|
{ |
60
|
12
|
|
|
12
|
1
|
70
|
my $this = shift; |
61
|
12
|
|
|
|
|
14
|
my $append = shift; |
62
|
12
|
|
|
|
|
26
|
$this->set_value($this->value() . $append); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub replace |
66
|
|
|
|
|
|
|
{ |
67
|
12
|
|
|
12
|
1
|
140
|
my $this = shift; |
68
|
12
|
|
|
|
|
14
|
my $new_value = shift; |
69
|
12
|
|
|
|
|
72
|
$this->set_value($new_value); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub clear |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
0
|
1
|
0
|
my $this = shift; |
75
|
0
|
|
|
|
|
0
|
$this->set_value(''); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub filter |
79
|
|
|
|
|
|
|
{ |
80
|
6
|
|
|
6
|
1
|
58
|
my $this = shift; |
81
|
6
|
|
|
|
|
10
|
my $filter = shift; |
82
|
6
|
|
|
|
|
40
|
local $_ = $this->value(); |
83
|
6
|
|
|
|
|
6
|
&{$filter}; |
|
6
|
|
|
|
|
20
|
|
84
|
6
|
|
|
|
|
50
|
$this->set_value($_); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# |
88
|
|
|
|
|
|
|
# Attribute access |
89
|
|
|
|
|
|
|
# |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub is_read_only |
92
|
|
|
|
|
|
|
{ |
93
|
36
|
|
|
36
|
1
|
30
|
my $this = shift; |
94
|
36
|
|
|
|
|
68
|
return $this->{is_read_only}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# |
98
|
|
|
|
|
|
|
# High-level classification predicates |
99
|
|
|
|
|
|
|
# |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub is_input |
102
|
|
|
|
|
|
|
{ |
103
|
0
|
|
|
0
|
1
|
0
|
return 1; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# |
107
|
|
|
|
|
|
|
# Predicates for the Input hierarchy |
108
|
|
|
|
|
|
|
# |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub is_field |
111
|
|
|
|
|
|
|
{ |
112
|
0
|
|
|
0
|
1
|
0
|
return 0; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub is_area |
116
|
|
|
|
|
|
|
{ |
117
|
0
|
|
|
0
|
1
|
0
|
return 0; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub is_password |
121
|
|
|
|
|
|
|
{ |
122
|
0
|
|
|
0
|
1
|
0
|
return 0; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub is_file |
126
|
|
|
|
|
|
|
{ |
127
|
57
|
|
|
57
|
1
|
101
|
return 0; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 NAME |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
CGI::Test::Form::Widget::Input - Abstract representation of an input field |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 SYNOPSIS |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# Inherits from CGI::Test::Form::Widget |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 DESCRIPTION |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This class is the abstract representation of a text input field, i.e. a |
143
|
|
|
|
|
|
|
text field, a password field, a file upload field or a text area. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
To simulate user input in those fields, there are a set of routines to |
146
|
|
|
|
|
|
|
C, C, C, C or even run existing text |
147
|
|
|
|
|
|
|
through C. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 INTERFACE |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
The interface is the same as the one described in L, |
152
|
|
|
|
|
|
|
with the following additions: |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 Attribute Setting |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
There are a number of convenience routines that are wrappers on C: |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over 4 |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item C I |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Appends the I text to the existing text. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item C |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Clears existing text. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item C I |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Runs existing text through the given I. The C<$_> variable |
171
|
|
|
|
|
|
|
is set to the whole text value, and is made available to the filter. |
172
|
|
|
|
|
|
|
Hence you may write: |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
$input->filter(sub { s/this/that/g }); |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
to replace all instances of C by C within the input text. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item C I |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Prepends the I text to the existing text. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item C I |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Replaces the existing text with I. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=back |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 Widget Classification Predicates |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
There are additional predicates to distinguish between the various |
191
|
|
|
|
|
|
|
input fields: |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=over 4 |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item C |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Returns I for a text area. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item C |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Returns I for a pure text field. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item C |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Returns I for a file upload field (text field with browser support for |
206
|
|
|
|
|
|
|
file selection). |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item C |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Returns I for a password field (text field with input masked by GUI). |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=back |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 AUTHORS |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
The original author is Raphael Manfredi. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Steven Hilton was long time maintainer of this module. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Current maintainer is Alexander Tokarev Ftokarev@cpan.orgE>. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head1 SEE ALSO |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
CGI::Test::Form::Widget(3), |
225
|
|
|
|
|
|
|
CGI::Test::Form::Widget::Input::File(3), |
226
|
|
|
|
|
|
|
CGI::Test::Form::Widget::Input::Password(3), |
227
|
|
|
|
|
|
|
CGI::Test::Form::Widget::Input::Text_Area(3), |
228
|
|
|
|
|
|
|
CGI::Test::Form::Widget::Input::Text_Field(3). |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
231
|
|
|
|
|
|
|
|