line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: IDspace.pm 2011-09-29 erick.antezana $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Module : IDspace.pm |
4
|
|
|
|
|
|
|
# Purpose : A mapping between a "local" ID space and a "global" ID space. |
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::IDspace; |
11
|
|
|
|
|
|
|
|
12
|
9
|
|
|
9
|
|
8910
|
use Carp; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
530
|
|
13
|
9
|
|
|
9
|
|
42
|
use strict; |
|
9
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
246
|
|
14
|
9
|
|
|
9
|
|
35
|
use warnings; |
|
9
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
4657
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
19
|
|
|
19
|
0
|
118
|
my $class = shift; |
18
|
19
|
|
|
|
|
26
|
my $self = {}; |
19
|
|
|
|
|
|
|
|
20
|
19
|
|
|
|
|
38
|
$self->{LOCAL_IDSPACE} = ''; # required, scalar (1) |
21
|
19
|
|
|
|
|
25
|
$self->{URI} = ''; # required, scalar (1) |
22
|
19
|
|
|
|
|
22
|
$self->{DESCRIPTION} = undef; # optional scalar (0..1) |
23
|
|
|
|
|
|
|
|
24
|
19
|
|
|
|
|
29
|
bless ($self, $class); |
25
|
19
|
|
|
|
|
37
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 local_idspace |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Usage - print $idspace->local_idspace() or $idspace->local_idspace($local_idspace) |
31
|
|
|
|
|
|
|
Returns - the local ID space (string) |
32
|
|
|
|
|
|
|
Args - the local ID space (string) |
33
|
|
|
|
|
|
|
Function - gets/sets the local ID space |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub local_idspace { |
38
|
10
|
100
|
|
10
|
1
|
29
|
if ($_[1]) { |
39
|
5
|
|
|
|
|
16
|
$_[0]->{LOCAL_IDSPACE} = $_[1]; |
40
|
|
|
|
|
|
|
} else { # get-mode |
41
|
5
|
50
|
|
|
|
17
|
croak 'The local ID space of this ID space is not defined.' if (!defined($_[0]->{LOCAL_IDSPACE})); |
42
|
|
|
|
|
|
|
} |
43
|
10
|
|
|
|
|
26
|
return $_[0]->{LOCAL_IDSPACE}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 uri |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Usage - print $idspace->uri() or $idspace->uri($uri) |
49
|
|
|
|
|
|
|
Returns - the URI (string) of this ID space |
50
|
|
|
|
|
|
|
Args - the URI (string) of this ID space |
51
|
|
|
|
|
|
|
Function - gets/sets the URI of this ID space |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub uri { |
56
|
7
|
100
|
|
7
|
1
|
17
|
if ($_[1]) { |
57
|
5
|
|
|
|
|
11
|
$_[0]->{URI} = $_[1]; |
58
|
|
|
|
|
|
|
} else { # get-mode |
59
|
2
|
50
|
|
|
|
7
|
croak 'The URI of this ID space is not defined.' if (!defined($_[0]->{URI})); |
60
|
|
|
|
|
|
|
} |
61
|
7
|
|
|
|
|
17
|
return $_[0]->{URI}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 description |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Usage - print $idspace->description() or $idspace->description($description) |
67
|
|
|
|
|
|
|
Returns - the idspace description (string) |
68
|
|
|
|
|
|
|
Args - the idspace description (string) |
69
|
|
|
|
|
|
|
Function - gets/sets the idspace description |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub description { |
74
|
7
|
100
|
|
7
|
1
|
16
|
if ($_[1]) { |
75
|
5
|
|
|
|
|
8
|
$_[0]->{DESCRIPTION} = $_[1]; |
76
|
|
|
|
|
|
|
} else { # get-mode |
77
|
2
|
50
|
33
|
|
|
12
|
croak 'Neither the local idspace nor the URI of this idspace is defined.' if (!defined($_[0]->{LOCAL_IDSPACE}) || !defined($_[0]->{URI})); |
78
|
|
|
|
|
|
|
} |
79
|
7
|
|
|
|
|
17
|
return $_[0]->{DESCRIPTION}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 as_string |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Usage - print $idspace->as_string() |
85
|
|
|
|
|
|
|
Returns - returns this idspace (local_idspace uri "description") as string if it is defined; otherwise, undef |
86
|
|
|
|
|
|
|
Args - none |
87
|
|
|
|
|
|
|
Function - returns this idspace as string |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub as_string { |
92
|
21
|
100
|
66
|
21
|
1
|
111
|
if ($_[1] && $_[2]){ |
93
|
12
|
|
|
|
|
32
|
$_[0]->{LOCAL_IDSPACE} = $_[1]; |
94
|
12
|
|
|
|
|
17
|
$_[0]->{URI} = $_[2]; |
95
|
12
|
50
|
|
|
|
27
|
$_[0]->{DESCRIPTION} = $_[3] if ($_[3]); |
96
|
12
|
|
|
|
|
19
|
return; # set mode |
97
|
|
|
|
|
|
|
} else { |
98
|
9
|
50
|
33
|
|
|
56
|
croak 'Neither the local idspace nor the URI of this idspace is defined.' if (!defined($_[0]->{LOCAL_IDSPACE}) || !defined($_[0]->{URI})); |
99
|
9
|
|
|
|
|
40
|
my $result = $_[0]->{LOCAL_IDSPACE}.' '.$_[0]->{URI}; |
100
|
9
|
100
|
66
|
|
|
78
|
$result .= ' "'.$_[0]->{DESCRIPTION}.'"' if (defined $_[0]->{DESCRIPTION} && $_[0]->{DESCRIPTION} ne ''); |
101
|
9
|
100
|
|
|
|
58
|
$result = '' if ($result =~ /^\s*$/); |
102
|
9
|
|
|
|
|
47
|
return $result; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 equals |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Usage - print $idspace->equals($another_idspace) |
109
|
|
|
|
|
|
|
Returns - either 1(true) or 0 (false) |
110
|
|
|
|
|
|
|
Args - the idspace (OBO::Core::IDspace) to compare with |
111
|
|
|
|
|
|
|
Function - tells whether this idspace is equal to the parameter |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub equals { |
116
|
100
|
50
|
33
|
100
|
1
|
187
|
if ($_[1] && eval { $_[1]->isa('OBO::Core::IDspace') }) { |
|
100
|
|
|
|
|
343
|
|
117
|
|
|
|
|
|
|
|
118
|
100
|
50
|
33
|
|
|
285
|
croak 'Neither the local idspace or the URI of this idspace is defined.' if (!defined($_[0]->{LOCAL_IDSPACE}) || !defined($_[0]->{URI})); |
119
|
100
|
50
|
33
|
|
|
246
|
croak 'Neither the local idspace or the URI of this idspace is defined.' if (!defined($_[1]->{LOCAL_IDSPACE}) || !defined($_[1]->{URI})); |
120
|
100
|
|
100
|
|
|
440
|
my $result = ((defined $_[0]->{DESCRIPTION} && defined $_[1]->{DESCRIPTION}) && ($_[0]->{DESCRIPTION} eq $_[1]->{DESCRIPTION})); |
121
|
100
|
|
66
|
|
|
440
|
return $result && (($_[0]->{LOCAL_IDSPACE} eq $_[1]->{LOCAL_IDSPACE}) && |
122
|
|
|
|
|
|
|
($_[0]->{URI} eq $_[1]->{URI})); |
123
|
|
|
|
|
|
|
} else { |
124
|
0
|
|
|
|
|
|
croak "An unrecognized object type (not a OBO::Core::IDspace) was found: '", $_[1], "'"; |
125
|
|
|
|
|
|
|
} |
126
|
0
|
|
|
|
|
|
return 0; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |