lib/HTML/FormFu/Constraint/Equal.pm

filter: Statementstmt 96.4% 55 / 57 Branchbran 78.9% 30 / 38 Conditioncond 72.2% 13 / 18 MC/DCmcdc 54.5% 6 / 11 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 1 totaltotal 83.5% 112 / 134 CC 28 SCAR 23.1
CC
28
Cov
87%
process
15.2
_values_eq
10.9
_arrays_eq
4.1
CRAP 10.1
« lib/HTML/FormFu/UploadParam.pm ↑ Summary lib/HTML/FormFu/Role/CustomRoles.pm »
1 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Constraint::Equal;
4 11 $HTML::FormFu::Constraint::Equal::VERSION = '2.09';
5 # ABSTRACT: Multi-field Equality Constraint
6  
7 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 extends 'HTML::FormFu::Constraint';
9  
10 11 with 'HTML::FormFu::Role::Constraint::Others';
11  
12 11 ▶use HTML::FormFu::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 DEBUG_CONSTRAINTS
14 debug
15 11 );
16 11 ▶use List::Util 1.33 qw( all );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 11 our $EMPTY_STR = q{};
19  
20 35 ▶sub process {
Subroutine process: called CC=15 SCAR=27.2
Pod undocumented
21 35 my ( $self, $params ) = @_;
22  
23 # check when condition
24 35 ▶ return if !$self->_process_when($params);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_process_when($params) 0 35 35
25  
26 35 my $others = $self->others;
27 35 ▶ return if !defined $others;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $others 0 35 35
28  
29 35 my $value = $self->get_nested_hash_value( $params, $self->nested_name );
30  
31 35 ▶ DEBUG_CONSTRAINTS && debug( VALUE => $value );
Branch: 1 branch
BranchTrueFalseTotal
DEBUG_CONSTRAINTS() and debug("VALUE", $value) 0 35 35
32  
33 35 ▶ my @names = ref $others ? @{$others} : ($others);
Branch: 1 branch
BranchTrueFalseTotal
ref $others ? : 31 4 35
34 35 my @failed;
35 my %values;
36  
37 35 for my $name (@names) {
38  
39 66 my $other_value = $self->get_nested_hash_value( $params, $name );
40  
41 66 ▶ DEBUG_CONSTRAINTS && debug( NAME => $name, VALUE => $value );
Branch: 1 branch
BranchTrueFalseTotal
DEBUG_CONSTRAINTS() and debug("NAME", $name, "VALUE", $value) 0 66 66
42  
43 66 my $ok = _values_eq( $value, $other_value );
44  
45 66 ▶ if ( $self->not ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->not) { } 28 38 66
elsif (not $ok) { } 11 27 38
46 28 ▶ if ( $value eq $EMPTY_STR ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value eq $HTML::FormFu::Constraint::Equal::EMPTY_STR) { } 12 16 28
elsif ($ok) { } 6 10 16
47  
48 # no error if both values are empty and not(1) is set
49 }
50 elsif ($ok) {
51 6 push @failed, $name;
52 }
53 }
54 elsif ( !$ok ) {
55 11 push @failed, $name;
56 }
57  
58 66 $values{$name} = $other_value;
59 }
60  
61 # special case for $self->not()
62 # no errors if all values are empty
63 35 ▶ if ( $self->not
Branch: 1 branch
BranchTrueFalseTotal
if ($self->not and $value eq $HTML::FormFu::Constraint::Equal::EMPTY_STR and &all(sub { not defined $_ or $_ eq $EMPTY_STR; } , values %values)) 2 33 35
Condition100%6/6
$self->not and $value eq $HTML::FormFu::Constraint::Equal::EMPTY_STR and &all(sub { not defined $_ or $_ eq $EMPTY_STR; } , values %values)
!ll&&!rl&&r
2942
$self->not and $value eq $HTML::FormFu::Constraint::Equal::EMPTY_STR
!ll&&!rl&&r
2096
MC/DC100%3/3
$self->not and $value eq $HTML::FormFu::Constraint::Equal::EMPTY_STR and &all(sub { not defined $_ or $_ eq $EMPTY_STR; } , values %values)
$self->not $value eq $HTML::FormFu::Constraint::Equal::EMPTY_STR &all(sub { not defined $_ or $_ eq $EMPTY_STR; } , values %values)
Truth table100%4/4
A and B and C
A= $self->notB= $value eq $HTML::FormFu::Constraint::Equal::EMPTY_STRC= &all(sub { not defined $_ or $_ eq $EMPTY_STR; } , values %values)
ABCresult
0XX0
10X0
1100
1111
64 && $value eq $EMPTY_STR
65 10 ▶ && all { !defined || $_ eq $EMPTY_STR } values %values )
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
not defined $_ or $_ eq $HTML::FormFu::Constraint::Equal::EMPTY_STR 0 10 10
66 {
67 2 return;
68 }
69  
70 33 ▶ return $self->mk_errors(
Branch: 1 branch
BranchTrueFalseTotal
@failed ? : 14 19 33
71 { pass => @failed ? 0 : 1,
72 failed => \@failed,
73 names => [ $self->nested_name, @names ],
74 } );
75 }
76  
77 71 ▶sub _values_eq {
Subroutine _values_eq: called CC=10 SCAR=23.9
78 71 my ( $v1, $v2 ) = @_;
79  
80 # the params should be coming from a CGI.pm compatible query object,
81 # so the value is either a string or an arrayref of strings
82  
83 71 ▶ return 1 if !defined $v1 && !defined $v2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v1 or defined $v2 0 71 71
Condition33%1/3
defined $v1 or defined $v2
l!l&&r!l&&!r
7100
MC/DC0%0/2
defined $v1 or defined $v2
defined $v1 defined $v2
Truth table33%1/3
A or B
A= defined $v1B= defined $v2
ABresult
1X1
011
000
84  
85 71 ▶ return if !defined $v1 || !defined $v2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v1 and defined $v2 2 69 71
Condition66%2/3
defined $v1 and defined $v2
!ll&&!rl&&r
0269
MC/DC50%1/2
defined $v1 and defined $v2
defined $v1 defined $v2
Truth table66%2/3
A and B
A= defined $v1B= defined $v2
ABresult
0X0
100
111
86  
87 69 ▶ if ( !ref $v1 && !ref $v2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $v1 || ref $v2) { } 59 10 69
elsif (ref $v1 eq 'ARRAY' and ref $v2 eq 'ARRAY') { } 8 2 10
Condition66%2/3
ref $v1 || ref $v2
l!l&&r!l&&!r
10059
MC/DC50%1/2
ref $v1 || ref $v2
ref $v1 ref $v2
Truth table66%2/3
A || B
A= ref $v1B= ref $v2
ABresult
1X1
011
000
88 59 ▶ return 1 if $v1 eq $v2;
Branch: 1 branch
BranchTrueFalseTotal
if $v1 eq $v2 36 23 59
89 }
90 ▶ elsif ( ( ref $v1 eq 'ARRAY' ) && ( ref $v2 eq 'ARRAY' ) ) {
Condition66%2/3
ref $v1 eq "ARRAY" and ref $v2 eq "ARRAY"
!ll&&!rl&&r
028
MC/DC50%1/2
ref $v1 eq "ARRAY" and ref $v2 eq "ARRAY"
ref $v1 eq "ARRAY" ref $v2 eq "ARRAY"
Truth table66%2/3
A and B
A= ref $v1 eq "ARRAY"B= ref $v2 eq "ARRAY"
ABresult
0X0
100
111
91 8 return _arrays_eq( $v1, $v2 );
92 }
93  
94 25 return;
95 }
96  
97 8 ▶sub _arrays_eq {
Subroutine _arrays_eq: called CC=4 SCAR=14.0
98 8 my @a1 = sort @{ $_[0] };
99 8 my @a2 = sort @{ $_[1] };
100  
101 8 ▶ return if scalar @a1 != scalar @a2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @a1 != scalar @a2 0 8 8
102  
103 8 for my $i ( 0 .. $#a1 ) {
104 15 ▶ return if $a1[$i] ne $a2[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $a1[$i] ne $a2[$i] 0 15 15
105 }
106  
107 8 return 1;
108 }
109  
110 0 ▶sub _localize_args {
Subroutine _localize_args: not called CC=1 SCAR=6.9
111 0 my ($self) = @_;
112  
113 0 return $self->parent->label;
114 }
115  
116 11 __PACKAGE__->meta->make_immutable;
117  
118 11 1;
119  
120 __END__
« lib/HTML/FormFu/UploadParam.pm ↑ Summary lib/HTML/FormFu/Role/CustomRoles.pm »