| 1 | package CGI::Test::Form::Widget::Input::Text_Field; | ||||||||||||||||||||||||||||
| 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: Text_Field.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 text field. | ||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 14 | ▶ | use base qw(CGI::Test::Form::Widget::Input); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||
| 24 | # %attr | ||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||
| 26 | # Defines which HTML attributes we should look at within the node, and how | ||||||||||||||||||||||||||||
| 27 | # to translate that into class attributes. | ||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 14 | my %attr = ('name' => 'name', | |||||||||||||||||||||||||||
| 31 | 'value' => 'value', | ||||||||||||||||||||||||||||
| 32 | 'size' => 'size', | ||||||||||||||||||||||||||||
| 33 | 'maxlength' => 'max_length', | ||||||||||||||||||||||||||||
| 34 | 'disabled' => 'is_disabled', | ||||||||||||||||||||||||||||
| 35 | 'readonly' => 'is_read_only', | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # | ||||||||||||||||||||||||||||
| 39 | # ->_init | ||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||
| 41 | # Per-widget initialization routine. | ||||||||||||||||||||||||||||
| 42 | # Parse HTML node to determine our specific parameters. | ||||||||||||||||||||||||||||
| 43 | # | ||||||||||||||||||||||||||||
| 44 | sub _init | ||||||||||||||||||||||||||||
| 45 | 48 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 48 | my $this = shift; | |||||||||||||||||||||||||||
| 47 | 48 | my ($node) = shift; | |||||||||||||||||||||||||||
| 48 | 48 | $this->_parse_attr($node, \%attr); | |||||||||||||||||||||||||||
| 49 | 48 | return; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # | ||||||||||||||||||||||||||||
| 53 | # Attribute access | ||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | sub size | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 0 | $_[ 0 ]->{size}; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | sub max_length | ||||||||||||||||||||||||||||
| 62 | 30 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
max_length: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 30 | $_[ 0 ]->{max_length}; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | sub gui_type | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
gui_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 0 | "text field" | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # | ||||||||||||||||||||||||||||
| 72 | # Redefined predicates | ||||||||||||||||||||||||||||
| 73 | # | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | sub is_field | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
is_field: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 0 | 1 | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # | ||||||||||||||||||||||||||||
| 81 | # Redefined routines | ||||||||||||||||||||||||||||
| 82 | # | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # | ||||||||||||||||||||||||||||
| 85 | # ->set_value -- redefined | ||||||||||||||||||||||||||||
| 86 | # | ||||||||||||||||||||||||||||
| 87 | # Ensure text is not larger than the maximum field length, by truncating | ||||||||||||||||||||||||||||
| 88 | # from the right. | ||||||||||||||||||||||||||||
| 89 | # | ||||||||||||||||||||||||||||
| 90 | sub set_value | ||||||||||||||||||||||||||||
| 91 | 30 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_value: called CC=6 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 30 | my $this = shift; | |||||||||||||||||||||||||||
| 93 | 30 | my ($value) = @_; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 30 | my $maxlen = $this->max_length; | |||||||||||||||||||||||||||
| 96 | 30 | ▶ | $maxlen = 1 if defined $maxlen && $maxlen < 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $maxlen and $maxlen < 1
MC/DC0%0/2
defined $maxlen and $maxlen < 1
defined $maxlen
$maxlen < 1
Truth table33%1/3
A and B
A= defined $maxlenB= $maxlen < 1
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 30 | ▶ | if (defined $maxlen && length($value) > $maxlen) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $maxlen and length $value > $maxlen
MC/DC0%0/2
defined $maxlen and length $value > $maxlen
defined $maxlen
length $value > $maxlen
Truth table33%1/3
A and B
A= defined $maxlenB= length $value > $maxlen
| |||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | carp "truncating text to %d byte%s for %s '%s'", $maxlen, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | $maxlen == 1 ? "" : "s", $this->gui_type, $this->name; | ||||||||||||||||||||||||||||
| 102 | 0 | substr($value, $maxlen) = ''; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 30 | $this->SUPER::set_value($value); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 14 | 1; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head1 NAME | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | CGI::Test::Form::Widget::Input::Text_Field - A text field | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | # Inherits from CGI::Test::Form::Widget::Input | ||||||||||||||||||||||||||||
| 117 | # $form is a CGI::Test::Form | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | my $desc = $form->input_by_name("description"); | ||||||||||||||||||||||||||||
| 120 | $desc->replace("small and beautiful"); | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | This class models a single-line text field, where users can type text. | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head1 INTERFACE | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | The interface is the same as the one described in | ||||||||||||||||||||||||||||
| 129 | L<CGI::Test::Form::Widget::Input>, with the following additional attributes: | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =over 4 | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =item C<max_length> | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | The maximum allowed text length within the field. If not defined, it means | ||||||||||||||||||||||||||||
| 136 | the length is not limited. | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =item C<size> | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | The size of the displayed text field, in characters. The text held within | ||||||||||||||||||||||||||||
| 141 | the field can be much larger than that, however. | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =back | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | The original author is Raphael Manfredi. | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | Steven Hilton was long time maintainer of this module. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | Current maintainer is Alexander Tokarev F<E<lt>tokarev@cpan.orgE<gt>>. | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | CGI::Test::Form::Widget::Input(3). | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||