lib/HTML/FormFu/Constraint/DependOn.pm

filter: Statementstmt 76.6% 36 / 47 Branchbran 50.0% 13 / 26 Conditioncond 33.3% 2 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 2 totaltotal 62.6% 57 / 91 CC 17 SCAR 32.3
CC
17
Cov
65%
process
36.1
constrain_value
3.0
_localize_args
2.0
CRAP 25.3
« lib/HTML/FormFu/Role/NestedHashUtils.pm ↑ Summary lib/HTML/FormFu/Deploy.pm »
1 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Constraint::DependOn;
4 8 $HTML::FormFu::Constraint::DependOn::VERSION = '2.09';
5 # ABSTRACT: Multi-field Dependency Constraint
6  
7 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 extends 'HTML::FormFu::Constraint';
9  
10 8 with 'HTML::FormFu::Role::Constraint::Others';
11  
12 8 ▶use HTML::FormFu::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 DEBUG_CONSTRAINTS
14 debug
15 8 );
16  
17 10 ▶sub process {
Subroutine process: called CC=15 SCAR=35.9
Pod undocumented
18 10 my ( $self, $params ) = @_;
19  
20 # check when condition
21 10 ▶ if ( !$self->_process_when($params) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_process_when($params)) 0 10 10
22 0 ▶ DEBUG_CONSTRAINTS && debug('fail when() check - skipping constraint');
Branch: 1 branch
BranchTrueFalseTotal
DEBUG_CONSTRAINTS() and debug("fail when() check - skipping constraint") 0 0 0
23 0 return;
24 }
25  
26 10 my $others = $self->others;
27 10 ▶ if ( !defined $others ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $others) 0 10 10
28 0 ▶ DEBUG_CONSTRAINTS && debug('no others() - skipping constraint');
Branch: 1 branch
BranchTrueFalseTotal
DEBUG_CONSTRAINTS() and debug("no others() - skipping constraint") 0 0 0
29 0 return;
30 }
31  
32 10 ▶ my @names = ref $others ? @{$others} : ($others);
Branch: 1 branch
BranchTrueFalseTotal
ref $others ? : 6 4 10
33 10 my @failed;
34  
35 10 my $value = $self->get_nested_hash_value( $params, $self->nested_name );
36  
37 10 ▶ if ( !$self->constrain_value($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->constrain_value($value)) 0 10 10
38 0 ▶ DEBUG_CONSTRAINTS && debug('no value - skipping constraint');
Branch: 1 branch
BranchTrueFalseTotal
DEBUG_CONSTRAINTS() and debug("no value - skipping constraint") 0 0 0
39 0 return;
40 }
41  
42 10 for my $name (@names) {
43 16 my $value = $self->get_nested_hash_value( $params, $name );
44  
45 16 my $ok = 0;
46  
47 16 ▶ if ( ref $value eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 16 16
48 0 my @err = eval { $self->constrain_values( $value, $params ) };
49 0 ▶ $ok = 1 if !@err && !$@;
Branch: 1 branch
BranchTrueFalseTotal
unless @err or $@ 0 0 0
Condition0%0/3
@err or $@
l!l&&r!l&&!r
000
MC/DC0%0/2
@err or $@
@err $@
Truth table0%0/3
A or B
A= @errB= $@
ABresult
1X1
011
000
50 }
51 else {
52 16 $ok = eval { $self->constrain_value($value) };
53 16 ▶ $ok = 0 if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 16 16
54 }
55  
56 16 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 5 11 16
57 5 push @failed, $name;
58 }
59 }
60  
61 10 ▶ return $self->mk_errors(
Branch: 1 branch
BranchTrueFalseTotal
@failed ? : 5 5 10
62 { pass => @failed ? 0 : 1,
63 failed => \@failed,
64 names => [ $self->nested_name, @names ],
65 } );
66 }
67  
68 26 ▶sub constrain_value {
Subroutine constrain_value: called CC=3 SCAR=11.0
Pod undocumented
69 26 my ( $self, $value ) = @_;
70  
71 26 ▶ return 0 if !defined $value || $value eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or $value eq "" 5 21 26
Condition66%2/3
not defined $value or $value eq ""
l!l&&r!l&&!r
0521
MC/DC50%1/2
not defined $value or $value eq ""
not defined $value $value eq ""
Truth table66%2/3
not(A) or B
A= not defined $valueB= $value eq ""
ABresult
1X1
011
000
72  
73 21 return 1;
74 }
75  
76 0 ▶sub _localize_args {
Subroutine _localize_args: not called CC=1 SCAR=6.9
77 0 my ($self) = @_;
78  
79 0 return $self->parent->label;
80 }
81  
82 8 __PACKAGE__->meta->make_immutable;
83  
84 8 1;
85  
86 __END__
« lib/HTML/FormFu/Role/NestedHashUtils.pm ↑ Summary lib/HTML/FormFu/Deploy.pm »