File Coverage

blib/lib/Dancer2/Plugin/FormValidator/Validator/Max.pm
Criterion Covered Total %
statement 24 26 92.3
branch 2 4 50.0
condition n/a
subroutine 8 8 100.0
pod 0 2 0.0
total 34 40 85.0


line stmt bran cond sub pod time code
1              
2             use strict;
3 2     2   1192 use warnings;
  2         5  
  2         51  
4 2     2   8  
  2         4  
  2         38  
5             use Moo;
6 2     2   9 use utf8;
  2         3  
  2         9  
7 2     2   575 use Scalar::Util qw(looks_like_number);
  2         4  
  2         8  
8 2     2   47 use namespace::clean;
  2         5  
  2         93  
9 2     2   11  
  2         4  
  2         11  
10             with 'Dancer2::Plugin::FormValidator::Role::Validator';
11              
12             return {
13             en => '%s must be no more than %d',
14             ru => '%s должно быть не больше %d',
15 1     1 0 1225 de => 'muss kleiner als %d sein',
16             };
17             }
18              
19             my ($self, $field, $input, $max) = @_;
20              
21             if ($self->_field_defined_and_non_empty($field, $input)) {
22 2     2 0 6 my $maybe_num = $input->{$field};
23              
24 2 50       7 if (looks_like_number($maybe_num)) {
25 2         5 return $maybe_num <= $max;
26             }
27 2 50       8 else {
28 2         11 return 0;
29             }
30             }
31 0            
32             return 1;
33             }
34              
35 0           1;