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