blib/lib/Blessed/Merge.pm

filter: Statementstmt 100% 84 / 84 Branchbran 100% 54 / 54 Conditioncond 100% 18 / 18 MC/DCmcdc 100% 10 / 10 Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 100% 180 / 180 SCAR 36.9
CC
40
Cov
100%
_unique_merge
14.0
merge
11.0
_merge
10.0
CRAP 40.0
↑ Summary
1 package Blessed::Merge;
2  
3 5 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 our $VERSION = '1.00';
6 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Scalar::Util qw/reftype/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Combine::Keys qw/combine_keys/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub new {
14 6 ▶ my ($pkg, $args) = (shift, reftype $_[0] || "" eq 'HASH' ? $_[0] : {@_});
Subroutine new: called CC=7 SCAR=19.5
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($_[0]) || !1 ? : 2 4 6
Condition100%2/2
builtin::reftype($_[0]) or
l!l
24
MC/DC100%1/1
builtin::reftype($_[0]) or
builtin::reftype($_[0])
Truth table100%2/2
A
A= builtin::reftype($_[0])
Aresult
11
00
15 6 my $self = bless $args, $pkg;
16 6 ▶ $self->{$_} = $self->{$_} // 1 foreach (qw/same blessed/);
Condition100%2/2
$self->{$_} // 1
l!l
39
MC/DC100%1/1
$self->{$_} // 1
$self->{$_}
Truth table100%2/2
A
A= $self->{$_}
Aresult
11
00
17 6 ▶ $self->{$_} = $self->{$_} // 0 foreach(qw/unique_array unique_hash/);
Condition100%2/2
$self->{$_} // 0
l!l
39
MC/DC100%1/1
$self->{$_} // 0
$self->{$_}
Truth table100%2/2
A
A= $self->{$_}
Aresult
11
00
18 6 $self->{itterator} = 1;
19 6 return $self;
20 }
21  
22 sub merge {
23 11 ▶ my ($self, $base_bless, $new) = (shift, ref $_[0], shift);
Subroutine merge: called CC=11 SCAR=24.0
Pod documented
24 11 tie my %isa, 'Tie::IxHash';
25 11 $isa{$base_bless} = $new;
26 map {
27 11 ▶ if ( $self->{same} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'same'}) { } 9 8 17
28 9 ▶ croak 'Attempting to merge two different *packages*' unless $base_bless eq ref $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $base_bless eq ref $_ 1 8 9
29 } else {
30 8 my $r = ref $_;
31 8 ▶ $isa{$r} = $_ unless $r =~ m/HASH|ARRAY|SCALAR/;
Branch: 1 branch
BranchTrueFalseTotal
unless $r =~ /HASH|ARRAY|SCALAR/ 7 1 8
32 }
33 16 $new = $self->_merge($new, $_);
34 } @_;
35 10 for my $f (keys %isa) {
36 16 ▶ my $check = $isa{$f} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $check = $isa{$f} or next 1 15 16
37 15 for (keys %isa) {
38 33 ▶ $_ eq $f and next;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq $f and next 15 18 33
39 18 ▶ delete $isa{$_} if $check->isa($_);
Branch: 1 branch
BranchTrueFalseTotal
if $check->isa($_) 3 15 18
40 }
41 }
42 10 ▶ return $self->{blessed} ? scalar keys %isa == 1 ? bless $new, $base_bless : do {
Branch: 2 branches
BranchTrueFalseTotal
$self->{'blessed'} ? : 8 2 10
scalar keys %isa == 1 ? : 6 2 8
43 2 my $class = sprintf "Blessed::Merge::__ANON__::%s", $self->{itterator}++;
44 2 eval sprintf('package %s; our @ISA = qw/%s/; 1;', $class, join ' ', keys %isa);
45 2 return bless $new, $class;
46 } : $new;
47 }
48  
49 sub _merge {
50 80 ▶ my ($self, $new, $merger) = @_;
Subroutine _merge: called CC=10 SCAR=23.0
51 80 ▶ return $new unless defined $merger;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $merger 10 70 80
52 70 ▶ my $new_ref = reftype($new) || '';
Condition100%2/2
builtin::reftype($new) || ''
l!l
4822
MC/DC100%1/1
builtin::reftype($new) || ''
builtin::reftype($new)
Truth table100%2/2
A
A= builtin::reftype($new)
Aresult
11
00
53 70 ▶ my $merger_ref = reftype($merger) || 'SCALAR';
Condition100%2/2
builtin::reftype($merger) || 'SCALAR'
l!l
5416
MC/DC100%1/1
builtin::reftype($merger) || 'SCALAR'
builtin::reftype($merger)
Truth table100%2/2
A
A= builtin::reftype($merger)
Aresult
11
00
54 $merger_ref eq 'HASH' ? do {
55 39 ▶ $new = {} if ( $new_ref ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if $new_ref ne "HASH" 2 37 39
56 return {
57 $self->{unique_hash}
58 ? $self->_unique_merge($merger_ref, $new, $merger)
59 39 ▶ : map +( $_ => $self->_merge( $new->{$_}, $merger->{$_} ) ), combine_keys($new, $merger)
Branch: 2 branches
BranchTrueFalseTotal
$self->{'unique_hash'} ? : 19 20 39
$merger_ref eq 'ARRAY' ? : 13 18 31
60 };
61 70 ▶ } : $merger_ref eq 'ARRAY' ? do {
Branch: 1 branch
BranchTrueFalseTotal
$merger_ref eq 'HASH' ? : 39 31 70
62 $new_ref eq 'ARRAY' ? do {
63 11 ▶ my $length = sub {$_[0] < $_[1] ? $_[1] : $_[0]}->(scalar @{$new}, scalar @{$merger});
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] < $_[1] ? : 1 10 11
64 [ $self->{unique_array}
65 ? $self->_unique_merge($merger_ref, $new, $merger, $length)
66 11 ▶ : map { $self->_merge($new->[$_], $merger->[$_]) } 0 .. $length - 1
Branch: 1 branch
BranchTrueFalseTotal
$self->{'unique_array'} ? : 9 2 11
67 ];
68 13 ▶ } : [ map { $self->_merge('', $_ ) } @{ $merger } ]; # destroy da references
Branch: 1 branch
BranchTrueFalseTotal
$new_ref eq 'ARRAY' ? : 11 2 13
69 } : $merger;
70 }
71  
72 sub _unique_merge {
73 28 ▶ my ($s, $r, $n, $m, $l) = @_;
Subroutine _unique_merge: called CC=14 SCAR=26.4
74 28 ▶ ($r eq 'ARRAY') && do {
Branch: 1 branch
BranchTrueFalseTotal
$r eq "ARRAY" and do { my(@z, %u, $x1, $x2); for (my $i = 0; $i < $l; ++$i) { my $c = grep({my($x) = builtin::reftype(\$_); $x eq "SCALAR" ? !$_ || exists $u{$_} ? 1 : do { $u{$_} = 1; push @z, $_ } : 0;} $n->[$i], $m->[$i]); do { () = (builtin::reftype($n->[$i]), builtin::reftype($m->[$i])); $c == 0 } ? $x1 eq $x2 ? push(@z, $s->_merge($n->[$i], $m->[$i])) : push(@z, $n->[$i], $m->[$i]) : ($x1 ? push(@z, $n->[$i]) : push(@z, $m->[$i])) if $c != 2; } ; return @z } 9 19 28
75 9 my (@z, %u, $x1, $x2);
76 9 ▶ for (my $i = 0; $i < $l; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $l) 24 9 33
77 my $c = grep {
78 24 my ($x) = reftype(\$_);
79 48 ▶ $x eq 'SCALAR' ? !$_ || exists $u{$_} ? 1 : do { $u{$_} = 1; push @z, $_; } : 0;
Branch: 2 branches
BranchTrueFalseTotal
$x eq 'SCALAR' ? : 41 7 48
!$_ || exists $u{$_} ? : 14 27 41
Condition100%3/3
not $_ or exists $u{$_}
l!l&&r!l&&!r
7727
MC/DC100%2/2
not $_ or exists $u{$_}
not $_ exists $u{$_}
Truth table100%3/3
not(A) or B
A= not $_B= exists $u{$_}
ABresult
1X1
011
000
80 } ($n->[$i], $m->[$i]);
81 24 ▶ do { ($x1, $x2) = (reftype($n->[$i]), reftype($m->[$i])); $c == 0 }
Branch: 4 branches
BranchTrueFalseTotal
if $c != 2 5 19 24
do { () = (builtin::reftype($n->[$i]), builtin::reftype($m->[$i])); $c == 0 } ? : 2 3 5
$x1 eq $x2 ? : 1 1 2
$x1 ? : 1 2 3
82 ? $x1 eq $x2
83 ? push @z, $s->_merge($n->[$i], $m->[$i])
84 : push @z, $n->[$i], $m->[$i]
85 : $x1
86 ? push @z, $n->[$i]
87 : push @z, $m->[$i] if $c != 2;
88 }
89 9 return @z;
90 };
91 19 my %z = %{ $n };
92 map {
93 31 ▶ my $x = reftype($m->{$_}) || 'SCALAR';
Condition100%2/2
builtin::reftype($m->{$_}) || 'SCALAR'
l!l
229
MC/DC100%1/1
builtin::reftype($m->{$_}) || 'SCALAR'
builtin::reftype($m->{$_})
Truth table100%2/2
A
A= builtin::reftype($m->{$_})
Aresult
11
00
94 exists $z{$_} ? $x ne 'SCALAR' && $x eq reftype($z{$_})
95 31 ▶ ? do { $z{$_} = $s->_merge($z{$_}, $m->{$_}) } : '*\o/*' : do { $z{$_} = $m->{$_} }
Branch: 2 branches
BranchTrueFalseTotal
exists $z{$_} ? : 27 4 31
$x ne 'SCALAR' && $x eq builtin::reftype($z{$_}) ? : 21 6 27
Condition100%3/3
$x ne "SCALAR" and $x eq builtin::reftype($z{$_})
!ll&&!rl&&r
5121
MC/DC100%2/2
$x ne "SCALAR" and $x eq builtin::reftype($z{$_})
$x ne "SCALAR" $x eq builtin::reftype($z{$_})
Truth table100%3/3
A and B
A= $x ne "SCALAR"B= $x eq builtin::reftype($z{$_})
ABresult
0X0
100
111
96 19 } keys %{ $m };
97 19 return %z;
98 }
99  
100 5 1;
101  
102 __END__
↑ Summary