File Coverage

blib/lib/OBO/Core/SynonymTypeDef.pm
Criterion Covered Total %
statement 39 40 97.5
branch 16 24 66.6
condition 9 15 60.0
subroutine 9 9 100.0
pod 4 6 66.6
total 77 94 81.9


line stmt bran cond sub pod time code
1             # $Id: SynonymTypeDef.pm 2011-06-06 erick.antezana $
2             #
3             # Module : SynonymTypeDef.pm
4             # Purpose : A synonym type 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::SynonymTypeDef;
11              
12 9     9   5744 use Carp;
  9         17  
  9         507  
13 9     9   43 use strict;
  9         12  
  9         235  
14 9     9   35 use warnings;
  9         12  
  9         3570  
15              
16             sub new {
17 18     18 0 70 my $class = shift;
18 18         23 my $self = {};
19              
20 18         30 $self->{NAME} = undef; # required
21 18         21 $self->{DESCRIPTION} = undef; # required
22 18         16 $self->{SCOPE} = undef; # optional: The scope specifier indicates the default scope for any synonym that has this type.
23              
24 18         30 bless ($self, $class);
25 18         32 return $self;
26             }
27             =head2 name
28              
29             Usage - print $synonym_type_def->name() or $synonym_type_def->name($name)
30             Returns - the synonym type name (string)
31             Args - the synonym type name (string)
32             Function - gets/sets the synonym type name
33            
34             =cut
35              
36             sub name {
37 24 100   24 0 74 $_[0]->{NAME} = $_[1] if ($_[1]);
38 24         92 return $_[0]->{NAME};
39             }
40              
41             =head2 description
42              
43             Usage - print $synonym_type_def->description() or $synonym_type_def->description($desc)
44             Returns - the synonym description (string)
45             Args - the synonym description (string)
46             Function - gets/sets the synonym description
47            
48             =cut
49              
50             sub description {
51 10 100   10 1 33 $_[0]->{DESCRIPTION} = $_[1] if ($_[1]);
52 10         22 return $_[0]->{DESCRIPTION};
53             }
54              
55             =head2 scope
56              
57             Usage - print $synonym_type_def->scope() or $synonym_type_def->scope($scope)
58             Returns - the scope of this synonym type definition (string)
59             Args - the scope of this synonym type definition (string)
60             Function - gets/sets the scope of this synonym type definition
61            
62             =cut
63              
64             sub scope {
65 10 100   10 1 32 $_[0]->{SCOPE} = $_[1] if ($_[1]);
66 10         26 return $_[0]->{SCOPE};
67             }
68              
69             =head2 as_string
70              
71             Usage - $synonym_type_def->as_string() or $synonym_type_def->as_string("UK_SPELLING", "British spelling", "EXACT")
72             Returns - the synonym type definition (string)
73             Args - the synonym type definition (string)
74             Function - gets/sets the definition of this synonym
75            
76             =cut
77              
78             sub as_string {
79 14 50 66 14 1 102 if ($_[1] && $_[2]){
80 11         27 $_[0]->{NAME} = $_[1];
81 11         17 $_[0]->{DESCRIPTION} = $_[2];
82 11 50       30 $_[0]->{SCOPE} = $_[3] if ($_[3]);
83             }
84 14         44 my $result = $_[0]->{NAME}." \"".$_[0]->{DESCRIPTION}."\"";
85 14         22 my $scope = $_[0]->{SCOPE};
86 14 50       49 $result .= (defined $scope)?" ".$scope:"";
87             }
88              
89             =head2 equals
90              
91             Usage - print $synonym_type_def->equals($another_synonym_type_def)
92             Returns - either 1 (true) or 0 (false)
93             Args - the synonym type definition (OBO::Core::SynonymTypeDef) to compare with
94             Function - tells whether this synonym type definition is equal to the given argument (another synonym type definition)
95            
96             =cut
97              
98             sub equals {
99 95     95 1 86 my $result = 0;
100 95 50 33     197 if ($_[1] && eval { $_[1]->isa('OBO::Core::SynonymTypeDef') }) {
  95         378  
101              
102 95 50       190 croak 'The name of this synonym type definition is undefined.' if (!defined($_[0]->{NAME}));
103 95 50       162 croak 'The name of the target synonym type definition is undefined.' if (!defined($_[1]->{NAME}));
104            
105 95 50       157 croak "The description of the this ($_[0]->{NAME}) synonym type definition is undefined." if (!defined($_[0]->{DESCRIPTION}));
106 95 50       150 croak "The description of the target ($_[1]->{NAME}) synonym type definition is undefined." if (!defined($_[1]->{DESCRIPTION}));
107            
108 95   66     255 $result = ($_[0]->{NAME} eq $_[1]->{NAME}) && ($_[0]->{DESCRIPTION} eq $_[1]->{DESCRIPTION});
109 95 100 66     463 $result = $result && ($_[0]->{SCOPE} eq $_[1]->{SCOPE}) if (defined $_[0]->{SCOPE} && defined $_[1]->{SCOPE}); # TODO Future improvement, consider case: scope_1 undefined and scope_2 defined!
      66        
110             } else {
111 0         0 croak "An unrecognized object type (not a OBO::Core::SynonymTypeDef) was found: '", $_[1], "'";
112             }
113 95         302 return $result;
114             }
115              
116             1;
117              
118             __END__