line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Rose::HTML::Form::Field::Integer; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
110879
|
use strict; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
191
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
502
|
use Rose::HTML::Object::Errors qw(:number); |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
56
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
35
|
use base 'Rose::HTML::Form::Field::Numeric'; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
2962
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.624'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->add_required_html_attrs({ |
12
|
|
|
|
|
|
|
step => 1, |
13
|
|
|
|
|
|
|
}); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub validate |
17
|
|
|
|
|
|
|
{ |
18
|
29
|
|
|
29
|
1
|
65
|
my($self) = shift; |
19
|
|
|
|
|
|
|
|
20
|
29
|
|
|
|
|
106
|
my $ok = $self->SUPER::validate(@_); |
21
|
29
|
100
|
|
|
|
96
|
return $ok unless($ok); |
22
|
|
|
|
|
|
|
|
23
|
22
|
|
|
|
|
65
|
my $value = $self->internal_value; |
24
|
22
|
100
|
66
|
|
|
121
|
return 1 unless(defined $value && length $value); |
25
|
|
|
|
|
|
|
|
26
|
21
|
0
|
|
0
|
|
86
|
my $name = sub { $self->error_label || $self->name }; |
|
0
|
|
|
|
|
0
|
|
27
|
|
|
|
|
|
|
|
28
|
21
|
100
|
|
|
|
106
|
unless($value =~ /^-?\d+$/) |
29
|
|
|
|
|
|
|
{ |
30
|
1
|
|
|
|
|
5
|
$self->add_error_id(NUM_INVALID_INTEGER, { label => $name }); |
31
|
1
|
|
|
|
|
6
|
return 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
20
|
|
|
|
|
132
|
return 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my %Error_Map = |
38
|
|
|
|
|
|
|
( |
39
|
|
|
|
|
|
|
NUM_INVALID_NUMBER() => NUM_INVALID_INTEGER, |
40
|
|
|
|
|
|
|
NUM_INVALID_NUMBER_POSITIVE() => NUM_INVALID_INTEGER_POSITIVE, |
41
|
|
|
|
|
|
|
NUM_NOT_POSITIVE_NUMBER() => NUM_NOT_POSITIVE_INTEGER, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub add_error_id |
45
|
|
|
|
|
|
|
{ |
46
|
8
|
|
|
8
|
0
|
16
|
my($self) = shift; |
47
|
8
|
|
|
|
|
15
|
my $error_id = shift; |
48
|
8
|
|
66
|
|
|
30
|
my $new_error_id = $Error_Map{$error_id} || $error_id; |
49
|
8
|
|
|
|
|
32
|
return $self->SUPER::add_error_id($new_error_id, @_); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub error_id |
53
|
|
|
|
|
|
|
{ |
54
|
22
|
|
|
22
|
1
|
94
|
my($self) = shift; |
55
|
|
|
|
|
|
|
|
56
|
22
|
100
|
|
|
|
70
|
if(@_) |
57
|
|
|
|
|
|
|
{ |
58
|
18
|
|
|
|
|
32
|
my $error_id = shift; |
59
|
18
|
|
33
|
|
|
97
|
my $new_error_id = $Error_Map{$error_id} || $error_id; |
60
|
18
|
|
|
|
|
93
|
return $self->SUPER::error_id($new_error_id, @_); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else |
63
|
|
|
|
|
|
|
{ |
64
|
4
|
|
|
|
|
19
|
my $error_id = $self->SUPER::error_id; |
65
|
4
|
|
33
|
|
|
19
|
my $new_error_id = $Error_Map{$error_id} || $error_id; |
66
|
4
|
|
|
|
|
21
|
return $new_error_id; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
if(__PACKAGE__->localizer->auto_load_messages) |
71
|
|
|
|
|
|
|
{ |
72
|
|
|
|
|
|
|
__PACKAGE__->localizer->load_all_messages; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
5
|
|
|
5
|
|
52
|
use utf8; # The __DATA__ section contains UTF-8 text |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
27
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__DATA__ |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
[% LOCALE en %] |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
NUM_INVALID_INTEGER = "[label] must be an integer." |
84
|
|
|
|
|
|
|
NUM_INVALID_INTEGER_POSITIVE = "[label] must be a positive integer." |
85
|
|
|
|
|
|
|
NUM_NOT_POSITIVE_INTEGER = "[label] must be a positive integer." |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
[% LOCALE de %] |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
NUM_INVALID_INTEGER = "[label] muß eine Ganzzahl sein." |
90
|
|
|
|
|
|
|
NUM_INVALID_INTEGER_POSITIVE = "[label] muß eine positive Ganzzahl sein." |
91
|
|
|
|
|
|
|
NUM_NOT_POSITIVE_INTEGER = "[label] muß eine positive Ganzzahl sein." |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
[% LOCALE fr %] |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
NUM_INVALID_INTEGER = "[label] doit être un entier." |
96
|
|
|
|
|
|
|
NUM_INVALID_INTEGER_POSITIVE = "[label] doit être un entier positif." |
97
|
|
|
|
|
|
|
NUM_NOT_POSITIVE_INTEGER = "[label] doit être un entier positif." |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
[% LOCALE bg %] |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
NUM_INVALID_INTEGER = "Полето '[label]' трябва да бъде цяло число." |
102
|
|
|
|
|
|
|
NUM_INVALID_INTEGER_POSITIVE = "Полето '[label]' трябва да бъде цяло положително число." |
103
|
|
|
|
|
|
|
NUM_NOT_POSITIVE_INTEGER = "Полето '[label]' трябва да бъде цяло положително число." |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 NAME |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Rose::HTML::Form::Field::Integer - Text field that only accepts integer values. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SYNOPSIS |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$field = |
114
|
|
|
|
|
|
|
Rose::HTML::Form::Field::Integer->new( |
115
|
|
|
|
|
|
|
label => 'Count', |
116
|
|
|
|
|
|
|
name => 'count', |
117
|
|
|
|
|
|
|
maxlength => 6); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$field->input_value('abc'); |
120
|
|
|
|
|
|
|
$field->validate; # false |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$field->input_value(123); |
123
|
|
|
|
|
|
|
$field->validate; # true |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Set minimum and maximum values |
126
|
|
|
|
|
|
|
$field->min(2); |
127
|
|
|
|
|
|
|
$field->max(100); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$field->input_value(123); |
130
|
|
|
|
|
|
|
$field->validate; # false |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$field->input_value(1); |
133
|
|
|
|
|
|
|
$field->validate; # false |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
$field->input_value(5); |
136
|
|
|
|
|
|
|
$field->validate; # true |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
print $field->html; |
139
|
|
|
|
|
|
|
... |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 DESCRIPTION |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
L<Rose::HTML::Form::Field::Integer> is a subclass of L<Rose::HTML::Form::Field::Numeric> that only accepts integer values. It overrides the L<validate()|Rose::HTML::Form::Field/validate> method of its parent class, returning true if the L<internal_value()|Rose::HTML::Form::Field/internal_value> is a valid integer, or setting an error message and returning false otherwise. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Use the L<min|/min> and :<max|/max> attributes to control whether the range of valid values. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over 4 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item B<max [INT]> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Get or set the maximum acceptable value. If the field's L<internal_value()|Rose::HTML::Form::Field/internal_value> is B<greater than> this value, then the L<validate()|Rose::HTML::Form::Field/validate> method will return false. If undefined, then no limit on the maximum value is enforced. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item B<min [INT]> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Get or set the minimum acceptable value. If the field's L<internal_value()|Rose::HTML::Form::Field/internal_value> is B<less than> this value, then the L<validate()|Rose::HTML::Form::Field/validate> method will return false. If undefined, then no limit on the minimum value is enforced. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item B<negative [BOOL]> |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
If BOOL is true or omitted, sets L<max|/max> to C<0>. If BOOL is false, sets L<max|/max> to undef. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item B<positive [BOOL]> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
If BOOL is true or omitted, sets L<min|/min> to C<0>. If BOOL is false, sets L<min|/min> to undef. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item B<step [ NUM | any ]> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Get or set the granularity that is expected (and required). The value may be a number or the keyword C<any>. The default value is C<1>. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=back |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 AUTHOR |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
John C. Siracusa (siracusa@gmail.com) |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 LICENSE |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |