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   3254 use warnings;
  5         12  
  5         146  
4 5     5   26  
  5         11  
  5         127  
5             use Moo;
6 5     5   25 use utf8;
  5         10  
  5         34  
7 5     5   1719 use List::Util qw(any);
  5         12  
  5         56  
8 5     5   166 use namespace::clean;
  5         12  
  5         503  
9 5     5   35  
  5         12  
  5         40  
10             with 'Dancer2::Plugin::FormValidator::Role::Validator';
11              
12             return {
13             en => '%s contains invalid value',
14             ru => '%s содержит неверное значение',
15 1     1 0 1575 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 34 return $self->_is_enum($input->{$field}, @enum);
23             }
24 7 50       41  
25 7         32 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   24  
33             }
34 7 50       24  
35 7     13   63 return 0;
  13         68  
36             }
37              
38             1;