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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri Nov 29 04:49:30 2002 UTC (21 years, 7 months ago) by joko
Branch: MAIN
+ initial check-in

1 joko 1.1 ## --------------------------------------------------------------------------------
2     ## $Id: Common.pm,v 1.1 2002/10/10 03:26:00 cvsjoko Exp $
3     ## --------------------------------------------------------------------------------
4     ## $Log: Common.pm,v $
5     ## --------------------------------------------------------------------------------
6    
7    
8     package Data::Compare::Struct;
9    
10     use strict;
11     use warnings;
12    
13     require Exporter;
14     our @ISA = qw( Exporter );
15     our @EXPORT_OK = qw(
16     &getRelations
17     &getDifference
18     &isEmpty
19     );
20    
21     use Data::Dumper;
22    
23     sub getRelations {
24     my $a_ref = shift;
25     my $b_ref = shift;
26     my @a = @{$a_ref};
27     my @b = @{$b_ref};
28    
29     my @isect = my @diff = my @union = ();
30     my $e;
31     my %count;
32    
33     foreach $e (@a, @b) { $count{$e}++ }
34    
35     foreach $e (keys %count) {
36     push(@union, $e);
37     push @{ $count{$e} == 2 ? \@isect : \@diff }, $e;
38     }
39    
40     # bugfix: a diff is no diff if we don't even have an isect
41     @diff = undef if !@isect;
42    
43     my $result = {
44     union => \@union,
45     isect => \@isect,
46     diff => \@diff,
47     };
48    
49     return $result;
50    
51     }
52    
53     sub getDifference {
54     my $res = getRelations(shift, shift);
55     return $res->{diff};
56     }
57    
58     sub isEmpty {
59     my $var = shift;
60     my $reftype = attributes::reftype($var);
61    
62     if ($reftype eq 'HASH') {
63     foreach (keys %$var) {
64     return 0 if defined $var->{$_};
65     }
66    
67     } elsif ($reftype eq 'ARRAY') {
68     foreach (@$var) {
69     return 0 if defined $_;
70     }
71     }
72    
73     return 1;
74     }
75    
76     1;

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