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 |
12 |
|
## + updated/enhanced isEmpty (hacky?) |
13 |
|
## |
14 |
## Revision 1.1 2002/11/29 04:49:30 joko |
## Revision 1.1 2002/11/29 04:49:30 joko |
15 |
## + initial check-in |
## + initial check-in |
16 |
## |
## |
68 |
} |
} |
69 |
|
|
70 |
sub isEmpty { |
sub isEmpty { |
71 |
|
|
72 |
my $var = shift; |
my $var = shift; |
73 |
my $reftype = attributes::reftype($var); |
my $ref = ref($var); |
74 |
|
my $reftype = ''; |
75 |
|
$reftype = attributes::reftype($var) if $ref; |
76 |
|
|
77 |
if ($reftype eq 'HASH') { |
#print "isEmpty is parsing variable ( ref $ref reftype $reftype )", "\n"; |
78 |
foreach (keys %$var) { |
|
79 |
return 0 if defined $var->{$_}; |
#print Dumper($var); |
80 |
|
|
81 |
|
my $found; |
82 |
|
|
83 |
|
if ($ref eq 'Set::Object') { |
84 |
|
$found = 1; |
85 |
|
#print "members:", "\n"; |
86 |
|
#print Dumper($var->members()); |
87 |
|
#print "\n"; |
88 |
|
my $tc = { ok => 0, count => 0, empty => 0 }; |
89 |
|
foreach ($var->members()) { |
90 |
|
#print "member!!", "\n"; |
91 |
|
#print "empty: ", isEmpty($_), "\n"; |
92 |
|
#$tc->{ok} = 1; |
93 |
|
$tc->{count}++; |
94 |
|
$tc->{empty}++ if isEmpty($_); |
95 |
|
#return $result if $result; |
96 |
|
} |
97 |
|
|
98 |
|
#print Dumper($tc); |
99 |
|
|
100 |
|
return 1 if ($tc->{count} == $tc->{empty}); |
101 |
|
return 0; |
102 |
|
|
103 |
|
} |
104 |
|
|
105 |
|
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 'ARRAY') { |
} elsif ($reftype eq 'HASH') { |
117 |
foreach (@$var) { |
my $empty = 1; |
118 |
return 0 if defined $_; |
$found = 1; |
119 |
|
foreach (keys %$var) { |
120 |
|
# TODO: review and fix this! |
121 |
|
=pod |
122 |
|
# recursion |
123 |
|
if (ref $var->{$_} eq 'Set::Object') { |
124 |
|
print "==========set", "\n"; |
125 |
|
if (isEmpty($var->{$_})) { |
126 |
|
return 0; |
127 |
|
#next; |
128 |
|
} |
129 |
|
} |
130 |
|
=cut |
131 |
|
next if ref $var->{$_} eq 'Set::Object'; |
132 |
|
#return 0 if defined $var->{$_}; |
133 |
|
#return 1 if isEmpty($var->{$_}); |
134 |
|
my $elem_empty = isEmpty($var->{$_}); |
135 |
|
|
136 |
|
#print "elem: $elem_empty\n"; |
137 |
|
$empty &&= $elem_empty; |
138 |
} |
} |
139 |
|
return $empty; |
140 |
|
#return 0; |
141 |
|
|
142 |
|
} else { |
143 |
|
$found = 1; |
144 |
|
return 0 if defined $var; |
145 |
|
} |
146 |
|
|
147 |
|
if (!$found) { |
148 |
|
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 |
} |
} |
156 |
|
|
157 |
1; |
1; |