/[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.2 by joko, Thu Dec 5 07:56:34 2002 UTC revision 1.4 by joko, Thu Dec 19 01:06:27 2002 UTC
# Line 2  Line 2 
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  ##  ##
# Line 70  sub isEmpty { Line 76  sub isEmpty {
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') {
# Line 106  sub isEmpty { Line 130  sub isEmpty {
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;
# Line 124  sub isEmpty { Line 148  sub isEmpty {
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  }  }

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

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