| 1 | package perl5i::2::equal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | no if $] >= 5.018000, warnings => 'experimental::smartmatch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use perl5i::2::autobox; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | sub are_equal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 411 | ▶ | my ($r1, $r2) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
are_equal: called CC=22 SCAR=30.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # given two scalars, decide whether they are identical or not, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # recursing over deep data structures. Since it uses recursion, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # traversal is done depth-first. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # Warning: complex if-then-else decision tree ahead. It's ordered on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # my perceived and anecdotical take on the frequency of occurrence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # of each reftype: most popular on top, most rare on the bottom. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # This way we return as early as possible. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # undef eq undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 411 | ▶ | return 1 if !defined $r1 and !defined $r2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $r1 or defined $r2
MC/DC100%2/2
defined $r1 or defined $r2
defined $r1
defined $r2
Truth table100%3/3
A or B
A= defined $r1B= defined $r2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # One is defined, one isn't | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 410 | ▶ | return if defined $r1 xor defined $r2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%3/4
defined $r1 xor defined $r2
MC/DC100%2/2
defined $r1 xor defined $r2
defined $r1
defined $r2
Truth table75%3/4
A xor B
A= defined $r1B= defined $r2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 390 | my( $ref1, $ref2 ) = (ref $r1, ref $r2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 390 | ▶ | if( !$ref1 and !$ref2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$ref1 || $ref2
MC/DC100%2/2
$ref1 || $ref2
$ref1
$ref2
Truth table100%3/3
A || B
A= $ref1B= $ref2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 90 | my $is_num1 = $r1->is_number; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 90 | my $is_num2 = $r2->is_number; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 90 | ▶ | if( $is_num1 xor $is_num2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%4/4
$is_num1 xor $is_num2
MC/DC100%2/2
$is_num1 xor $is_num2
$is_num1
$is_num2
Truth table100%4/4
A xor B
A= $is_num1B= $is_num2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # One's looks like a number, the other doesn't. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # Can't be equal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | elsif( $is_num1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # They're both numbers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 53 | return $r1 == $r2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # They're both strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 35 | return $r1 eq $r2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | elsif( $ref1 eq $ref2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 77 | ▶ | if ( $ref1 ~~ [qw(Regexp GLOB CODE)] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 12 | return $r1 eq $r2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | elsif ( $ref1 eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 12 | return _equal_arrays( $r1, $r2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | elsif ( $ref1 eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 27 | return _equal_hashes( $r1, $r2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | elsif ( $ref1 ~~ [qw(SCALAR REF)] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 14 | return are_equal($$r1, $$r2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Must be an object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 12 | return _equal_objects( $r1, $r2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ▶ | elsif( $ref1 and $ref2 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$ref1 and $ref2
MC/DC100%2/2
$ref1 and $ref2
$ref1
$ref2
Truth table100%3/3
A and B
A= $ref1B= $ref2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # They're both refs, but not of the same type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 116 | my $is_overloaded1 = overload::Overloaded($r1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 116 | my $is_overloaded2 = overload::Overloaded($r2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 116 | ▶ | if( $is_overloaded1 and $is_overloaded2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$is_overloaded1 and $is_overloaded2
MC/DC100%2/2
$is_overloaded1 and $is_overloaded2
$is_overloaded1
$is_overloaded2
Truth table100%3/3
A and B
A= $is_overloaded1B= $is_overloaded2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # Two overloaded objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 6 | return _equal_overload( $r1, $r2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # One's an overloaded object, the other is not or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # Two plain refs different type or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # non-overloaded objects of different type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 110 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # One is a ref, one is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 107 | ▶ | my $is_overloaded = $ref1 ? overload::Overloaded($r1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | : overload::Overloaded($r2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 107 | ▶ | if( $is_overloaded ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # One's an overloaded object, one's a plain scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 20 | ▶ | return $ref1 ? _equal_overload_vs_scalar($r1, $r2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | : _equal_overload_vs_scalar($r2, $r1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # One's a plain ref or object, one's a plain scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 87 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | sub _equal_arrays { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 12 | ▶ | my ($r1, $r2) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_equal_arrays: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # They can only be equal if they have the same nº of elements. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 12 | ▶ | return if @$r1 != @$r2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 9 | foreach my $i (0 .. @$r1 - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 24 | ▶ | return unless are_equal($r1->[$i], $r2->[$i]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 7 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | sub _equal_hashes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 27 | ▶ | my ($r1, $r2) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_equal_hashes: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # Hashes can't be equal unless their keys are equal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 27 | ▶ | return unless ( %$r1 ~~ %$r2 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # Compare the equality of the values for each key. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 23 | foreach my $key (keys %$r1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 23 | ▶ | return unless are_equal( $r1->{$key}, $r2->{$key} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 16 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # Returns the code which will run when the object is used as a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 6 | require overload; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | sub _overload_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 48 | ▶ | return unless ref $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_overload_type: called CC=8 SCAR=22.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 48 | my $str = overload::Method($_[0], q[""]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 48 | my $num = overload::Method($_[0], "0+"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 48 | ▶ | return "both" if $str and $num; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$str and $num
MC/DC0%0/2
$str and $num
$str
$num
Truth table66%2/3
A and B
A= $strB= $num
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 48 | ▶ | return "" if !$str and !$num; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$str or $num
MC/DC0%0/2
$str or $num
$str
$num
Truth table66%2/3
A or B
A= $strB= $num
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 48 | ▶ | return "str" if $str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 27 | ▶ | return "num" if $num; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # Two objects, possibly different classes, both overloaded. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | sub _equal_overload { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 14 | ▶ | my($obj1, $obj2) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_equal_overload: called CC=13 SCAR=28.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 14 | my $type1 = _overload_type($obj1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 14 | my $type2 = _overload_type($obj2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # One of them is not overloaded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 14 | ▶ | return if !$type1 or !$type2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type1 and $type2
MC/DC0%0/2
$type1 and $type2
$type1
$type2
Truth table33%1/3
A and B
A= $type1B= $type2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 14 | ▶ | if( $type1 eq 'both' and $type2 eq 'both' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition33%1/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 table33%1/3
A and B
A= $type1 eq "both"B= $type2 eq "both"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | ▶ | elsif( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%9/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/DC75%3/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 table57%4/7
A and B or C and D
A= $type1 eq "num"B= $type2 eq "str"C= $type1 eq "str"D= $type2 eq "num"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | ($type1 eq 'num' and $type2 eq 'str') or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ($type1 eq 'str' and $type2 eq 'num') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # They're not both numbers, not both strings, and not both both | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # Must be str vs num. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 6 | ▶ | return $type1 eq 'num' ? $obj1+0 eq "$obj2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | : $obj2+0 eq "$obj1"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | elsif( 'num' ~~ [$type1, $type2] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 5 | return $obj1 == $obj2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | elsif( 'str' ~~ [$type1, $type2] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 3 | return $obj1 eq $obj2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | die "Should never be reached"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # Two objects, same class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | sub _equal_objects { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 12 | ▶ | my($r1, $r2) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_equal_objects: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # No need to check both, they're the same class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 12 | my $is_overloaded = overload::Overloaded($r1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 12 | ▶ | if( !$is_overloaded ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # Neither are overloaded, they're the same class, are they the same object? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | return $r1 eq $r2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 8 | return _equal_overload( $r1, $r2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # One overloaded object, one plain scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # STRING != OBJ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # NUMBER != OBJ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # STRING eq OBJeq | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # STRING eq OBJboth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # STRING != OBJ== (using == will throw a warning) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # NUMBER == OBJ== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # NUMBER eq OBJeq | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # NUMBER == OBJboth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | sub _equal_overload_vs_scalar { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 20 | ▶ | my($obj, $scalar) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_equal_overload_vs_scalar: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 20 | my $type = _overload_type($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 20 | ▶ | return unless $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 20 | ▶ | if( $scalar->is_number ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 10 | ▶ | if( $type eq 'str' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | $obj eq $scalar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | $obj == $scalar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 10 | ▶ | if( $type eq 'num' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # Can't reliably compare | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 5 | $obj eq $scalar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||