FormValidator/Validator/Enum.pm

filter: Statementstmt 93.3% 28 / 30 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 86.9% 40 / 46 CC 3 SCAR 3.2
CC
3
Cov
88%
validate
2.1
_is_enum
2.1
BEGIN
1.0
CRAP 1.4
« FormValidator/Validator/EmailDns.pm ↑ Summary FormValidator/Validator/RequiredWith.pm »
1 package Dancer2::Plugin::FormValidator::Validator::Enum;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 with 'Dancer2::Plugin::FormValidator::Role::Validator';
12  
13 sub message {
14 return {
15 1 ▶ en => '%s contains invalid value',
Subroutine message: called CC=1 SCAR=0.0
Pod undocumented
16 ru => '%s содержит неверное значение',
17 de => '%s enthält einen ungültigen Wert',
18 };
19 }
20  
21 sub validate {
22 7 ▶ my ($self, $field, $input, @enum) = @_;
Subroutine validate: called CC=2 SCAR=7.6
Pod undocumented
23  
24 7 ▶ if ($self->_field_defined_and_non_empty($field, $input)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_field_defined_and_non_empty($field, $input)) 7 0 7
25 7 return $self->_is_enum($input->{$field}, @enum);
26 }
27  
28 0 return 1;
29 }
30  
31 sub _is_enum {
32 7 ▶ my ($self, $value1, @enum) = @_;
Subroutine _is_enum: called CC=2 SCAR=7.4
33  
34 7 ▶ if (defined $value1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value1) 7 0 7
35 7 ▶ return any {$_ eq $value1} @enum;
Subroutine __ANON__: called CC=1 SCAR=0.0
36  
37 }
38  
39 0 return 0;
40 }
41  
42 5 1;
« FormValidator/Validator/EmailDns.pm ↑ Summary FormValidator/Validator/RequiredWith.pm »