line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormHandler::Field::Integer; |
2
|
|
|
|
|
|
|
# ABSTRACT: validate an integer value |
3
|
|
|
|
|
|
|
$HTML::FormHandler::Field::Integer::VERSION = '0.40067'; |
4
|
14
|
|
|
14
|
|
9865
|
use HTML::FormHandler::Moose; |
|
14
|
|
|
|
|
17
|
|
|
14
|
|
|
|
|
119
|
|
5
|
|
|
|
|
|
|
extends 'HTML::FormHandler::Field::Text'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has '+size' => ( default => 8 ); |
8
|
|
|
|
|
|
|
has '+html5_type_attr' => ( default => 'number' ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $class_messages = { |
11
|
|
|
|
|
|
|
'integer_needed' => 'Value must be an integer', |
12
|
|
|
|
|
|
|
}; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub get_class_messages { |
15
|
23
|
|
|
23
|
0
|
115
|
my $self = shift; |
16
|
|
|
|
|
|
|
return { |
17
|
23
|
|
|
|
|
23
|
%{ $self->next::method }, |
|
23
|
|
|
|
|
46
|
|
18
|
|
|
|
|
|
|
%$class_messages, |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
apply( |
24
|
|
|
|
|
|
|
[ |
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
transform => sub { |
27
|
|
|
|
|
|
|
my $value = shift; |
28
|
|
|
|
|
|
|
$value =~ s/^\+//; |
29
|
|
|
|
|
|
|
return $value; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
{ |
33
|
|
|
|
|
|
|
check => sub { $_[0] =~ /^-?[0-9]+$/ }, |
34
|
|
|
|
|
|
|
message => sub { |
35
|
|
|
|
|
|
|
my ( $value, $field ) = @_; |
36
|
|
|
|
|
|
|
return $field->get_message('integer_needed'); |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
] |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
44
|
14
|
|
|
14
|
|
25434
|
use namespace::autoclean; |
|
14
|
|
|
|
|
25
|
|
|
14
|
|
|
|
|
243
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=pod |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=encoding UTF-8 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
HTML::FormHandler::Field::Integer - validate an integer value |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 VERSION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
version 0.40067 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 DESCRIPTION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
This accepts a positive or negative integer. Negative integers may |
64
|
|
|
|
|
|
|
be prefixed with a dash. By default a max of eight digits are accepted. |
65
|
|
|
|
|
|
|
Widget type is 'text'. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
If form has 'is_html5' flag active it will render <input type="number" ... /> |
68
|
|
|
|
|
|
|
instead of type="text" |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The 'range_start' and 'range_end' attributes may be used to limit valid numbers. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 AUTHOR |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
FormHandler Contributors - see HTML::FormHandler |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Gerda Shank. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
81
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |