File Coverage

blib/lib/OBO/Core/SubsetDef.pm
Criterion Covered Total %
statement 32 33 96.9
branch 10 16 62.5
condition 4 9 44.4
subroutine 8 8 100.0
pod 3 5 60.0
total 57 71 80.2


line stmt bran cond sub pod time code
1             # $Id: SubsetDef.pm 2011-06-06 erick.antezana $
2             #
3             # Module : SubsetDef.pm
4             # Purpose : A subset definition.
5             # License : Copyright (c) 2006-2014 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             package OBO::Core::SubsetDef;
11              
12 9     9   9105 use Carp;
  9         15  
  9         556  
13 9     9   44 use strict;
  9         13  
  9         251  
14 9     9   38 use warnings;
  9         11  
  9         3174  
15              
16             sub new {
17 30     30 0 324 my $class = shift;
18 30         39 my $self = {};
19              
20 30         59 $self->{NAME} = undef; # required
21 30         115 $self->{DESCRIPTION} = undef; # required
22              
23 30         59 bless ($self, $class);
24 30         63 return $self;
25             }
26             =head2 name
27              
28             Usage - print $subset_def->name() or $subset_def->name($name)
29             Returns - the subset def name (string)
30             Args - the subset def name (string)
31             Function - gets/sets the subset def name
32            
33             =cut
34              
35             sub name {
36 109 100   109 0 687 $_[0]->{NAME} = $_[1] if ($_[1]);
37 109         359 return $_[0]->{NAME};
38             }
39              
40             =head2 description
41              
42             Usage - print $subset_def->description() or $subset_def->description($desc)
43             Returns - the subset def description (string)
44             Args - the subset def description (string)
45             Function - gets/sets the synonym description
46            
47             =cut
48              
49             sub description {
50 38 100   38 1 108 $_[0]->{DESCRIPTION} = $_[1] if ($_[1]);
51 38         98 return $_[0]->{DESCRIPTION};
52             }
53              
54             =head2 as_string
55              
56             Usage - $subset_def->as_string() or $subset_def->as_string("GO_SLIM", "GO Slim")
57             Returns - the subset def definition (string)
58             Args - the subset def definition (string)
59             Function - gets/sets the definition of this synonym
60            
61             =cut
62              
63             sub as_string {
64 33 50 66 33 1 255 if ($_[1] && $_[2]){
65 9         1118 $_[0]->{NAME} = $_[1];
66 9         35 $_[0]->{DESCRIPTION} = $_[2];
67             }
68 33         142 return $_[0]->{NAME}.' "'.$_[0]->{DESCRIPTION}.'"';
69             }
70              
71             =head2 equals
72              
73             Usage - print $subset_def->equals($another_subset_def)
74             Returns - either 1 (true) or 0 (false)
75             Args - the subset def definition to compare with
76             Function - tells whether this subset def definition is equal to the given argument (another subset def definition)
77            
78             =cut
79              
80             sub equals {
81 44     44 1 34 my $result = 0;
82 44 50 33     80 if ($_[1] && eval { $_[1]->isa('OBO::Core::SubsetDef') }) {
  44         181  
83            
84 44 50       133 croak 'The name of this subset definition is undefined.' if (!defined($_[0]->{NAME}));
85 44 50       57 croak 'The name of the target subset definition is undefined.' if (!defined($_[1]->{NAME}));
86            
87 44 50       64 croak 'The description of the this subset definition is undefined.' if (!defined($_[0]->{DESCRIPTION}));
88 44 50       66 croak 'The description of the target subset definition is undefined.' if (!defined($_[1]->{DESCRIPTION}));
89            
90 44   33     156 $result = ($_[0]->{NAME} eq $_[1]->{NAME}) && ($_[0]->{DESCRIPTION} eq $_[1]->{DESCRIPTION});
91             } else {
92 0         0 croak "An unrecognized object type (not a OBO::Core::SubsetDef) was found: '", $_[1], "'";
93             }
94 44         103 return $result;
95             }
96              
97             1;
98              
99             __END__