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

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

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