2 |
## $Id$ |
## $Id$ |
3 |
## -------------------------------------------------------------------------------- |
## -------------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.4 2002/12/19 01:06:27 joko |
6 |
|
## + fixed isEmpty with ARRAYs |
7 |
|
## |
8 |
|
## Revision 1.3 2002/12/13 21:47:04 joko |
9 |
|
## + fixes to 'sub isEmpty' |
10 |
|
## |
11 |
## Revision 1.2 2002/12/05 07:56:34 joko |
## Revision 1.2 2002/12/05 07:56:34 joko |
12 |
## + updated/enhanced isEmpty (hacky?) |
## + updated/enhanced isEmpty (hacky?) |
13 |
## |
## |
76 |
|
|
77 |
#print "isEmpty is parsing variable ( ref $ref reftype $reftype )", "\n"; |
#print "isEmpty is parsing variable ( ref $ref reftype $reftype )", "\n"; |
78 |
|
|
79 |
|
#print Dumper($var); |
80 |
|
|
81 |
my $found; |
my $found; |
82 |
|
|
83 |
if ($ref eq 'Set::Object') { |
if ($ref eq 'Set::Object') { |
84 |
$found = 1; |
$found = 1; |
85 |
#print "members:", "\n"; |
#print "members:", "\n"; |
86 |
#print Dumper($var->members()); |
#print Dumper($var->members()); |
87 |
#print "\n"; |
#print "\n"; |
88 |
my $tc = { ok => 0, count => 0, empty => 0 }; |
my $tc = { ok => 0, count => 0, empty => 0 }; |
89 |
foreach ($var->members()) { |
foreach ($var->members()) { |
90 |
|
#print "member!!", "\n"; |
91 |
#print "empty: ", isEmpty($_), "\n"; |
#print "empty: ", isEmpty($_), "\n"; |
92 |
#$tc->{ok} = 1; |
#$tc->{ok} = 1; |
93 |
$tc->{count}++; |
$tc->{count}++; |
94 |
$tc->{empty}++ if isEmpty($_); |
$tc->{empty}++ if isEmpty($_); |
95 |
#return $result if $result; |
#return $result if $result; |
96 |
} |
} |
97 |
|
|
98 |
|
#print Dumper($tc); |
99 |
|
|
100 |
return 1 if ($tc->{count} == $tc->{empty}); |
return 1 if ($tc->{count} == $tc->{empty}); |
101 |
return 0; |
return 0; |
102 |
|
|
103 |
} |
} |
104 |
|
|
105 |
if ($reftype eq 'HASH') { |
if ($reftype eq 'ARRAY') { |
106 |
|
my @arr = @$var; |
107 |
|
my $isReallyEmpty = ($#arr == -1 ? 1 : 0); |
108 |
|
return 1 if $isReallyEmpty; |
109 |
|
$found = 1; |
110 |
|
foreach (@arr) { |
111 |
|
#return 0 if defined $_; |
112 |
|
#return 1 if isEmpty($_); |
113 |
|
return 0 if !isEmpty($_); |
114 |
|
} |
115 |
|
|
116 |
|
} elsif ($reftype eq 'HASH') { |
117 |
|
my $empty = 1; |
118 |
$found = 1; |
$found = 1; |
119 |
foreach (keys %$var) { |
foreach (keys %$var) { |
120 |
|
# TODO: review and fix this! |
121 |
=pod |
=pod |
122 |
# recursion |
# recursion |
123 |
if (ref $var->{$_} eq 'Set::Object') { |
if (ref $var->{$_} eq 'Set::Object') { |
130 |
=cut |
=cut |
131 |
next if ref $var->{$_} eq 'Set::Object'; |
next if ref $var->{$_} eq 'Set::Object'; |
132 |
#return 0 if defined $var->{$_}; |
#return 0 if defined $var->{$_}; |
133 |
return 1 if isEmpty($var->{$_}); |
#return 1 if isEmpty($var->{$_}); |
134 |
} |
my $elem_empty = isEmpty($var->{$_}); |
135 |
|
|
136 |
} elsif ($reftype eq 'ARRAY') { |
#print "elem: $elem_empty\n"; |
137 |
$found = 1; |
$empty &&= $elem_empty; |
|
foreach (@$var) { |
|
|
return 0 if defined $_; |
|
138 |
} |
} |
139 |
|
return $empty; |
140 |
|
#return 0; |
141 |
|
|
142 |
} else { |
} else { |
143 |
$found = 1; |
$found = 1; |
148 |
print "isEmpty could not parse variable ( ref $ref reftype $reftype )", "\n"; |
print "isEmpty could not parse variable ( ref $ref reftype $reftype )", "\n"; |
149 |
} |
} |
150 |
|
|
151 |
|
#print "EMPTY!!!", "\n"; |
152 |
|
|
153 |
return 1; |
return 1; |
154 |
|
|
155 |
} |
} |