lib/MOSES/MOBY/Def/DataType.pm

filter: Statementstmt 25.3% 19 / 75 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 45.4% 5 / 11 Podpod 50.0% 1 / 2 totaltotal 21.0% 25 / 119 CC 16 SCAR 45.4
CC
16
Cov
18%
toXML
182.0
_attr_prop
12.0
_accessible
6.0
CRAP 93.3
« lib/MOSES/MOBY/Def/Service.pm ↑ Summary lib/MOSES/MOBY/Async.pm »
1 #-----------------------------------------------------------------
2 # MOSES::MOBY::Def::DataType
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: DataType.pm,v 1.4 2008/04/29 19:41:17 kawas Exp $
8 #-----------------------------------------------------------------
9  
10 package MOSES::MOBY::Def::DataType;
11 1 ▶use base qw( MOSES::MOBY::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use MOSES::MOBY::Def::Relationship;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # add versioning to this module
17 1 ▶use vars qw /$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/;
19  
20 =head1 NAME
21  
22 MOSES::MOBY::Def::DataType - a definition of BioMoby data type
23  
24 =head1 SYNOPSIS
25  
26 use MOSES::MOBY::Def::DataType;
27  
28 # create a new data type
29 my $datatype = new MOSES::MOBY::Def::DataType
30 ( name => 'MySequence',
31 authority => 'www.tulsoft.org',
32 email => 'george.bush@shame.gov',
33 description => 'Good moooorning, sequence!',
34 parent => 'DNASequence',
35 children => ( {memberName => 'annotation', datatype => 'Feature'} ),
36 );
37  
38 # get the name of this data type
39 print $datatype->name;
40  
41 # set new authority
42 $datatype->authority ('www.biomoby.org');
43
44 # get this data type in XML
45 my $xml = $datatype->toXML;
46 print $xml->toString (2);
47  
48 =cut
49  
50 =head1 DESCRIPTION
51  
52 A container representing a data type used in the Moby registry (in the
53 BioMoby speak it is called I<Object Class>). The Moby data types are
54 used to specify what types of inputs and outputs are needed or
55 produced by Moby services.
56  
57 This object does not carry real data but rather a definition
58 (metadata) of one of the most important BioMoby entities - a data
59 type.
60  
61 =head1 AUTHORS
62  
63 Edward Kawas (edward.kawas [at] gmail [dot] com)
64 Martin Senger (martin.senger [at] gmail [dot] com)
65  
66  
67 =cut
68  
69 #-----------------------------------------------------------------
70 # A list of allowed attribute names. See MOSES::MOBY::Base for details.
71 #-----------------------------------------------------------------
72  
73 =head1 ACCESSIBLE ATTRIBUTES
74  
75 Details are in L<MOSES::MOBY::Base>. Here just a list of them:
76  
77 =over
78  
79 =item B<name>
80  
81 A name of this data type. For example: C<DNASequence>.
82  
83 =item B<authority>
84  
85 =item B<email>
86  
87 =item B<description>
88  
89 =item B<parent>
90  
91 A name of a parent data type.
92  
93 =item B<children>
94  
95 A list of relationships to the children data types. Must be of type
96 C<MOSES::MOBY::Def::Relationship>.
97  
98 =item B<lsid>
99  
100 =back
101  
102 =cut
103  
104 {
105 my %_allowed =
106 (
107 name => { type => MOSES::MOBY::Base->STRING,
108 0 ▶ post => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
109 0 my ($self) = shift;
110 $self->{module_name} =
111 0 $self->datatype2module ($self->{name}) } },
112 parent => { type => MOSES::MOBY::Base->STRING,
113 0 ▶ post => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
114 0 my ($self) = shift;
115 $self->{module_parent} =
116 0 $self->datatype2module ($self->{parent}) } },
117 1 authority => undef,
118 email => undef,
119 description => undef,
120 children => {type => 'MOSES::MOBY::Def::Relationship', is_array => 1},
121 lsid => undef,
122  
123 # used internally (but cannot start with underscore - Template would ignore them)
124 module_name => undef,
125 module_parent => undef,
126 );
127  
128 0 ▶ sub _accessible {
Subroutine _accessible: not called CC=2 SCAR=17.9
129 0 my ($self, $attr) = @_;
130 0 ▶ exists $_allowed{$attr} or $self->SUPER::_accessible ($attr);
Branch: 1 branch
BranchTrueFalseTotal
exists $_allowed{$attr} or $self->SUPER::_accessible($attr) 0 0 0
131 }
132 0 ▶ sub _attr_prop {
Subroutine _attr_prop: not called CC=3 SCAR=24.8
133 0 my ($self, $attr_name, $prop_name) = @_;
134 0 my $attr = $_allowed {$attr_name};
135 0 ▶ return ref ($attr) ? $attr->{$prop_name} : $attr if $attr;
Branch: 2 branches
BranchTrueFalseTotal
if $attr 0 0 0
ref $attr ? : 0 0 0
136 0 return $self->SUPER::_attr_prop ($attr_name, $prop_name);
137 }
138 }
139  
140 #-----------------------------------------------------------------
141  
142 =head1 SUBROUTINES
143  
144 =cut
145  
146 #-----------------------------------------------------------------
147 # init
148 #-----------------------------------------------------------------
149 1 ▶sub init {
Subroutine init: not called CC=1 SCAR=4.1
Pod documented
150 0 my ($self) = shift;
151 0 $self->SUPER::init();
152 0 $self->children ([]);
153 # $self->parent ('Object');
154 0 $self->parent ('');
155 }
156  
157 #-----------------------------------------------------------------
158 # toXML
159 #-----------------------------------------------------------------
160 0 ▶sub toXML {
Subroutine toXML: not called CC=13 SCAR=52.0
Pod undocumented
161 0 my $self = shift;
162 0 my $root = $self->createXMLElement('registerObjectClass');
163
164 # objectType
165 0 my $node = $self->createXMLElement('objectType');
166 0 ▶ $node->appendTextNode ($self->name) if $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->name 0 0 0
167 0 $root->addChild ($node);
168
169 # description
170 0 $node = $self->createXMLElement('Description');
171 0 ▶ $node->addChild (XML::LibXML::CDATASection->new ($self->description)) if $self->description;
Branch: 1 branch
BranchTrueFalseTotal
if $self->description 0 0 0
172 0 $root->addChild ($node);
173
174 # authURI
175 0 $node = $self->createXMLElement('authURI');
176 0 ▶ $node->appendTextNode ($self->authority) if $self->authority;
Branch: 1 branch
BranchTrueFalseTotal
if $self->authority 0 0 0
177 0 $root->addChild ($node);
178
179 # email
180 0 $node = $self->createXMLElement('contactEmail');
181 0 ▶ $node->appendTextNode ($self->email) if $self->email;
Branch: 1 branch
BranchTrueFalseTotal
if $self->email 0 0 0
182 0 $root->addChild ($node);
183
184 # parent - isa relationship type
185 0 $node = $self->createXMLElement('Relationship');
186 0 $self->setXMLAttribute ($node, 'relationshipType', ISA);
187 0 my $type = $self->createXMLElement('objectType');
188 0 ▶ $type->appendTextNode ( $self->parent || 'Object' );
Condition0%0/2
$self->parent || 'Object'
l!l
00
MC/DC0%0/1
$self->parent || 'Object'
$self->parent
Truth table0%0/2
A
A= $self->parent
Aresult
11
00
189 0 $node->addChild ($type);
190 0 $root->addChild ($node);
191  
192 # children - has|hasa relationship types
193 0 my $hasNode = $self->createXMLElement('Relationship');
194 0 $self->setXMLAttribute ($hasNode, 'relationshipType', HAS);
195
196 0 my $hasaNode = $self->createXMLElement('Relationship');
197 0 $self->setXMLAttribute ($hasaNode, 'relationshipType', HASA);
198
199 0 my $hasa_count = 0;
200 0 my $has_count = 0;
201 0 foreach my $relation (@{ $self->children }) {
202 0 ▶ if ($relation->relationship eq HASA) {
Branch: 2 branches
BranchTrueFalseTotal
if ($relation->relationship eq 'HASA') { } 0 0 0
elsif ($relation->relationship eq 'HAS') { } 0 0 0
203 0 $hasa_count++;
204 0 my $type = $self->createXMLElement('objectType');
205 0 $self->setXMLAttribute ($type, 'articleName', $relation->original_memberName);
206 0 ▶ $type->appendTextNode ( $relation->datatype || 'Object' );
Condition0%0/2
$relation->datatype || 'Object'
l!l
00
MC/DC0%0/1
$relation->datatype || 'Object'
$relation->datatype
Truth table0%0/2
A
A= $relation->datatype
Aresult
11
00
207 0 $hasaNode->addChild ($type);
208 } elsif ($relation->relationship eq HAS) {
209 0 $has_count++;
210 0 my $type = $self->createXMLElement('objectType');
211 0 $self->setXMLAttribute ($type, 'articleName', $relation->original_memberName);
212 0 ▶ $type->appendTextNode ($relation->datatype || 'Object' );
Condition0%0/2
$relation->datatype || 'Object'
l!l
00
MC/DC0%0/1
$relation->datatype || 'Object'
$relation->datatype
Truth table0%0/2
A
A= $relation->datatype
Aresult
11
00
213 0 $hasNode->addChild ($type);
214 }
215 }
216 0 ▶ $root->addChild ($hasaNode) if $hasa_count > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $hasa_count > 0 0 0 0
217 0 ▶ $root->addChild ($hasNode) if $has_count > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $has_count > 0 0 0 0
218
219 0 return $root;
220 }
221  
222 1 1;
223 __END__
« lib/MOSES/MOBY/Def/Service.pm ↑ Summary lib/MOSES/MOBY/Async.pm »