lib/HTML/FormFu/Validator.pm

filter: Statementstmt 93.1% 41 / 44 Branchbran 58.3% 7 / 12 Conditioncond 62.5% 5 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 4 totaltotal 76.8% 63 / 82 CC 11 SCAR 14.2
CC
11
Cov
83%
return_error
6.6
process
6.1
validate_values
3.0
CRAP 4.1
« lib/HTML/FormFu/Role/Element/FieldMethods.pm ↑ Summary lib/HTML/FormFu/Filter/CopyValue.pm »
1 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Validator;
4 7 $HTML::FormFu::Validator::VERSION = '2.09';
5 # ABSTRACT: Validator Base Class
6  
7 7 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 extends 'HTML::FormFu::Processor';
9  
10 7 ▶use HTML::FormFu::Exception::Validator;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Scalar::Util qw( reftype blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 ▶sub process {
Subroutine process: called CC=6 SCAR=18.0
Pod undocumented
15 8 my ( $self, $params ) = @_;
16  
17 8 my $value = $self->get_nested_hash_value( $params, $self->nested_name );
18  
19 8 my @errors;
20  
21 8 ▶ if ( ( reftype($value) || '' ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((builtin::reftype($value) || '') eq 'ARRAY') { } 2 6 8
Condition100%2/2
builtin::reftype($value) || ''
l!l
26
MC/DC100%1/1
builtin::reftype($value) || ''
builtin::reftype($value)
Truth table100%2/2
A
A= builtin::reftype($value)
Aresult
11
00
22 2 push @errors, eval { $self->validate_values( $value, $params ) };
23  
24 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
25 0 push @errors, $self->return_error($@);
26 }
27 }
28 else {
29 6 my $ok = eval { $self->validate_value( $value, $params ) };
30  
31 6 ▶ if ( $@ or !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $ok) 1 5 6
Condition66%2/3
$@ or not $ok
l!l&&r!l&&!r
105
MC/DC50%1/2
$@ or not $ok
$@ not $ok
Truth table66%2/3
A or not(B)
A= $@B= not $ok
ABresult
1X1
011
000
32 1 push @errors, $self->return_error($@);
33 }
34 }
35  
36 8 return @errors;
37 }
38  
39 2 ▶sub validate_values {
Subroutine validate_values: called CC=3 SCAR=11.0
Pod undocumented
40 2 my ( $self, $values, $params ) = @_;
41  
42 2 my @errors;
43  
44 2 for my $value (@$values) {
45 6 my $ok = eval { $self->validate_value( $value, $params ) };
46  
47 6 ▶ push @errors, $self->return_error($@) if !$ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 6 6
48 }
49  
50 2 return @errors;
51 }
52  
53 0 ▶sub validate_value {
Subroutine validate_value: not called CC=1 SCAR=6.9
Pod undocumented
54 0 croak "validate() should be overridden";
55 }
56  
57 1 ▶sub return_error {
Subroutine return_error: called CC=4 SCAR=18.9
Pod undocumented
58 1 my ( $self, $err ) = @_;
59  
60 1 ▶ if ( !blessed $err || !$err->isa('HTML::FormFu::Exception::Validator') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($err) and $err->isa("HTML::FormFu::Exception::Validator")) 0 1 1
Condition33%1/3
builtin::blessed($err) and $err->isa("HTML::FormFu::Exception::Validator")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($err) and $err->isa("HTML::FormFu::Exception::Validator")
builtin::blessed($err) $err->isa("HTML::FormFu::Exception::Validator")
Truth table33%1/3
A and B
A= builtin::blessed($err)B= $err->isa("HTML::FormFu::Exception::Validator")
ABresult
0X0
100
111
61 0 ▶ $err = HTML::FormFu::Exception::Validator->new(
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 0 0 0
62 $err ? { message => $err } : () );
63 }
64  
65 1 return $err;
66 }
67  
68 7 __PACKAGE__->meta->make_immutable;
69  
70 7 1;
71  
72 __END__
« lib/HTML/FormFu/Role/Element/FieldMethods.pm ↑ Summary lib/HTML/FormFu/Filter/CopyValue.pm »