| 1 | package CGI::Test::Form::Widget::Input; | ||
| 2 | 14 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 14 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 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 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 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 | ▶ | use base qw(CGI::Test::Form::Widget); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 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 | 76 | ▶ | { |
|
Subroutine
_is_successful: called CC=1 SCAR=0.0
| |||
| 32 | 76 | my $this = shift; | |
| 33 | 76 | 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 | 6 | ▶ | { |
|
Subroutine
prepend: called CC=1 SCAR=0.0
Pod
documented
| |||
| 53 | 6 | my $this = shift; | |
| 54 | 6 | my $prepend = shift; | |
| 55 | 6 | $this->set_value($prepend . $this->value()); | |
| 56 | } | ||
| 57 | |||
| 58 | sub append | ||
| 59 | 12 | ▶ | { |
|
Subroutine
append: called CC=1 SCAR=0.0
Pod
documented
| |||
| 60 | 12 | my $this = shift; | |
| 61 | 12 | my $append = shift; | |
| 62 | 12 | $this->set_value($this->value() . $append); | |
| 63 | } | ||
| 64 | |||
| 65 | sub replace | ||
| 66 | 12 | ▶ | { |
|
Subroutine
replace: called CC=1 SCAR=0.0
Pod
documented
| |||
| 67 | 12 | my $this = shift; | |
| 68 | 12 | my $new_value = shift; | |
| 69 | 12 | $this->set_value($new_value); | |
| 70 | } | ||
| 71 | |||
| 72 | sub clear | ||
| 73 | 0 | ▶ | { |
|
Subroutine
clear: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 74 | 0 | my $this = shift; | |
| 75 | 0 | $this->set_value(''); | |
| 76 | } | ||
| 77 | |||
| 78 | sub filter | ||
| 79 | 6 | ▶ | { |
|
Subroutine
filter: called CC=1 SCAR=0.0
Pod
documented
| |||
| 80 | 6 | my $this = shift; | |
| 81 | 6 | my $filter = shift; | |
| 82 | 6 | local $_ = $this->value(); | |
| 83 | 6 | &{$filter}; | |
| 84 | 6 | $this->set_value($_); | |
| 85 | } | ||
| 86 | |||
| 87 | # | ||
| 88 | # Attribute access | ||
| 89 | # | ||
| 90 | |||
| 91 | sub is_read_only | ||
| 92 | 36 | ▶ | { |
|
Subroutine
is_read_only: called CC=1 SCAR=0.0
Pod
documented
| |||
| 93 | 36 | my $this = shift; | |
| 94 | 36 | return $this->{is_read_only}; | |
| 95 | } | ||
| 96 | |||
| 97 | # | ||
| 98 | # High-level classification predicates | ||
| 99 | # | ||
| 100 | |||
| 101 | sub is_input | ||
| 102 | 0 | ▶ | { |
|
Subroutine
is_input: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 103 | 0 | return 1; | |
| 104 | } | ||
| 105 | |||
| 106 | # | ||
| 107 | # Predicates for the Input hierarchy | ||
| 108 | # | ||
| 109 | |||
| 110 | sub is_field | ||
| 111 | 0 | ▶ | { |
|
Subroutine
is_field: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 112 | 0 | return 0; | |
| 113 | } | ||
| 114 | |||
| 115 | sub is_area | ||
| 116 | 0 | ▶ | { |
|
Subroutine
is_area: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 117 | 0 | return 0; | |
| 118 | } | ||
| 119 | |||
| 120 | sub is_password | ||
| 121 | 0 | ▶ | { |
|
Subroutine
is_password: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 122 | 0 | return 0; | |
| 123 | } | ||
| 124 | |||
| 125 | sub is_file | ||
| 126 | 57 | ▶ | { |
|
Subroutine
is_file: called CC=1 SCAR=0.0
Pod
documented
| |||
| 127 | 57 | return 0; | |
| 128 | } | ||
| 129 | |||
| 130 | 14 | 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<prepend()>, C<append()>, C<replace()>, C<clear()> or even run existing text | ||
| 147 | through C<filter()>. | ||
| 148 | |||
| 149 | =head1 INTERFACE | ||
| 150 | |||
| 151 | The interface is the same as the one described in L<CGI::Test::Form::Widget>, | ||
| 152 | with the following additions: | ||
| 153 | |||
| 154 | =head2 Attribute Setting | ||
| 155 | |||
| 156 | There are a number of convenience routines that are wrappers on C<set_value()>: | ||
| 157 | |||
| 158 | =over 4 | ||
| 159 | |||
| 160 | =item C<append> I<string> | ||
| 161 | |||
| 162 | Appends the I<string> text to the existing text. | ||
| 163 | |||
| 164 | =item C<clear> | ||
| 165 | |||
| 166 | Clears existing text. | ||
| 167 | |||
| 168 | =item C<filter> I<filter_routine> | ||
| 169 | |||
| 170 | Runs existing text through the given I<filter_routine>. 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<this> by C<that> within the input text. | ||
| 177 | |||
| 178 | =item C<prepend> I<string> | ||
| 179 | |||
| 180 | Prepends the I<string> text to the existing text. | ||
| 181 | |||
| 182 | =item C<replace> I<string> | ||
| 183 | |||
| 184 | Replaces the existing text with I<string>. | ||
| 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<is_area> | ||
| 196 | |||
| 197 | Returns I<true> for a text area. | ||
| 198 | |||
| 199 | =item C<is_field> | ||
| 200 | |||
| 201 | Returns I<true> for a pure text field. | ||
| 202 | |||
| 203 | =item C<is_file> | ||
| 204 | |||
| 205 | Returns I<true> for a file upload field (text field with browser support for | ||
| 206 | file selection). | ||
| 207 | |||
| 208 | =item C<is_password> | ||
| 209 | |||
| 210 | Returns I<true> 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 F<E<lt>tokarev@cpan.orgE<gt>>. | ||
| 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 | |||