/[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.5 by joko, Thu Mar 27 15:17:05 2003 UTC
# Line 2  Line 2 
2  ##    $Id$  ##    $Id$
3  ##    --------------------------------------------------------------------------------  ##    --------------------------------------------------------------------------------
4  ##    $Log$  ##    $Log$
5    ##    Revision 1.5  2003/03/27 15:17:05  joko
6    ##    namespace fixes for Data::Mungle::*
7    ##
8    ##    Revision 1.4  2002/12/19 01:06:27  joko
9    ##    + fixed isEmpty with ARRAYs
10    ##
11    ##    Revision 1.3  2002/12/13 21:47:04  joko
12    ##    + fixes to 'sub isEmpty'
13    ##
14  ##    Revision 1.2  2002/12/05 07:56:34  joko  ##    Revision 1.2  2002/12/05 07:56:34  joko
15  ##    + updated/enhanced isEmpty (hacky?)  ##    + updated/enhanced isEmpty (hacky?)
16  ##  ##
# Line 11  Line 20 
20  ##    --------------------------------------------------------------------------------  ##    --------------------------------------------------------------------------------
21    
22    
23  package Data::Compare::Struct;  package Data::Mungle::Compare::Struct;
24    
25  use strict;  use strict;
26  use warnings;  use warnings;
# Line 70  sub isEmpty { Line 79  sub isEmpty {
79    
80    #print "isEmpty is parsing variable ( ref $ref reftype $reftype )", "\n";    #print "isEmpty is parsing variable ( ref $ref reftype $reftype )", "\n";
81        
82    #print Dumper($var);
83      
84    my $found;    my $found;
85    
86    if ($ref eq 'Set::Object') {    if ($ref eq 'Set::Object') {
87      $found = 1;      $found = 1;
88      #print "members:", "\n";  #print "members:", "\n";
89      #print Dumper($var->members());  #print Dumper($var->members());
90      #print "\n";  #print "\n";
91      my $tc = { ok => 0, count => 0, empty => 0 };      my $tc = { ok => 0, count => 0, empty => 0 };
92      foreach ($var->members()) {      foreach ($var->members()) {
93    #print "member!!", "\n";
94        #print "empty: ", isEmpty($_), "\n";        #print "empty: ", isEmpty($_), "\n";
95        #$tc->{ok} = 1;        #$tc->{ok} = 1;
96        $tc->{count}++;        $tc->{count}++;
97        $tc->{empty}++ if isEmpty($_);        $tc->{empty}++ if isEmpty($_);
98        #return $result if $result;        #return $result if $result;
99      }      }
100    
101    #print Dumper($tc);
102            
103      return 1 if ($tc->{count} == $tc->{empty});      return 1 if ($tc->{count} == $tc->{empty});
104      return 0;      return 0;
105            
106    }    }
107    
108    if ($reftype eq 'HASH') {    if ($reftype eq 'ARRAY') {
109        my @arr = @$var;
110        my $isReallyEmpty = ($#arr == -1 ? 1 : 0);
111        return 1 if $isReallyEmpty;
112        $found = 1;
113        foreach (@arr) {
114          #return 0 if defined $_;
115          #return 1 if isEmpty($_);
116          return 0 if !isEmpty($_);
117        }
118    
119      } elsif ($reftype eq 'HASH') {
120        my $empty = 1;
121      $found = 1;      $found = 1;
122      foreach (keys %$var) {      foreach (keys %$var) {
123    # TODO: review and fix this!
124  =pod  =pod
125        # recursion        # recursion
126        if (ref $var->{$_} eq 'Set::Object') {        if (ref $var->{$_} eq 'Set::Object') {
# Line 106  sub isEmpty { Line 133  sub isEmpty {
133  =cut  =cut
134        next if ref $var->{$_} eq 'Set::Object';        next if ref $var->{$_} eq 'Set::Object';
135        #return 0 if defined $var->{$_};        #return 0 if defined $var->{$_};
136        return 1 if isEmpty($var->{$_});        #return 1 if isEmpty($var->{$_});
137      }        my $elem_empty = isEmpty($var->{$_});
138          
139    } elsif ($reftype eq 'ARRAY') {  #print "elem: $elem_empty\n";
140      $found = 1;        $empty &&= $elem_empty;
     foreach (@$var) {  
       return 0 if defined $_;  
141      }      }
142        return $empty;
143        #return 0;
144        
145    } else {    } else {
146      $found = 1;      $found = 1;
# Line 124  sub isEmpty { Line 151  sub isEmpty {
151      print "isEmpty could not parse variable ( ref $ref reftype $reftype )", "\n";      print "isEmpty could not parse variable ( ref $ref reftype $reftype )", "\n";
152    }    }
153    
154      #print "EMPTY!!!", "\n";
155    
156    return 1;    return 1;
157        
158  }  }

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

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