blib/lib/Blessed/Merge.pm

filter: Statementstmt 100% 82 / 82 Branchbran 94.2% 49 / 52 Conditioncond 88.4% 23 / 26 MC/DCmcdc 76.9% 10 / 13 Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 95.1% 178 / 187 SCAR 37.2
CC
41
Cov
96%
_unique_merge
14.0
merge
12.6
_merge
10.0
CRAP 41.1
↑ Summary
1 package Blessed::Merge;
2  
3 5 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 our $VERSION = '0.11';
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 10 ▶ my ($self, $base_bless, $new) = (shift, ref $_[0], shift);
Subroutine merge: called CC=12 SCAR=25.3
Pod documented
24 10 tie my %isa, 'Tie::IxHash';
25 10 $isa{$base_bless} = $new;
26 map {
27 10 ▶ if ( $self->{same} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'same'}) { } 9 6 15
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 6 my $r = ref $_;
31 6 ▶ $isa{$r} = $_ unless $r =~ m/HASH|ARRAY|SCALAR/;
Branch: 1 branch
BranchTrueFalseTotal
unless $r =~ /HASH|ARRAY|SCALAR/ 6 0 6
32 }
33 14 $new = $self->_merge($new, $_);
34 } @_;
35 9 for my $f (keys %isa) {
36 14 ▶ my $check = $isa{$f} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $check = $isa{$f} or next 0 14 14
37 14 ▶ $_ eq $f and next or $check->isa($_) and delete $isa{$_} for keys %isa;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq $f and next or $check->isa($_) and delete $isa{$_} 17 0 17
Condition62%5/8
$_ eq $f && (next) || $check->isa($_) && delete $isa{$_}
l!l&&r!l&&!r
0170
$_ eq $f and next
!ll
1714
$check->isa($_) and delete $isa{$_}
!ll&&!rl&&r
1430
MC/DC0%0/3
$_ eq $f && (next) || $check->isa($_) && delete $isa{$_}
$_ eq $f $check->isa($_) delete $isa{$_}
Truth table0%0/4
A || B and C
A= $_ eq $fB= $check->isa($_)C= delete $isa{$_}
ABCresult
1XX1
0111
00X0
0100
38 }
39 9 ▶ return $self->{blessed} ? scalar keys %isa == 1 ? bless $new, $base_bless : do {
Branch: 2 branches
BranchTrueFalseTotal
$self->{'blessed'} ? : 8 1 9
scalar keys %isa == 1 ? : 6 2 8
40 2 my $class = sprintf "Blessed::Merge::__ANON__::%s", $self->{itterator}++;
41 2 eval sprintf('package %s; our @ISA = qw/%s/; 1;', $class, join ' ', keys %isa);
42 2 return bless $new, $class;
43 } : $new;
44 }
45  
46 sub _merge {
47 74 ▶ my ($self, $new, $merger) = @_;
Subroutine _merge: called CC=10 SCAR=23.0
48 74 ▶ return $new unless defined $merger;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $merger 8 66 74
49 66 ▶ my $new_ref = reftype($new) || '';
Condition100%2/2
builtin::reftype($new) || ''
l!l
4521
MC/DC100%1/1
builtin::reftype($new) || ''
builtin::reftype($new)
Truth table100%2/2
A
A= builtin::reftype($new)
Aresult
11
00
50 66 ▶ my $merger_ref = reftype($merger) || 'SCALAR';
Condition100%2/2
builtin::reftype($merger) || 'SCALAR'
l!l
5115
MC/DC100%1/1
builtin::reftype($merger) || 'SCALAR'
builtin::reftype($merger)
Truth table100%2/2
A
A= builtin::reftype($merger)
Aresult
11
00
51 $merger_ref eq 'HASH' ? do {
52 36 ▶ $new = {} if ( $new_ref ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if $new_ref ne "HASH" 2 34 36
53 return {
54 $self->{unique_hash}
55 ? $self->_unique_merge($merger_ref, $new, $merger)
56 36 ▶ : map +( $_ => $self->_merge( $new->{$_}, $merger->{$_} ) ), combine_keys($new, $merger)
Branch: 2 branches
BranchTrueFalseTotal
$self->{'unique_hash'} ? : 19 17 36
$merger_ref eq 'ARRAY' ? : 13 17 30
57 };
58 66 ▶ } : $merger_ref eq 'ARRAY' ? do {
Branch: 1 branch
BranchTrueFalseTotal
$merger_ref eq 'HASH' ? : 36 30 66
59 $new_ref eq 'ARRAY' ? do {
60 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
61 [ $self->{unique_array}
62 ? $self->_unique_merge($merger_ref, $new, $merger, $length)
63 11 ▶ : map { $self->_merge($new->[$_], $merger->[$_]) } 0 .. $length - 1
Branch: 1 branch
BranchTrueFalseTotal
$self->{'unique_array'} ? : 9 2 11
64 ];
65 13 ▶ } : [ map { $self->_merge('', $_ ) } @{ $merger } ]; # destroy da references
Branch: 1 branch
BranchTrueFalseTotal
$new_ref eq 'ARRAY' ? : 11 2 13
66 } : $merger;
67 }
68  
69 sub _unique_merge {
70 28 ▶ my ($s, $r, $n, $m, $l) = @_;
Subroutine _unique_merge: called CC=14 SCAR=26.4
71 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
72 9 my (@z, %u, $x1, $x2);
73 9 ▶ for (my $i = 0; $i < $l; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $l) 24 9 33
74 my $c = grep {
75 24 my ($x) = reftype(\$_);
76 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
77 } ($n->[$i], $m->[$i]);
78 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
79 ? $x1 eq $x2
80 ? push @z, $s->_merge($n->[$i], $m->[$i])
81 : push @z, $n->[$i], $m->[$i]
82 : $x1
83 ? push @z, $n->[$i]
84 : push @z, $m->[$i] if $c != 2;
85 }
86 9 return @z;
87 };
88 19 my %z = %{ $n };
89 map {
90 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
91 exists $z{$_} ? $x ne 'SCALAR' && $x eq reftype($z{$_})
92 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
93 19 } keys %{ $m };
94 19 return %z;
95 }
96  
97 5 1;
98  
99 __END__
↑ Summary