2 |
## $Id$ |
## $Id$ |
3 |
## -------------------------------------------------------------------------------- |
## -------------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.3 2002/12/13 21:47:04 joko |
6 |
|
## + fixes to 'sub isEmpty' |
7 |
|
## |
8 |
## Revision 1.2 2002/12/05 07:56:34 joko |
## Revision 1.2 2002/12/05 07:56:34 joko |
9 |
## + updated/enhanced isEmpty (hacky?) |
## + updated/enhanced isEmpty (hacky?) |
10 |
## |
## |
73 |
|
|
74 |
#print "isEmpty is parsing variable ( ref $ref reftype $reftype )", "\n"; |
#print "isEmpty is parsing variable ( ref $ref reftype $reftype )", "\n"; |
75 |
|
|
76 |
|
#print Dumper($var); |
77 |
|
|
78 |
my $found; |
my $found; |
79 |
|
|
80 |
if ($ref eq 'Set::Object') { |
if ($ref eq 'Set::Object') { |
81 |
$found = 1; |
$found = 1; |
82 |
#print "members:", "\n"; |
#print "members:", "\n"; |
83 |
#print Dumper($var->members()); |
#print Dumper($var->members()); |
84 |
#print "\n"; |
#print "\n"; |
85 |
my $tc = { ok => 0, count => 0, empty => 0 }; |
my $tc = { ok => 0, count => 0, empty => 0 }; |
86 |
foreach ($var->members()) { |
foreach ($var->members()) { |
87 |
|
#print "member!!", "\n"; |
88 |
#print "empty: ", isEmpty($_), "\n"; |
#print "empty: ", isEmpty($_), "\n"; |
89 |
#$tc->{ok} = 1; |
#$tc->{ok} = 1; |
90 |
$tc->{count}++; |
$tc->{count}++; |
91 |
$tc->{empty}++ if isEmpty($_); |
$tc->{empty}++ if isEmpty($_); |
92 |
#return $result if $result; |
#return $result if $result; |
93 |
} |
} |
94 |
|
|
95 |
|
#print Dumper($tc); |
96 |
|
|
97 |
return 1 if ($tc->{count} == $tc->{empty}); |
return 1 if ($tc->{count} == $tc->{empty}); |
98 |
return 0; |
return 0; |
99 |
|
|
100 |
} |
} |
101 |
|
|
102 |
if ($reftype eq 'HASH') { |
if ($reftype eq 'ARRAY') { |
103 |
|
my @arr = @$var; |
104 |
|
my $isReallyEmpty = ($#arr == -1 ? 1 : 0); |
105 |
|
return 1 if $isReallyEmpty; |
106 |
|
$found = 1; |
107 |
|
foreach (@$var) { |
108 |
|
return 0 if defined $_; |
109 |
|
} |
110 |
|
|
111 |
|
} elsif ($reftype eq 'HASH') { |
112 |
|
my $empty = 1; |
113 |
$found = 1; |
$found = 1; |
114 |
foreach (keys %$var) { |
foreach (keys %$var) { |
115 |
|
# TODO: review and fix this! |
116 |
=pod |
=pod |
117 |
# recursion |
# recursion |
118 |
if (ref $var->{$_} eq 'Set::Object') { |
if (ref $var->{$_} eq 'Set::Object') { |
125 |
=cut |
=cut |
126 |
next if ref $var->{$_} eq 'Set::Object'; |
next if ref $var->{$_} eq 'Set::Object'; |
127 |
#return 0 if defined $var->{$_}; |
#return 0 if defined $var->{$_}; |
128 |
return 1 if isEmpty($var->{$_}); |
#return 1 if isEmpty($var->{$_}); |
129 |
} |
my $elem_empty = isEmpty($var->{$_}); |
130 |
|
|
131 |
} elsif ($reftype eq 'ARRAY') { |
#print "elem: $elem_empty\n"; |
132 |
$found = 1; |
$empty &&= $elem_empty; |
|
foreach (@$var) { |
|
|
return 0 if defined $_; |
|
133 |
} |
} |
134 |
|
return $empty; |
135 |
|
#return 0; |
136 |
|
|
137 |
} else { |
} else { |
138 |
$found = 1; |
$found = 1; |