/[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.6 by jonen, Wed May 12 13:53:19 2004 UTC
# Line 2  Line 2 
2  ##    $Id$  ##    $Id$
3  ##    --------------------------------------------------------------------------------  ##    --------------------------------------------------------------------------------
4  ##    $Log$  ##    $Log$
5    ##    Revision 1.6  2004/05/12 13:53:19  jonen
6    ##    + bugfix related to declaration of arrays,
7    ##        solved error: 'Bizarre copy of ARRAY in aassign at...'
8    ##
9    ##    Revision 1.5  2003/03/27 15:17:05  joko
10    ##    namespace fixes for Data::Mungle::*
11    ##
12    ##    Revision 1.4  2002/12/19 01:06:27  joko
13    ##    + fixed isEmpty with ARRAYs
14    ##
15    ##    Revision 1.3  2002/12/13 21:47:04  joko
16    ##    + fixes to 'sub isEmpty'
17    ##
18    ##    Revision 1.2  2002/12/05 07:56:34  joko
19    ##    + updated/enhanced isEmpty (hacky?)
20    ##
21  ##    Revision 1.1  2002/11/29 04:49:30  joko  ##    Revision 1.1  2002/11/29 04:49:30  joko
22  ##    + initial check-in  ##    + initial check-in
23  ##  ##
24  ##    --------------------------------------------------------------------------------  ##    --------------------------------------------------------------------------------
25    
26    
27  package Data::Compare::Struct;  package Data::Mungle::Compare::Struct;
28    
29  use strict;  use strict;
30  use warnings;  use warnings;
# Line 29  sub getRelations { Line 45  sub getRelations {
45    my @a = @{$a_ref};    my @a = @{$a_ref};
46    my @b = @{$b_ref};    my @b = @{$b_ref};
47    
48    my @isect = my @diff = my @union = ();    # BUGFIX 2004-05-12: following declaration of arrays occures an strange perl error:
49      # 'Bizarre copy of ARRAY in aassign at ..<PATH_TO>/<THIS_FILE> line <NEXT LINE>'
50      # (at PERL 5.8.4, Debian/unstable/experimental)
51      #
52      #my @isect = my @diff = my @union = ();
53      #
54      # so use normal declaration instead!!
55      my @isect = ();
56      my @diff = ();
57      my @union = ();
58    
59    my $e;    my $e;
60    my %count;    my %count;
61        
# Line 59  sub getDifference { Line 85  sub getDifference {
85  }  }
86    
87  sub isEmpty {  sub isEmpty {
88    
89    my $var = shift;    my $var = shift;
90    my $reftype = attributes::reftype($var);    my $ref = ref($var);
91      my $reftype = '';
92      $reftype = attributes::reftype($var) if $ref;
93    
94    if ($reftype eq 'HASH') {    #print "isEmpty is parsing variable ( ref $ref reftype $reftype )", "\n";
95      foreach (keys %$var) {    
96        return 0 if defined $var->{$_};  #print Dumper($var);
97      
98      my $found;
99    
100      if ($ref eq 'Set::Object') {
101        $found = 1;
102    #print "members:", "\n";
103    #print Dumper($var->members());
104    #print "\n";
105        my $tc = { ok => 0, count => 0, empty => 0 };
106        foreach ($var->members()) {
107    #print "member!!", "\n";
108          #print "empty: ", isEmpty($_), "\n";
109          #$tc->{ok} = 1;
110          $tc->{count}++;
111          $tc->{empty}++ if isEmpty($_);
112          #return $result if $result;
113      }      }
114    
115    } elsif ($reftype eq 'ARRAY') {  #print Dumper($tc);
116      foreach (@$var) {      
117        return 0 if defined $_;      return 1 if ($tc->{count} == $tc->{empty});
118        return 0;
119        
120      }
121    
122      if ($reftype eq 'ARRAY') {
123        my @arr = @$var;
124        my $isReallyEmpty = ($#arr == -1 ? 1 : 0);
125        return 1 if $isReallyEmpty;
126        $found = 1;
127        foreach (@arr) {
128          #return 0 if defined $_;
129          #return 1 if isEmpty($_);
130          return 0 if !isEmpty($_);
131        }
132    
133      } elsif ($reftype eq 'HASH') {
134        my $empty = 1;
135        $found = 1;
136        foreach (keys %$var) {
137    # TODO: review and fix this!
138    =pod
139          # recursion
140          if (ref $var->{$_} eq 'Set::Object') {
141            print "==========set", "\n";
142            if (isEmpty($var->{$_})) {
143              return 0;
144              #next;
145            }
146          }
147    =cut
148          next if ref $var->{$_} eq 'Set::Object';
149          #return 0 if defined $var->{$_};
150          #return 1 if isEmpty($var->{$_});
151          my $elem_empty = isEmpty($var->{$_});
152          
153    #print "elem: $elem_empty\n";
154          $empty &&= $elem_empty;
155      }      }
156        return $empty;
157        #return 0;
158      
159      } else {
160        $found = 1;
161        return 0 if defined $var;
162      }
163      
164      if (!$found) {
165        print "isEmpty could not parse variable ( ref $ref reftype $reftype )", "\n";
166    }    }
167    
168      #print "EMPTY!!!", "\n";
169    
170    return 1;    return 1;
171      
172  }  }
173    
174  1;  1;

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

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