FormValidator/Validator.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 83.3% 10 / 12 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 94.5% 69 / 73 CC 10 SCAR 18.4
CC
10
Cov
95%
validate
10.0
BEGIN
1.0
BEGIN
1.0
CRAP 6.3
↑ Summary FormValidator/Factory/Messages.pm »
1 package Dancer2::Plugin::FormValidator::Validator;
2  
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 17 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 17 ▶use Types::Standard qw(InstanceOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 17 has config => (
12 is => 'ro',
13 isa => InstanceOf['Dancer2::Plugin::FormValidator::Config'],
14 required => 1,
15 );
16  
17 17 has registry => (
18 is => 'ro',
19 isa => InstanceOf['Dancer2::Plugin::FormValidator::Registry'],
20 required => 1,
21 );
22  
23 # Apply validators to each fields.
24 # Collect valid and invalid fields.
25 sub validate {
26 19 ▶ my ($self, $profile, $input) = @_;
Subroutine validate: called CC=10 SCAR=23.1
Pod undocumented
27  
28 19 ▶ if (ref $profile ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $profile ne "HASH") 0 19 19
29 0 Carp::croak("Profile should be a HashRef\n")
30 }
31  
32 19 my $success = 0;
33 19 my %profile = %{ $profile };
34 19 my $is_valid;
35 my @valid;
36 19 my @invalid;
37  
38 19 for my $field (keys %profile) {
39 41 $is_valid = 1;
40 41 my @validators = @{ $profile{$field} };
41  
42 41 for my $validator_declaration (@validators) {
43 65 ▶ if (my ($name, $params) = $self->_split_validator_declaration($validator_declaration)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $self->_split_validator_declaration($validator_declaration)) 65 0 65
44 65 my $validator = $self->registry->get($name);
45  
46 65 ▶ if (not $validator->validate($field, $input, split(',', $params))) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($validator->validate($field, $input, split(/,/, $params, 0))) 23 42 65
47 23 push @invalid, [ $field, $name, $params ];
48 23 $is_valid = 0;
49 }
50  
51 65 ▶ if (!$is_valid && $validator->stop_on_fail) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_valid and $validator->stop_on_fail) 9 56 65
Condition100%3/3
not $is_valid and $validator->stop_on_fail
!ll&&!rl&&r
42149
MC/DC100%2/2
not $is_valid and $validator->stop_on_fail
not $is_valid $validator->stop_on_fail
Truth table100%3/3
not(A) and B
A= not $is_validB= $validator->stop_on_fail
ABresult
0X0
100
111
52 9 last;
53 }
54 }
55 }
56  
57 41 ▶ if ($is_valid == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_valid == 1) 18 23 41
58 18 push @valid, $field;
59 }
60 }
61  
62 19 ▶ if (not @invalid) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@invalid) 5 14 19
63 5 $success = 1;
64 }
65  
66 19 return ($success, \@valid, \@invalid)
67 }
68  
69 # Because validator signatures could be validator:params, we need to split it.
70 sub _split_validator_declaration {
71 65 ▶ return ($_[1] =~ /([^:]+):?(.*)/);
Subroutine _split_validator_declaration: called CC=1 SCAR=0.0
72 }
73  
74 17 1;
↑ Summary FormValidator/Factory/Messages.pm »