| 1 | package AutoCode::Compare; | ||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 5 | ▶ | use AutoCode::Root; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 5 | our @ISA=qw(AutoCode::Root); | |||||||||||||
| 5 | |||||||||||||||
| 6 | 5 | our @REGULAR_REF=qw(SCALAR ARRAY HASH); | |||||||||||||
| 7 | |||||||||||||||
| 8 | 5 | ▶ | use constant FALSE=>0; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 5 | ▶ | use constant TRUE =>1; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 1 | ▶ | sub equal { | ||||||||||||
|
Subroutine
equal: called CC=5 SCAR=22.7
Pod
undocumented
| |||||||||||||||
| 12 | 1 | my ($class, @array)=@_; | |||||||||||||
| 13 | 1 | my @refs=map{ref($_)}@array; | |||||||||||||
| 14 | 1 | ▶ | return 0 unless $refs[0] eq $refs[1]; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 15 | 1 | my $ref=$refs[0]; | |||||||||||||
| 16 | 1 | ▶ | if($ref eq ''){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 17 | 1 | return $array[0] eq $array[1]; | |||||||||||||
| 18 | } | ||||||||||||||
| 19 | 0 | my ($x, $y)=@array; | |||||||||||||
| 20 | 0 | ▶ | return TRUE if ref($x) eq ref($y); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 21 | |||||||||||||||
| 22 | 0 | ▶ | if(grep /^$ref$/, @REGULAR_REF){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 23 | 0 | my $method="equal_\L$ref"; | |||||||||||||
| 24 | 0 | return $class->$method(@array); | |||||||||||||
| 25 | }else{ | ||||||||||||||
| 26 | 0 | return $class->equal_object(@array); | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | } | ||||||||||||||
| 29 | |||||||||||||||
| 30 | 0 | ▶ | sub equal_scalar { | ||||||||||||
|
Subroutine
equal_scalar: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 31 | 0 | my $class=shift; | |||||||||||||
| 32 | 0 | my @scalars=map{my $z=$_; ${$z}}@_; | |||||||||||||
| 33 | 0 | return $class->equal(@scalars); | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 0 | ▶ | sub equal_array { | ||||||||||||
|
Subroutine
equal_array: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 37 | 0 | my $class=shift; | |||||||||||||
| 38 | 0 | my ($x, $y)=@_; | |||||||||||||
| 39 | 0 | my @x=@$x; | |||||||||||||
| 40 | 0 | my @y=@$y; | |||||||||||||
| 41 | 0 | my $max=scalar(@x); | |||||||||||||
| 42 | 0 | ▶ | return FALSE unless $max == scalar(@y); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | 0 | ▶ | return TRUE if $max==0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | 0 | ▶ | for(my $i=0; $i<$max; $i++){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | 0 | ▶ | return FALSE unless $class->equal($x[$i], $y[$i]); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | } | ||||||||||||||
| 47 | 0 | return TRUE; | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 0 | ▶ | sub equal_hash { | ||||||||||||
|
Subroutine
equal_hash: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||
| 51 | 0 | my $class=shift; | |||||||||||||
| 52 | 0 | my ($x, $y)=@_; | |||||||||||||
| 53 | 0 | my %x=%$x; | |||||||||||||
| 54 | 0 | my %y=%$y; | |||||||||||||
| 55 | 0 | my @keys=keys %x; | |||||||||||||
| 56 | 0 | my $max=scalar(@keys); | |||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | ▶ | return FALSE unless $max==scalar(keys %y); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | 0 | ▶ | return TRUE if $max==0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | |||||||||||||||
| 61 | 0 | my $found=0; | |||||||||||||
| 62 | 0 | foreach (@keys){ | |||||||||||||
| 63 | 0 | ▶ | $found++ if exists $y{$_}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | } | ||||||||||||||
| 65 | 0 | ▶ | return FALSE unless $found==$max; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 66 | |||||||||||||||
| 67 | 0 | foreach my $key(@keys){ | |||||||||||||
| 68 | 0 | ▶ | return FALSE unless $class->equal($x{$key}, $y{$key}); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 69 | } | ||||||||||||||
| 70 | 0 | return TRUE; | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 0 | ▶ | sub equal_obj { | ||||||||||||
|
Subroutine
equal_obj: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 74 | 0 | my $class=shift; | |||||||||||||
| 75 | 0 | my @array=@_; | |||||||||||||
| 76 | 0 | my ($x)=@_; | |||||||||||||
| 77 | 0 | my $string="$x"; | |||||||||||||
| 78 | 0 | $string =~ /^([^=]*=)?(\w+)\((\w+)\)$/; | |||||||||||||
| 79 | 0 | my $internal_structure=$2; | |||||||||||||
| 80 | 0 | local $_=$internal_structure; | |||||||||||||
| 81 | 0 | ▶ | if(/^ARRAY$/){ | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 82 | 0 | return $class->equal_array(@array); | |||||||||||||
| 83 | }elsif(/^HASH$/){ | ||||||||||||||
| 84 | 0 | return $class->equal_hash(@_); | |||||||||||||
| 85 | } | ||||||||||||||
| 86 | } | ||||||||||||||
| 87 | |||||||||||||||
| 88 | 5 | 1; | |||||||||||||
| 89 | |||||||||||||||