| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Syccess::Validator::IsNumber; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
2
|
|
|
2
|
|
2704
|
$Syccess::Validator::IsNumber::AUTHORITY = 'cpan:GETTY'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
# ABSTRACT: A validator to check if value is a number |
|
6
|
|
|
|
|
|
|
$Syccess::Validator::IsNumber::VERSION = '0.103'; |
|
7
|
2
|
|
|
2
|
|
12
|
use Moo; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
10
|
|
|
8
|
2
|
|
|
2
|
|
462
|
use Scalar::Util qw( looks_like_number ); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
248
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with qw( |
|
11
|
|
|
|
|
|
|
Syccess::ValidatorSimple |
|
12
|
|
|
|
|
|
|
); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has message => ( |
|
15
|
|
|
|
|
|
|
is => 'lazy', |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _build_message { |
|
19
|
1
|
|
|
1
|
|
464
|
return '%s must be a number.'; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub validator { |
|
23
|
3
|
|
|
3
|
0
|
5
|
my ( $self, $value ) = @_; |
|
24
|
3
|
100
|
|
|
|
37
|
return $self->message unless looks_like_number($value); |
|
25
|
1
|
|
|
|
|
4
|
return; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
1; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
__END__ |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=pod |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 NAME |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Syccess::Validator::IsNumber - A validator to check if value is a number |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 VERSION |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
version 0.103 |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Syccess->new( |
|
45
|
|
|
|
|
|
|
fields => [ |
|
46
|
|
|
|
|
|
|
foo => [ is_number => 1 ], |
|
47
|
|
|
|
|
|
|
bar => [ is_number => { message => 'This is not cool!' } ], |
|
48
|
|
|
|
|
|
|
], |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This simple validator only checks if the given value is a number (using |
|
54
|
|
|
|
|
|
|
I<looks_like_number> of L<Scalar::Util>). The parameter given will not be used, |
|
55
|
|
|
|
|
|
|
but as usual you can override the error message by given B<message>. |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 message |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
This contains the error message or the format for the error message |
|
62
|
|
|
|
|
|
|
generation. See L<Syccess::Error/validator_message>. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=encoding utf8 |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 SUPPORT |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
IRC |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Join #sycontent on irc.perl.org. Highlight Getty for fast reaction :). |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Repository |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
http://github.com/SyContent/Syccess |
|
75
|
|
|
|
|
|
|
Pull request and additional contributors are welcome |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Issue Tracker |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
http://github.com/SyContent/Syccess/issues |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 AUTHOR |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Torsten Raudssus <torsten@raudss.us> |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Torsten Raudssus. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
92
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |