/[cvs]/nfo/perl/libs/Data/Mungle/Compare/Struct.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Mungle/Compare/Struct.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by joko, Fri Nov 29 04:49:30 2002 UTC revision 1.2 by joko, Thu Dec 5 07:56:34 2002 UTC
# Line 2  Line 2 
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  ##  ##
# Line 59  sub getDifference { Line 62  sub getDifference {
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;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed