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