File Coverage

blib/lib/Dancer2/Plugin/FormValidator/Validator/Enum.pm
Criterion Covered Total %
statement 26 28 92.8
branch 2 4 50.0
condition n/a
subroutine 10 10 100.0
pod 0 2 0.0
total 38 44 86.3


line stmt bran cond sub pod time code
1              
2             use strict;
3 5     5   2564 use warnings;
  5         12  
  5         126  
4 5     5   25  
  5         16  
  5         149  
5             use Moo;
6 5     5   39 use utf8;
  5         15  
  5         25  
7 5     5   1474 use List::Util qw(any);
  5         14  
  5         45  
8 5     5   159 use namespace::clean;
  5         10  
  5         392  
9 5     5   28  
  5         17  
  5         26  
10             with 'Dancer2::Plugin::FormValidator::Role::Validator';
11              
12             return {
13             en => '%s contains invalid value',
14             ru => '%s содержит неверное значение',
15 1     1 0 1282 de => '%s enthält einen ungültigen Wert',
16             };
17             }
18              
19             my ($self, $field, $input, @enum) = @_;
20              
21             if ($self->_field_defined_and_non_empty($field, $input)) {
22 7     7 0 29 return $self->_is_enum($input->{$field}, @enum);
23             }
24 7 50       25  
25 7         26 return 1;
26             }
27              
28 0         0 my ($self, $value1, @enum) = @_;
29              
30             if (defined $value1) {
31             return any {$_ eq $value1} @enum;
32 7     7   22  
33             }
34 7 50       20  
35 7     13   42 return 0;
  13         58  
36             }
37              
38             1;