File Coverage

blib/lib/OBO/Util/SubsetDefMap.pm
Criterion Covered Total %
statement 30 32 93.7
branch 7 12 58.3
condition 1 3 33.3
subroutine 5 5 100.0
pod 1 1 100.0
total 44 53 83.0


line stmt bran cond sub pod time code
1             # $Id: SubsetDefMap.pm 2014-10-29 erick.antezana $
2             #
3             # Module : SubsetDefMap.pm
4             # Purpose : Subset Definition Map.
5             # License : Copyright (c) 2006-2015 by Erick Antezana. All rights reserved.
6             # This program is free software; you can redistribute it and/or
7             # modify it under the same terms as Perl itself.
8             # Contact : Erick Antezana
9             #
10              
11             package OBO::Util::SubsetDefMap;
12              
13             #
14             # key = subset name
15             # value = subset def
16             #
17              
18             our @ISA = qw(OBO::Util::Map);
19 8     8   4776 use OBO::Util::Map;
  8         21  
  8         211  
20              
21 8     8   46 use Carp;
  8         14  
  8         404  
22 8     8   37 use strict;
  8         14  
  8         152  
23 8     8   35 use warnings;
  8         14  
  8         1738  
24              
25             =head2 equals
26              
27             Usage - $map->equals($another_subset_def_map)
28             Returns - true or false
29             Args - the set (OBO::Util::SubsetDefMap) to compare with
30             Function - tells whether this set is equal to the given one
31            
32             =cut
33             sub equals {
34 17     17 1 32 my $self = shift;
35 17         20 my $result = 0; # I initially guess they're NOT identical
36 17 50       37 if (@_) {
37 17         19 my $other_map = shift;
38 17 50 33     71 if ($other_map && eval { $other_map->isa('OBO::Util::SubsetDefMap') }) {
  17         89  
39 17 100       45 if ($self->size() == $other_map->size()) {
40 9         10 my %cmp = map { $_ => 1 } sort keys %{$self->{MAP}};
  37         69  
  9         31  
41 9         30 for my $key ($other_map->key_set()->get_set()) {
42 37 50       75 last unless exists $cmp{$key};
43 37 50       97 last unless $self->{MAP}->{$key}->equals($other_map->get($key)); # 'equals'
44 37         75 delete $cmp{$key};
45             }
46 9 50       101 if (%cmp) {
47             #warn "they don't have the same keys or values\n";
48 0         0 $result = 0;
49             } else {
50             #warn "they have the same keys or values\n";
51 9         16 $result = 1;
52             }
53             } else {
54 8         13 $result = 0;
55             }
56             } else {
57 0         0 croak "An unrecognized object type (not a OBO::Util::SubsetDefMap) was found: '", $other_map, "'";
58             }
59             }
60 17         64 return $result;
61             }
62              
63             1;
64              
65             __END__