File Coverage

blib/lib/Dancer2/Plugin/FormValidator/Validator/Integer.pm
Criterion Covered Total %
statement 25 26 96.1
branch 3 4 75.0
condition n/a
subroutine 8 8 100.0
pod 0 2 0.0
total 36 40 90.0


line stmt bran cond sub pod time code
1              
2             use strict;
3 2     2   1120 use warnings;
  2         3  
  2         45  
4 2     2   9  
  2         8  
  2         39  
5             use Moo;
6 2     2   12 use utf8;
  2         4  
  2         8  
7 2     2   473 use Scalar::Util qw(looks_like_number);
  2         10  
  2         10  
8 2     2   65 use namespace::clean;
  2         4  
  2         114  
9 2     2   10  
  2         3  
  2         15  
10             with 'Dancer2::Plugin::FormValidator::Role::Validator';
11              
12             return {
13             en => '%s must be an integer',
14             ru => '%s должно содержать целочисленное значение',
15 1     1 0 1594 de => '%s muss eine ganze Zahl sein',
16             };
17             }
18              
19             my ($self, $field, $input) = @_;
20              
21             if ($self->_field_defined_and_non_empty($field, $input)) {
22 3     3 0 7 my $maybe_int = $input->{$field};
23              
24 3 50       12 if (looks_like_number($maybe_int)) {
25 3         7 return int($maybe_int) == $maybe_int;
26             }
27 3 100       12 else {
28 2         13 return 0;
29             }
30             }
31 1         6  
32             return 1;
33             }
34              
35 0           1;