File Coverage

blib/lib/Syccess/Validator/IsNumber.pm
Criterion Covered Total %
statement 10 10 100.0
branch 2 2 100.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 16 17 94.1


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