lib/MOSES/MOBY/Def/Relationship.pm

filter: Statementstmt 62.7% 27 / 43 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 8 / 14 Podpod 100% 1 / 1 totaltotal 54.5% 36 / 66 CC 5 SCAR 13.6
CC
5
Cov
53%
_attr_prop
12.0
_accessible
6.0
_check_relationship
4.0
CRAP 3.9
« lib/MOSES/MOBY/Data/String.pm ↑ Summary lib/MOSES/MOBY/Service/ServiceBase.pm »
1 #-----------------------------------------------------------------
2 # MOSES::MOBY::Def::Relationship
3 # Author: Edward Kawas <edward.kawas@gmail.com>,
4 # Martin Senger <martin.senger@gmail.com>
5 # For copyright and disclaimer see below.
6 #
7 # $Id: Relationship.pm,v 1.4 2008/04/29 19:41:31 kawas Exp $
8 #-----------------------------------------------------------------
9  
10 package MOSES::MOBY::Def::Relationship;
11 1 ▶use base qw( MOSES::MOBY::Base Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use vars qw( @EXPORT %ALLOWED_TYPES );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # add versioning to this module
16 1 ▶use vars qw /$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/;
18  
19 # relationship types
20 1 ▶use constant ISA => 'ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use constant HASA => 'HASA';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use constant HAS => 'HAS';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 @EXPORT = qw(
26 ISA
27 HASA
28 HAS);
29 }
30  
31 =head1 NAME
32  
33 MOSES::MOBY::Def::Relationship - a definition of relationships between Moby data types
34  
35 =head1 SYNOPSIS
36  
37 use MOSES::MOBY::Def::Relationship;
38 # create a new relationship
39 my $relationship = new MOSES::MOBY::Def::Relationship
40 ( memberName => 'myArticleName',
41 datatype => 'DNASequence',
42 raletionship => HASA
43 );
44
45 # get the article name of the datatype in this relationship
46 print $relationship->memberName;
47
48 # set the article name of the datatype in this relationship
49 $relationship->memberName ('myNewArticleName');
50  
51 =cut
52  
53 =head1 DESCRIPTION
54  
55 A container representing a relationship of a BioMoby data type.
56  
57 =head1 AUTHORS
58  
59 Edward Kawas (edward.kawas [at] gmail [dot] com)
60 Martin Senger (martin.senger [at] gmail [dot] com)
61  
62 =cut
63  
64 #-----------------------------------------------------------------
65 # A list of allowed attribute names. See MOSES::MOBY::Base for details.
66 #-----------------------------------------------------------------
67  
68 =head1 ACCESSIBLE ATTRIBUTES
69  
70 Details are in L<MOSES::MOBY::Base>. Here just a list of them:
71  
72 =over
73  
74 =item B<memberName>
75  
76 A name how this relationship is known (an I<article name> in the
77 BioMoby speak).
78  
79 =item B<datatype>
80  
81 A name of a data type that is related by this relationship.
82  
83 =item B<relationship>
84  
85 A type of this relationship. Can be C<HAS>, C<HASA> or C<ISA>.
86  
87 =back
88  
89 =cut
90  
91 {
92 my %_allowed =
93 (
94 memberName => { type => MOSES::MOBY::Base->STRING,
95 0 ▶ post => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
96 0 my ($self) = shift;
97 0 $self->{original_memberName} = $self->{memberName};
98 $self->{memberName} = $self->escape_name ($self->{original_memberName})
99 0 } },
100 datatype => { type => MOSES::MOBY::Base->STRING,
101 0 ▶ post => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
102 0 my ($self) = shift;
103 $self->{module_datatype} =
104 0 $self->datatype2module ($self->{datatype}) } },
105 1 relationship => { type => MOSES::MOBY::Base->STRING,
106 post => \&_check_relationship },
107  
108 # used internally (but cannot start with underscore - Template would ignore it)
109 module_datatype => undef,
110 original_memberName => undef,
111 );
112  
113 0 ▶ sub _accessible {
Subroutine _accessible: not called CC=2 SCAR=17.9
114 0 my ($self, $attr) = @_;
115 0 ▶ exists $_allowed{$attr} or $self->SUPER::_accessible ($attr);
Branch: 1 branch
BranchTrueFalseTotal
exists $_allowed{$attr} or $self->SUPER::_accessible($attr) 0 0 0
116 }
117 0 ▶ sub _attr_prop {
Subroutine _attr_prop: not called CC=3 SCAR=24.8
118 0 my ($self, $attr_name, $prop_name) = @_;
119 0 my $attr = $_allowed {$attr_name};
120 0 ▶ return ref ($attr) ? $attr->{$prop_name} : $attr if $attr;
Branch: 2 branches
BranchTrueFalseTotal
if $attr 0 0 0
ref $attr ? : 0 0 0
121 0 return $self->SUPER::_attr_prop ($attr_name, $prop_name);
122 }
123 }
124  
125 #-----------------------------------------------------------------
126 # Checking relationship type.
127 #-----------------------------------------------------------------
128 1 ▶sub _check_relationship {
Subroutine _check_relationship: not called CC=2 SCAR=14.0
129 0 my ($self, $attr) = @_;
130 $self->throw ('Invalid relationship type: ' . $self->relationship)
131 0 ▶ unless exists $ALLOWED_TYPES{$self->relationship};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $MOSES::MOBY::Def::Relationship::ALLOWED_TYPES{$self->relationship} 0 0 0
132 }
133  
134 1 %ALLOWED_TYPES = (HAS => 1, HASA => 1, ISA => 1);
135  
136 #-----------------------------------------------------------------
137 # init
138 #-----------------------------------------------------------------
139 0 ▶sub init {
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
140 0 my ($self) = shift;
141 0 $self->SUPER::init();
142 0 $self->relationship (HASA);
143 }
144  
145 1 1;
146 __END__
« lib/MOSES/MOBY/Data/String.pm ↑ Summary lib/MOSES/MOBY/Service/ServiceBase.pm »