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 |
22 |
|
## + updated/enhanced isEmpty (hacky?) |
23 |
|
## |
24 |
## Revision 1.1 2002/11/29 04:49:30 joko |
## Revision 1.1 2002/11/29 04:49:30 joko |
25 |
## + initial check-in |
## + initial check-in |
26 |
## |
## |
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 |
|
|
88 |
} |
} |
89 |
|
|
90 |
sub isEmpty { |
sub isEmpty { |
91 |
|
|
92 |
my $var = shift; |
my $var = shift; |
93 |
my $reftype = attributes::reftype($var); |
my $ref = ref($var); |
94 |
|
my $reftype = ''; |
95 |
|
$reftype = attributes::reftype($var) if $ref; |
96 |
|
|
97 |
if ($reftype eq 'HASH') { |
#print "isEmpty is parsing variable ( ref $ref reftype $reftype )", "\n"; |
98 |
foreach (keys %$var) { |
|
99 |
return 0 if defined $var->{$_}; |
#print Dumper($var); |
100 |
|
|
101 |
|
my $found; |
102 |
|
|
103 |
|
if ($ref eq 'Set::Object') { |
104 |
|
$found = 1; |
105 |
|
#print "members:", "\n"; |
106 |
|
#print Dumper($var->members()); |
107 |
|
#print "\n"; |
108 |
|
my $tc = { ok => 0, count => 0, empty => 0 }; |
109 |
|
foreach ($var->members()) { |
110 |
|
#print "member!!", "\n"; |
111 |
|
#print "empty: ", isEmpty($_), "\n"; |
112 |
|
#$tc->{ok} = 1; |
113 |
|
$tc->{count}++; |
114 |
|
$tc->{empty}++ if isEmpty($_); |
115 |
|
#return $result if $result; |
116 |
|
} |
117 |
|
|
118 |
|
#print Dumper($tc); |
119 |
|
|
120 |
|
return 1 if ($tc->{count} == $tc->{empty}); |
121 |
|
return 0; |
122 |
|
|
123 |
|
} |
124 |
|
|
125 |
|
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 'ARRAY') { |
} elsif ($reftype eq 'HASH') { |
137 |
foreach (@$var) { |
my $empty = 1; |
138 |
return 0 if defined $_; |
$found = 1; |
139 |
|
foreach (keys %$var) { |
140 |
|
# TODO: review and fix this! |
141 |
|
=pod |
142 |
|
# recursion |
143 |
|
if (ref $var->{$_} eq 'Set::Object') { |
144 |
|
print "==========set", "\n"; |
145 |
|
if (isEmpty($var->{$_})) { |
146 |
|
return 0; |
147 |
|
#next; |
148 |
|
} |
149 |
|
} |
150 |
|
=cut |
151 |
|
next if ref $var->{$_} eq 'Set::Object'; |
152 |
|
#return 0 if defined $var->{$_}; |
153 |
|
#return 1 if isEmpty($var->{$_}); |
154 |
|
my $elem_empty = isEmpty($var->{$_}); |
155 |
|
|
156 |
|
#print "elem: $elem_empty\n"; |
157 |
|
$empty &&= $elem_empty; |
158 |
} |
} |
159 |
|
return $empty; |
160 |
|
#return 0; |
161 |
|
|
162 |
|
# check for empty string |
163 |
|
} elsif (defined $var) { |
164 |
|
$found = 1; |
165 |
|
return 0 if $var ne ''; |
166 |
|
} |
167 |
|
|
168 |
|
if (!$found) { |
169 |
|
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 |
} |
} |
177 |
|
|
178 |
1; |
1; |