line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormHandler::Field::Text; |
2
|
|
|
|
|
|
|
# ABSTRACT: text field |
3
|
|
|
|
|
|
|
$HTML::FormHandler::Field::Text::VERSION = '0.40067'; |
4
|
135
|
|
|
135
|
|
143051
|
use Moose; |
|
135
|
|
|
|
|
1486045
|
|
|
135
|
|
|
|
|
914
|
|
5
|
|
|
|
|
|
|
extends 'HTML::FormHandler::Field'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has 'size' => ( isa => 'Int|Undef', is => 'rw', default => '0' ); |
8
|
|
|
|
|
|
|
has 'maxlength' => ( isa => 'Int|Undef', is => 'rw' ); |
9
|
|
|
|
|
|
|
has 'maxlength_message' => ( isa => 'Str', is => 'rw', |
10
|
|
|
|
|
|
|
default => 'Field should not exceed [quant,_1,character]. You entered [_2]', |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
has 'minlength' => ( isa => 'Int|Undef', is => 'rw', default => '0' ); |
13
|
|
|
|
|
|
|
has 'minlength_message' => ( isa => 'Str', is => 'rw', |
14
|
|
|
|
|
|
|
default => 'Field must be at least [quant,_1,character]. You entered [_2]' ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has '+widget' => ( default => 'Text' ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $class_messages = { |
19
|
|
|
|
|
|
|
'text_maxlength' => 'Field should not exceed [quant,_1,character]. You entered [_2]', |
20
|
|
|
|
|
|
|
'text_minlength' => 'Field must be at least [quant,_1,character]. You entered [_2]', |
21
|
|
|
|
|
|
|
'multiple_values_disallowed' => 'Field must contain a single value', |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub get_class_messages { |
25
|
92
|
|
|
92
|
0
|
471
|
my $self = shift; |
26
|
|
|
|
|
|
|
my $messages = { |
27
|
92
|
|
|
|
|
114
|
%{ $self->next::method }, |
|
92
|
|
|
|
|
254
|
|
28
|
|
|
|
|
|
|
%$class_messages, |
29
|
|
|
|
|
|
|
}; |
30
|
92
|
50
|
|
|
|
2703
|
$messages->{text_minlength} = $self->minlength_message |
31
|
|
|
|
|
|
|
if $self->minlength_message; |
32
|
92
|
50
|
|
|
|
2449
|
$messages->{text_maxlength} = $self->maxlength_message |
33
|
|
|
|
|
|
|
if $self->maxlength_message; |
34
|
92
|
|
|
|
|
848
|
return $messages; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _inner_validate_field { |
38
|
564
|
|
|
564
|
|
638
|
my $self = shift; |
39
|
|
|
|
|
|
|
# Check for multiple values |
40
|
564
|
100
|
|
|
|
1483
|
if ( ref $self->value eq 'ARRAY' ) { |
41
|
2
|
|
|
|
|
16
|
return $self->add_error( |
42
|
|
|
|
|
|
|
$self->get_message('multiple_values_disallowed'), |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub validate { |
48
|
541
|
|
|
541
|
1
|
711
|
my $field = shift; |
49
|
|
|
|
|
|
|
|
50
|
541
|
50
|
|
|
|
1847
|
return unless $field->next::method; |
51
|
541
|
|
|
|
|
1199
|
my $value = $field->value; |
52
|
|
|
|
|
|
|
# Check for max length |
53
|
541
|
100
|
|
|
|
13637
|
if ( my $maxlength = $field->maxlength ) { |
54
|
11
|
100
|
|
|
|
35
|
return $field->add_error( $field->get_message('text_maxlength'), |
55
|
|
|
|
|
|
|
$maxlength, length $value, $field->loc_label ) |
56
|
|
|
|
|
|
|
if length $value > $maxlength; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Check for min length |
60
|
538
|
100
|
|
|
|
13592
|
if ( my $minlength = $field->minlength ) { |
61
|
12
|
100
|
|
|
|
45
|
return $field->add_error( |
62
|
|
|
|
|
|
|
$field->get_message('text_minlength'), |
63
|
|
|
|
|
|
|
$minlength, length $value, $field->loc_label ) |
64
|
|
|
|
|
|
|
if length $value < $minlength; |
65
|
|
|
|
|
|
|
} |
66
|
535
|
|
|
|
|
974
|
return 1; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
71
|
135
|
|
|
135
|
|
645701
|
use namespace::autoclean; |
|
135
|
|
|
|
|
30399
|
|
|
135
|
|
|
|
|
1172
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=pod |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=encoding UTF-8 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 NAME |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
HTML::FormHandler::Field::Text - text field |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 VERSION |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
version 0.40067 |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 DESCRIPTION |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This is a simple text entry field. Widget type is 'text'. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 METHODS |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 size [integer] |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This is used in constructing HTML. It determines the size of the input field. |
97
|
|
|
|
|
|
|
The 'maxlength' field should be used as a constraint on the size of the field, |
98
|
|
|
|
|
|
|
not this attribute. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 minlength [integer] |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This integer value, if non-zero, defines the minimum number of characters that must |
103
|
|
|
|
|
|
|
be entered. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 maxlength [integer] |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
A constraint on the maximum length of the text. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 error messages |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Set error messages (text_minlength, text_maxlength): |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
has_field 'my_text' => ( type => 'Text', messages => |
114
|
|
|
|
|
|
|
{ 'text_minlength' => 'Field is too short', |
115
|
|
|
|
|
|
|
'text_maxlength' => 'Field is too long', |
116
|
|
|
|
|
|
|
} ); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
FormHandler Contributors - see HTML::FormHandler |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Gerda Shank. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
127
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |