blib/lib/Hash/Diff.pm

filter: Statementstmt 97.0% 33 / 34 Branchbran 90.0% 9 / 10 Conditioncond 100% 12 / 12 MC/DCmcdc 100% 6 / 6 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 97.2% 70 / 72 CC 11 SCAR 19.6
CC
11
Cov
96%
left_diff
11.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.1
↑ Summary
1 package Hash::Diff;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Hash::Merge;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 $VERSION = 0.010;
12 4 @EXPORT_OK = qw( diff left_diff );
13  
14 24 ▶sub left_diff {
Subroutine left_diff: called CC=11 SCAR=24.0
Pod documented
15 24 my ($h1, $h2) = @_;
16 24 my $rh = {}; # return_hash
17
18 24 foreach my $k (keys %{$h1}) {
19 31 ▶ if (not defined $h1->{$k} and exists $h2->{$k} and not defined $h2->{$k}) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $h1->{$k} and exists $h2->{$k} and not defined $h2->{$k}) { } 2 29 31
elsif (ref $h1->{$k} eq 'HASH') { } 6 23 29
elsif (not defined $h1->{$k} && defined $h2->{$k} or $h1->{$k} ne $h2->{$k}) { } 13 10 23
Condition100%6/6
not defined $h1->{$k} and exists $h2->{$k} and not defined $h2->{$k}
!ll&&!rl&&r
2812
not defined $h1->{$k} and exists $h2->{$k}
!ll&&!rl&&r
2533
MC/DC100%3/3
not defined $h1->{$k} and exists $h2->{$k} and not defined $h2->{$k}
not defined $h1->{$k} exists $h2->{$k} not defined $h2->{$k}
Truth table100%4/4
not(A) and B and not(C)
A= not defined $h1->{$k}B= exists $h2->{$k}C= not defined $h2->{$k}
ABCresult
0XX0
10X0
1100
1111
20 # Empty
21 }
22 elsif (ref $h1->{$k} eq 'HASH') {
23 6 ▶ if (ref $h2->{$k} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $h2->{$k} eq 'HASH') { } 6 0 6
24 6 my $d = left_diff($h1->{$k}, $h2->{$k});
25 6 ▶ $rh->{$k} = $d if (%$d);
Branch: 1 branch
BranchTrueFalseTotal
if %$d 2 4 6
26 }
27 else {
28 0 $rh->{$k} = $h1->{$k}
29 }
30 }
31 ▶ elsif ((!defined $h1->{$k})||(!defined $h2->{$k})||($h1->{$k} ne $h2->{$k})) {
Condition100%6/6
not defined $h1->{$k} && defined $h2->{$k} or $h1->{$k} ne $h2->{$k}
l!l&&r!l&&!r
11210
defined $h1->{$k} && defined $h2->{$k}
!ll&&!rl&&r
4712
MC/DC100%3/3
not defined $h1->{$k} && defined $h2->{$k} or $h1->{$k} ne $h2->{$k}
defined $h1->{$k} defined $h2->{$k} $h1->{$k} ne $h2->{$k}
Truth table100%4/4
not(A && B) or C
A= defined $h1->{$k}B= defined $h2->{$k}C= $h1->{$k} ne $h2->{$k}
ABCresult
0XX1
10X1
1111
1100
32 13 $rh->{$k} = $h1->{$k}
33 }
34 }
35
36 24 return $rh;
37  
38 }
39  
40 9 ▶sub diff {
Subroutine diff: called CC=1 SCAR=0.0
Pod documented
41 9 my ($h1, $h2) = @_;
42  
43 9 return Hash::Merge::merge(left_diff($h1,$h2),left_diff($h2,$h1));
44 }
45  
46  
47 4 1;
48  
49 __END__
↑ Summary