| 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
Condition100%6/6
not defined $h1->{$k} and exists $h2->{$k} and not defined $h2->{$k}
not defined $h1->{$k} and exists $h2->{$k}
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # Empty | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | elsif (ref $h1->{$k} eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | ▶ | if (ref $h2->{$k} eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | my $d = left_diff($h1->{$k}, $h2->{$k}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | ▶ | $rh->{$k} = $d if (%$d); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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}
defined $h1->{$k} && defined $h2->{$k}
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||