| 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
Condition100%2/2
builtin::reftype($_[0]) or
MC/DC100%1/1
builtin::reftype($_[0]) or
builtin::reftype($_[0])
Truth table100%2/2
A
A= builtin::reftype($_[0])
| |||||||||||||||||||||||||||||||||
| 15 | 6 | my $self = bless $args, $pkg; | |||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | $self->{$_} = $self->{$_} // 1 foreach (qw/same blessed/); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{$_} // 1
MC/DC100%1/1
$self->{$_} // 1
$self->{$_}
Truth table100%2/2
A
A= $self->{$_}
| |||||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | $self->{$_} = $self->{$_} // 0 foreach(qw/unique_array unique_hash/); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{$_} // 0
MC/DC100%1/1
$self->{$_} // 0
$self->{$_}
Truth table100%2/2
A
A= $self->{$_}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 28 | 9 | ▶ | croak 'Attempting to merge two different *packages*' unless $base_bless eq ref $_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 29 | } else { | ||||||||||||||||||||||||||||||||
| 30 | 8 | my $r = ref $_; | |||||||||||||||||||||||||||||||
| 31 | 8 | ▶ | $isa{$r} = $_ unless $r =~ m/HASH|ARRAY|SCALAR/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 37 | 15 | for (keys %isa) { | |||||||||||||||||||||||||||||||
| 38 | 33 | ▶ | $_ eq $f and next; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | 18 | ▶ | delete $isa{$_} if $check->isa($_); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | 10 | ▶ | return $self->{blessed} ? scalar keys %isa == 1 ? bless $new, $base_bless : do { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 52 | 70 | ▶ | my $new_ref = reftype($new) || ''; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
builtin::reftype($new) || ''
MC/DC100%1/1
builtin::reftype($new) || ''
builtin::reftype($new)
Truth table100%2/2
A
A= builtin::reftype($new)
| |||||||||||||||||||||||||||||||||
| 53 | 70 | ▶ | my $merger_ref = reftype($merger) || 'SCALAR'; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
builtin::reftype($merger) || 'SCALAR'
MC/DC100%1/1
builtin::reftype($merger) || 'SCALAR'
builtin::reftype($merger)
Truth table100%2/2
A
A= builtin::reftype($merger)
| |||||||||||||||||||||||||||||||||
| 54 | $merger_ref eq 'HASH' ? do { | ||||||||||||||||||||||||||||||||
| 55 | 39 | ▶ | $new = {} if ( $new_ref ne 'HASH' ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||||||||||||||
| 61 | 70 | ▶ | } : $merger_ref eq 'ARRAY' ? do { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 67 | ]; | ||||||||||||||||||||||||||||||||
| 68 | 13 | ▶ | } : [ map { $self->_merge('', $_ ) } @{ $merger } ]; # destroy da references | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 75 | 9 | my (@z, %u, $x1, $x2); | |||||||||||||||||||||||||||||||
| 76 | 9 | ▶ | for (my $i = 0; $i < $l; $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
not $_ or exists $u{$_}
MC/DC100%2/2
not $_ or exists $u{$_}
not $_
exists $u{$_}
Truth table100%3/3
not(A) or B
A= not $_B= exists $u{$_}
| |||||||||||||||||||||||||||||||||
| 80 | } ($n->[$i], $m->[$i]); | ||||||||||||||||||||||||||||||||
| 81 | 24 | ▶ | do { ($x1, $x2) = (reftype($n->[$i]), reftype($m->[$i])); $c == 0 } | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||
| 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'
MC/DC100%1/1
builtin::reftype($m->{$_}) || 'SCALAR'
builtin::reftype($m->{$_})
Truth table100%2/2
A
A= builtin::reftype($m->{$_})
| |||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$x ne "SCALAR" and $x eq builtin::reftype($z{$_})
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{$_})
| |||||||||||||||||||||||||||||||||
| 96 | 19 | } keys %{ $m }; | |||||||||||||||||||||||||||||||
| 97 | 19 | return %z; | |||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 5 | 1; | |||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||||||