lib/HTML/FormFu/Constraint/AllOrNone.pm

filter: Statementstmt 100% 38 / 38 Branchbran 85.0% 17 / 20 Conditioncond 75.0% 9 / 12 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 86.9% 73 / 84 CC 16 SCAR 24.1
CC
16
Cov
91%
process
14.3
constrain_value
3.0
BEGIN
1.0
CRAP 11.1
« lib/HTML/FormFu/OutputProcessor/Indent.pm ↑ Summary lib/HTML/FormFu/Constraint.pm »
1 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Constraint::AllOrNone;
4 10 $HTML::FormFu::Constraint::AllOrNone::VERSION = '2.09';
5 # ABSTRACT: Multi-field All or None Constraint
6  
7 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 extends 'HTML::FormFu::Constraint';
9  
10 10 with 'HTML::FormFu::Role::Constraint::Others';
11  
12 18 ▶sub process {
Subroutine process: called CC=14 SCAR=26.6
Pod undocumented
13 18 my ( $self, $params ) = @_;
14  
15 # check when condition
16 18 ▶ return if !$self->_process_when($params);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_process_when($params) 0 18 18
17  
18 18 my $others = $self->others;
19 18 ▶ return if !defined $others;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $others 0 18 18
20  
21 18 my @names = ( $self->nested_name );
22 18 ▶ push @names, ref $others ? @{$others} : $others;
Branch: 1 branch
BranchTrueFalseTotal
ref $others ? : 11 7 18
23  
24 18 my @failed;
25  
26 18 for my $name (@names) {
27 54 my $value = $self->get_nested_hash_value( $params, $name );
28  
29 54 my $seen = 0;
30 54 ▶ if ( ref $value eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 6 48 54
31 6 my @errors = eval { $self->constrain_values( $value, $params ) };
32  
33 6 ▶ if ( !@errors && !$@ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@errors or $@) 6 0 6
Condition33%1/3
@errors or $@
l!l&&r!l&&!r
006
MC/DC0%0/2
@errors or $@
@errors $@
Truth table33%1/3
A or B
A= @errorsB= $@
ABresult
1X1
011
000
34 6 $seen = 1;
35 }
36 }
37 else {
38 48 my $ok = eval { $self->constrain_value($value) };
39  
40 48 ▶ if ( $ok && !$@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok and not $@) 25 23 48
Condition66%2/3
$ok and not $@
!ll&&!rl&&r
23025
MC/DC50%1/2
$ok and not $@
$ok not $@
Truth table66%2/3
A and not(B)
A= $okB= not $@
ABresult
0X0
100
111
41 25 $seen = 1;
42 }
43 }
44  
45 54 ▶ if ( !$seen ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen) 23 31 54
46 23 push @failed, $name;
47 }
48 }
49  
50 18 ▶ my $pass = @failed && scalar @failed != scalar @names ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
@failed && scalar @failed != scalar @names ? : 7 11 18
Condition100%3/3
@failed and scalar @failed != scalar @names
!ll&&!rl&&r
657
MC/DC100%2/2
@failed and scalar @failed != scalar @names
@failed scalar @failed != scalar @names
Truth table100%3/3
A and B
A= @failedB= scalar @failed != scalar @names
ABresult
0X0
100
111
51  
52 18 ▶ return $self->mk_errors(
Branch: 1 branch
BranchTrueFalseTotal
$pass ? : 11 7 18
53 { pass => $pass,
54 failed => $pass ? [] : \@failed,
55 names => \@names,
56 } );
57 }
58  
59 60 ▶sub constrain_value {
Subroutine constrain_value: called CC=3 SCAR=11.0
Pod undocumented
60 60 my ( $self, $value ) = @_;
61  
62 60 ▶ return 0 if !defined $value || $value eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or $value eq "" 23 37 60
Condition100%3/3
not defined $value or $value eq ""
l!l&&r!l&&!r
17637
MC/DC100%2/2
not defined $value or $value eq ""
not defined $value $value eq ""
Truth table100%3/3
not(A) or B
A= not defined $valueB= $value eq ""
ABresult
1X1
011
000
63  
64 37 return 1;
65 }
66  
67 10 __PACKAGE__->meta->make_immutable;
68  
69 10 1;
70  
71 __END__
« lib/HTML/FormFu/OutputProcessor/Indent.pm ↑ Summary lib/HTML/FormFu/Constraint.pm »