| 2 |
## $Id$ |
## $Id$ |
| 3 |
## -------------------------------------------------------------------------------- |
## -------------------------------------------------------------------------------- |
| 4 |
## $Log$ |
## $Log$ |
| 5 |
|
## Revision 1.7 2004/07/07 03:13:43 joko |
| 6 |
|
## minor fix for "sub isEmpty" |
| 7 |
|
## |
| 8 |
|
## Revision 1.6 2004/05/12 13:53:19 jonen |
| 9 |
|
## + bugfix related to declaration of arrays, |
| 10 |
|
## solved error: 'Bizarre copy of ARRAY in aassign at...' |
| 11 |
|
## |
| 12 |
|
## Revision 1.5 2003/03/27 15:17:05 joko |
| 13 |
|
## namespace fixes for Data::Mungle::* |
| 14 |
|
## |
| 15 |
|
## Revision 1.4 2002/12/19 01:06:27 joko |
| 16 |
|
## + fixed isEmpty with ARRAYs |
| 17 |
|
## |
| 18 |
|
## Revision 1.3 2002/12/13 21:47:04 joko |
| 19 |
|
## + fixes to 'sub isEmpty' |
| 20 |
|
## |
| 21 |
## Revision 1.2 2002/12/05 07:56:34 joko |
## Revision 1.2 2002/12/05 07:56:34 joko |
| 22 |
## + updated/enhanced isEmpty (hacky?) |
## + updated/enhanced isEmpty (hacky?) |
| 23 |
## |
## |
| 27 |
## -------------------------------------------------------------------------------- |
## -------------------------------------------------------------------------------- |
| 28 |
|
|
| 29 |
|
|
| 30 |
package Data::Compare::Struct; |
package Data::Mungle::Compare::Struct; |
| 31 |
|
|
| 32 |
use strict; |
use strict; |
| 33 |
use warnings; |
use warnings; |
| 48 |
my @a = @{$a_ref}; |
my @a = @{$a_ref}; |
| 49 |
my @b = @{$b_ref}; |
my @b = @{$b_ref}; |
| 50 |
|
|
| 51 |
my @isect = my @diff = my @union = (); |
# BUGFIX 2004-05-12: following declaration of arrays occures an strange perl error: |
| 52 |
|
# 'Bizarre copy of ARRAY in aassign at ..<PATH_TO>/<THIS_FILE> line <NEXT LINE>' |
| 53 |
|
# (at PERL 5.8.4, Debian/unstable/experimental) |
| 54 |
|
# |
| 55 |
|
#my @isect = my @diff = my @union = (); |
| 56 |
|
# |
| 57 |
|
# so use normal declaration instead!! |
| 58 |
|
my @isect = (); |
| 59 |
|
my @diff = (); |
| 60 |
|
my @union = (); |
| 61 |
|
|
| 62 |
my $e; |
my $e; |
| 63 |
my %count; |
my %count; |
| 64 |
|
|
| 96 |
|
|
| 97 |
#print "isEmpty is parsing variable ( ref $ref reftype $reftype )", "\n"; |
#print "isEmpty is parsing variable ( ref $ref reftype $reftype )", "\n"; |
| 98 |
|
|
| 99 |
|
#print Dumper($var); |
| 100 |
|
|
| 101 |
my $found; |
my $found; |
| 102 |
|
|
| 103 |
if ($ref eq 'Set::Object') { |
if ($ref eq 'Set::Object') { |
| 104 |
$found = 1; |
$found = 1; |
| 105 |
#print "members:", "\n"; |
#print "members:", "\n"; |
| 106 |
#print Dumper($var->members()); |
#print Dumper($var->members()); |
| 107 |
#print "\n"; |
#print "\n"; |
| 108 |
my $tc = { ok => 0, count => 0, empty => 0 }; |
my $tc = { ok => 0, count => 0, empty => 0 }; |
| 109 |
foreach ($var->members()) { |
foreach ($var->members()) { |
| 110 |
|
#print "member!!", "\n"; |
| 111 |
#print "empty: ", isEmpty($_), "\n"; |
#print "empty: ", isEmpty($_), "\n"; |
| 112 |
#$tc->{ok} = 1; |
#$tc->{ok} = 1; |
| 113 |
$tc->{count}++; |
$tc->{count}++; |
| 114 |
$tc->{empty}++ if isEmpty($_); |
$tc->{empty}++ if isEmpty($_); |
| 115 |
#return $result if $result; |
#return $result if $result; |
| 116 |
} |
} |
| 117 |
|
|
| 118 |
|
#print Dumper($tc); |
| 119 |
|
|
| 120 |
return 1 if ($tc->{count} == $tc->{empty}); |
return 1 if ($tc->{count} == $tc->{empty}); |
| 121 |
return 0; |
return 0; |
| 122 |
|
|
| 123 |
} |
} |
| 124 |
|
|
| 125 |
if ($reftype eq 'HASH') { |
if ($reftype eq 'ARRAY') { |
| 126 |
|
my @arr = @$var; |
| 127 |
|
my $isReallyEmpty = ($#arr == -1 ? 1 : 0); |
| 128 |
|
return 1 if $isReallyEmpty; |
| 129 |
|
$found = 1; |
| 130 |
|
foreach (@arr) { |
| 131 |
|
#return 0 if defined $_; |
| 132 |
|
#return 1 if isEmpty($_); |
| 133 |
|
return 0 if !isEmpty($_); |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
} elsif ($reftype eq 'HASH') { |
| 137 |
|
my $empty = 1; |
| 138 |
$found = 1; |
$found = 1; |
| 139 |
foreach (keys %$var) { |
foreach (keys %$var) { |
| 140 |
|
# TODO: review and fix this! |
| 141 |
=pod |
=pod |
| 142 |
# recursion |
# recursion |
| 143 |
if (ref $var->{$_} eq 'Set::Object') { |
if (ref $var->{$_} eq 'Set::Object') { |
| 150 |
=cut |
=cut |
| 151 |
next if ref $var->{$_} eq 'Set::Object'; |
next if ref $var->{$_} eq 'Set::Object'; |
| 152 |
#return 0 if defined $var->{$_}; |
#return 0 if defined $var->{$_}; |
| 153 |
return 1 if isEmpty($var->{$_}); |
#return 1 if isEmpty($var->{$_}); |
| 154 |
} |
my $elem_empty = isEmpty($var->{$_}); |
| 155 |
|
|
| 156 |
} elsif ($reftype eq 'ARRAY') { |
#print "elem: $elem_empty\n"; |
| 157 |
$found = 1; |
$empty &&= $elem_empty; |
|
foreach (@$var) { |
|
|
return 0 if defined $_; |
|
| 158 |
} |
} |
| 159 |
|
return $empty; |
| 160 |
|
#return 0; |
| 161 |
|
|
| 162 |
} else { |
# check for empty string |
| 163 |
|
} elsif (defined $var) { |
| 164 |
$found = 1; |
$found = 1; |
| 165 |
return 0 if defined $var; |
return 0 if $var ne ''; |
| 166 |
} |
} |
| 167 |
|
|
| 168 |
if (!$found) { |
if (!$found) { |
| 169 |
print "isEmpty could not parse variable ( ref $ref reftype $reftype )", "\n"; |
print "isEmpty could not parse variable ( ref $ref reftype $reftype )", "\n"; |
| 170 |
} |
} |
| 171 |
|
|
| 172 |
|
#print "EMPTY!!!", "\n"; |
| 173 |
|
|
| 174 |
return 1; |
return 1; |
| 175 |
|
|
| 176 |
} |
} |