lib/AutoCode/Compare.pm

filter: Statementstmt 31.8% 22 / 69 Branchbran 6.6% 2 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 5 totaltotal 25.6% 29 / 113 CC 18 SCAR 34.5
CC
18
Cov
24%
equal_hash
72.0
equal_array
30.0
equal_obj
12.0
CRAP 31.4
↑ Summary lib/AutoCode/SymbolTableUtils.pm »
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
BranchTrueFalseTotal
unless $refs[0] eq $refs[1] 0 1 1
15 1 my $ref=$refs[0];
16 1 ▶ if($ref eq ''){
Branch: 1 branch
BranchTrueFalseTotal
if ($ref eq "") 1 0 1
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
BranchTrueFalseTotal
if ref $x eq ref $y 0 0 0
21
22 0 ▶ if(grep /^$ref$/, @REGULAR_REF){
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^$ref$/, @AutoCode::Compare::REGULAR_REF) { } 0 0 0
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
BranchTrueFalseTotal
unless $max == scalar @y 0 0 0
43 0 ▶ return TRUE if $max==0;
Branch: 1 branch
BranchTrueFalseTotal
if $max == 0 0 0 0
44 0 ▶ for(my $i=0; $i<$max; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max) 0 0 0
45 0 ▶ return FALSE unless $class->equal($x[$i], $y[$i]);
Branch: 1 branch
BranchTrueFalseTotal
unless $class->equal($x[$i], $y[$i]) 0 0 0
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
BranchTrueFalseTotal
unless $max == scalar keys %y 0 0 0
59 0 ▶ return TRUE if $max==0;
Branch: 1 branch
BranchTrueFalseTotal
if $max == 0 0 0 0
60  
61 0 my $found=0;
62 0 foreach (@keys){
63 0 ▶ $found++ if exists $y{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $y{$_} 0 0 0
64 }
65 0 ▶ return FALSE unless $found==$max;
Branch: 1 branch
BranchTrueFalseTotal
unless $found == $max 0 0 0
66  
67 0 foreach my $key(@keys){
68 0 ▶ return FALSE unless $class->equal($x{$key}, $y{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless $class->equal($x{$key}, $y{$key}) 0 0 0
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
BranchTrueFalseTotal
if (/^ARRAY$/) { } 0 0 0
elsif (/^HASH$/) { } 0 0 0
82 0 return $class->equal_array(@array);
83 }elsif(/^HASH$/){
84 0 return $class->equal_hash(@_);
85 }
86 }
87  
88 5 1;
89
↑ Summary lib/AutoCode/SymbolTableUtils.pm »