| 1 | # vi: set ts=4 sw=4 ht=4 et : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | package perl5i::1::ARRAY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | no if $] >= 5.018000, warnings => 'experimental::smartmatch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use perl5i::1::autobox; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | sub first { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | my ( $array, $filter ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # Deep recursion and segfault (lines 90 and 91 in first.t) if we use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # the same elegant approach as in grep(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | if ( ref $filter eq 'Regexp' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | return List::Util::first( sub { $_ ~~ $filter }, @$array ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | return List::Util::first( sub { $filter->() }, @$array ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | sub grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my ( $array, $filter ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
grep: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my @result = CORE::grep { $_ ~~ $filter } @$array; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | return wantarray ? @result : \@result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | sub all { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | require List::MoreUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | return List::MoreUtils::all($_[1], @{$_[0]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | sub any { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | require List::MoreUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
any: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | return List::MoreUtils::any($_[1], @{$_[0]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | sub none { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | require List::MoreUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
none: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | return List::MoreUtils::none($_[1], @{$_[0]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | sub true { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | require List::MoreUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
true: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return List::MoreUtils::true($_[1], @{$_[0]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | sub false { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | require List::MoreUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
false: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | return List::MoreUtils::false($_[1], @{$_[0]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | sub uniq { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | require List::MoreUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uniq: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my @uniq = List::MoreUtils::uniq(@{$_[0]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | return wantarray ? @uniq : \@uniq; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | sub minmax { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | require List::MoreUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
minmax: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my @minmax = List::MoreUtils::minmax(@{$_[0]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | return wantarray ? @minmax : \@minmax; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | sub mesh { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | require List::MoreUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mesh: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my @mesh = List::MoreUtils::zip(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return wantarray ? @mesh : \@mesh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # Returns the code which will run when the object is used as a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | require overload; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | my $overload_type = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return unless ref $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $str = overload::Method($_[0], q[""]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $num = overload::Method($_[0], "0+"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | return "both" if $str and $num; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$str and $num
MC/DC0%0/2
$str and $num
$str
$num
Truth table0%0/3
A and B
A= $strB= $num
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | return "" if !$str and !$num; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$str or $num
MC/DC0%0/2
$str or $num
$str
$num
Truth table0%0/3
A or B
A= $strB= $num
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | return "str" if $str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | return "num" if $num; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | my $are_equal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # Two objects, possibly different classes, both overloaded. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | my $equal_overload = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my($obj1, $obj2) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $type1 = $overload_type->($obj1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $type2 = $overload_type->($obj2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # One of them is not overloaded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | return if !$type1 or !$type2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type1 and $type2
MC/DC0%0/2
$type1 and $type2
$type1
$type2
Truth table0%0/3
A and B
A= $type1B= $type2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if( $type1 eq 'both' and $type2 eq 'both' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
$type1 eq "both" and $type2 eq "both"
MC/DC0%0/2
$type1 eq "both" and $type2 eq "both"
$type1 eq "both"
$type2 eq "both"
Truth table0%0/3
A and B
A= $type1 eq "both"B= $type2 eq "both"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | return $obj1 == $obj2 || $obj1 eq $obj2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj1 == $obj2 || $obj1 eq $obj2
MC/DC0%0/2
$obj1 == $obj2 || $obj1 eq $obj2
$obj1 == $obj2
$obj1 eq $obj2
Truth table0%0/3
A || B
A= $obj1 == $obj2B= $obj1 eq $obj2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | ▶ | elsif( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$type1 eq "num" and $type2 eq "str" or $type1 eq "str" and $type2 eq "num"
$type1 eq "num" and $type2 eq "str"
$type1 eq "str" and $type2 eq "num"
MC/DC0%0/4
$type1 eq "num" and $type2 eq "str" or $type1 eq "str" and $type2 eq "num"
$type1 eq "num"
$type2 eq "str"
$type1 eq "str"
$type2 eq "num"
Truth table0%0/7
A and B or C and D
A= $type1 eq "num"B= $type2 eq "str"C= $type1 eq "str"D= $type2 eq "num"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ($type1 eq 'num' and $type2 eq 'str') or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ($type1 eq 'str' and $type2 eq 'num') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # They're not both numbers, not both strings, and not both both | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # Must be str vs num. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | return $type1 eq 'num' ? $obj1+0 eq "$obj2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | : $obj2+0 eq "$obj1"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | elsif( 'num' ~~ [$type1, $type2] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | return $obj1 == $obj2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | elsif( 'str' ~~ [$type1, $type2] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | return $obj1 eq $obj2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | die "Should never be reached"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # Two objects, same class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | my $equal_objects = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my($r1, $r2) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # No need to check both, they're the same class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $is_overloaded = overload::Overloaded($r1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if( !$is_overloaded ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # Neither are overloaded, they're the same class, are they the same object? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | return $r1 eq $r2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | return $equal_overload->( $r1, $r2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # One overloaded object, one plain scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # STRING != OBJ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # NUMBER != OBJ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # STRING eq OBJeq | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # STRING eq OBJboth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # STRING != OBJ== (using == will throw a warning) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # NUMBER == OBJ== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # NUMBER eq OBJeq | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # NUMBER == OBJboth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | my $equal_overload_vs_scalar = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | my($obj, $scalar) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $type = $overload_type->($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | return unless $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if( $scalar->is_number ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if( $type eq 'str' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $obj eq $scalar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $obj == $scalar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if( $type eq 'num' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # Can't reliably compare | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $obj eq $scalar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | my $equal_arrays = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | my ($r1, $r2) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # They can only be equal if they have the same nº of elements. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | return if @$r1 != @$r2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | foreach my $i (0 .. @$r1 - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | return unless $are_equal->($r1->[$i], $r2->[$i]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | my $equal_hashes = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | my ($r1, $r2) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # Hashes can't be equal unless their keys are equal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | return unless ( %$r1 ~~ %$r2 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # Compare the equality of the values for each key. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | foreach my $key (keys %$r1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | return unless $are_equal->( $r1->{$key}, $r2->{$key} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | $are_equal = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | my ($r1, $r2) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=22 SCAR=62.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # given two scalars, decide whether they are identical or not, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # recursing over deep data structures. Since it uses recursion, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # traversal is done depth-first. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # Warning: complex if-then-else decision tree ahead. It's ordered on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # my perceived and anecdotical take on the frequency of occurrence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # of each reftype: most popular on top, most rare on the bottom. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # This way we return as early as possible. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # undef eq undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | return 1 if !defined $r1 and !defined $r2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $r1 or defined $r2
MC/DC0%0/2
defined $r1 or defined $r2
defined $r1
defined $r2
Truth table0%0/3
A or B
A= defined $r1B= defined $r2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # One is defined, one isn't | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | return if defined $r1 xor defined $r2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
defined $r1 xor defined $r2
MC/DC0%0/2
defined $r1 xor defined $r2
defined $r1
defined $r2
Truth table0%0/4
A xor B
A= defined $r1B= defined $r2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my( $ref1, $ref2 ) = (ref $r1, ref $r2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if( !$ref1 and !$ref2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$ref1 || $ref2
MC/DC0%0/2
$ref1 || $ref2
$ref1
$ref2
Truth table0%0/3
A || B
A= $ref1B= $ref2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $is_num1 = $r1->is_number; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | my $is_num2 = $r2->is_number; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if( $is_num1 xor $is_num2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/4
$is_num1 xor $is_num2
MC/DC0%0/2
$is_num1 xor $is_num2
$is_num1
$is_num2
Truth table0%0/4
A xor B
A= $is_num1B= $is_num2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # One's looks like a number, the other doesn't. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # Can't be equal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | elsif( $is_num1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # They're both numbers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return $r1 == $r2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # They're both strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | return $r1 eq $r2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | elsif( $ref1 eq $ref2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if ( $ref1 ~~ [qw(Regexp GLOB CODE)] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | return $r1 eq $r2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | elsif ( $ref1 eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | return $equal_arrays->( $r1, $r2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | elsif ( $ref1 eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | return $equal_hashes->( $r1, $r2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | elsif ( $ref1 ~~ [qw(SCALAR REF)] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return $are_equal->($$r1, $$r2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # Must be an object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | return $equal_objects->( $r1, $r2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | ▶ | elsif( $ref1 and $ref2 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ref1 and $ref2
MC/DC0%0/2
$ref1 and $ref2
$ref1
$ref2
Truth table0%0/3
A and B
A= $ref1B= $ref2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # They're both refs, but not of the same type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my $is_overloaded1 = overload::Overloaded($r1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my $is_overloaded2 = overload::Overloaded($r2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | if( $is_overloaded1 and $is_overloaded2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$is_overloaded1 and $is_overloaded2
MC/DC0%0/2
$is_overloaded1 and $is_overloaded2
$is_overloaded1
$is_overloaded2
Truth table0%0/3
A and B
A= $is_overloaded1B= $is_overloaded2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # Two overloaded objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | return $equal_overload->( $r1, $r2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # One's an overloaded object, the other is not or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # Two plain refs different type or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # non-overloaded objects of different type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # One is a ref, one is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | my $is_overloaded = $ref1 ? overload::Overloaded($r1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | : overload::Overloaded($r2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | if( $is_overloaded ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # One's an overloaded object, one's a plain scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | return $ref1 ? $equal_overload_vs_scalar->($r1, $r2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | : $equal_overload_vs_scalar->($r2, $r1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # One's a plain ref or object, one's a plain scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | my $diff_two = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # Compare differences between two arrays. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | my ($c, $d) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my $diff = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # For each element of $c, try to find if it is equal to any of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # elements of $d. If not, it's unique, and has to be pushed into | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # $diff. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | require List::MoreUtils; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | foreach my $item (@$c) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | unless ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | List::MoreUtils::any( sub { $are_equal->( $item, $_ ) }, @$d ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | push @$diff, $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | return $diff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | sub diff { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | my ($base, @rest) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
diff: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | unless (@rest) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | return wantarray ? @$base : $base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # XXX If I use carp here, the exception is "bizarre copy of ARRAY in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # ssasign ... " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | die "Arguments must be array references" if grep { ref $_ ne 'ARRAY' } @rest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | foreach my $array (@rest) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $base = $diff_two->($base, $array); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | return wantarray ? @$base : $base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | my $intersect_two = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # Compare differences between two arrays. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | my ($c, $d) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my $intersect = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # For each element of $c, try to find if it is equal to any of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # elements of $d. If it is, it's shared, and has to be pushed into | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # $intersect. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | require List::MoreUtils; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | foreach my $item (@$c) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | List::MoreUtils::any( sub { $are_equal->( $item, $_ ) }, @$d ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | push @$intersect, $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | return $intersect; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | sub intersect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | my ($base, @rest) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
intersect: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | unless (@rest) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | return wantarray ? @$base : $base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # XXX If I use carp here, the exception is "bizarre copy of ARRAY in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # ssasign ... " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | die "Arguments must be array references" if grep { ref $_ ne 'ARRAY' } @rest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | foreach my $array (@rest) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $base = $intersect_two->($base, $array); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | return wantarray ? @$base : $base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||