2 |
## $Id$ |
## $Id$ |
3 |
## -------------------------------------------------------------------------------- |
## -------------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.2 2002/12/05 07:56:34 joko |
6 |
|
## + updated/enhanced isEmpty (hacky?) |
7 |
|
## |
8 |
## Revision 1.1 2002/11/29 04:49:30 joko |
## Revision 1.1 2002/11/29 04:49:30 joko |
9 |
## + initial check-in |
## + initial check-in |
10 |
## |
## |
62 |
} |
} |
63 |
|
|
64 |
sub isEmpty { |
sub isEmpty { |
65 |
|
|
66 |
my $var = shift; |
my $var = shift; |
67 |
my $reftype = attributes::reftype($var); |
my $ref = ref($var); |
68 |
|
my $reftype = ''; |
69 |
|
$reftype = attributes::reftype($var) if $ref; |
70 |
|
|
71 |
|
#print "isEmpty is parsing variable ( ref $ref reftype $reftype )", "\n"; |
72 |
|
|
73 |
|
my $found; |
74 |
|
|
75 |
|
if ($ref eq 'Set::Object') { |
76 |
|
$found = 1; |
77 |
|
#print "members:", "\n"; |
78 |
|
#print Dumper($var->members()); |
79 |
|
#print "\n"; |
80 |
|
my $tc = { ok => 0, count => 0, empty => 0 }; |
81 |
|
foreach ($var->members()) { |
82 |
|
#print "empty: ", isEmpty($_), "\n"; |
83 |
|
#$tc->{ok} = 1; |
84 |
|
$tc->{count}++; |
85 |
|
$tc->{empty}++ if isEmpty($_); |
86 |
|
#return $result if $result; |
87 |
|
} |
88 |
|
|
89 |
|
return 1 if ($tc->{count} == $tc->{empty}); |
90 |
|
return 0; |
91 |
|
|
92 |
|
} |
93 |
|
|
94 |
if ($reftype eq 'HASH') { |
if ($reftype eq 'HASH') { |
95 |
|
$found = 1; |
96 |
foreach (keys %$var) { |
foreach (keys %$var) { |
97 |
return 0 if defined $var->{$_}; |
=pod |
98 |
|
# recursion |
99 |
|
if (ref $var->{$_} eq 'Set::Object') { |
100 |
|
print "==========set", "\n"; |
101 |
|
if (isEmpty($var->{$_})) { |
102 |
|
return 0; |
103 |
|
#next; |
104 |
|
} |
105 |
|
} |
106 |
|
=cut |
107 |
|
next if ref $var->{$_} eq 'Set::Object'; |
108 |
|
#return 0 if defined $var->{$_}; |
109 |
|
return 1 if isEmpty($var->{$_}); |
110 |
} |
} |
111 |
|
|
112 |
} elsif ($reftype eq 'ARRAY') { |
} elsif ($reftype eq 'ARRAY') { |
113 |
|
$found = 1; |
114 |
foreach (@$var) { |
foreach (@$var) { |
115 |
return 0 if defined $_; |
return 0 if defined $_; |
116 |
} |
} |
117 |
|
|
118 |
|
} else { |
119 |
|
$found = 1; |
120 |
|
return 0 if defined $var; |
121 |
|
} |
122 |
|
|
123 |
|
if (!$found) { |
124 |
|
print "isEmpty could not parse variable ( ref $ref reftype $reftype )", "\n"; |
125 |
} |
} |
126 |
|
|
127 |
return 1; |
return 1; |
128 |
|
|
129 |
} |
} |
130 |
|
|
131 |
1; |
1; |