lib/MOSES/MOBY/Def/ServiceType.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 77 CC 8 SCAR 30.0
CC
8
Cov
0%
toXML
42.0
_attr_prop
12.0
_accessible
2.0
CRAP 20.0
1 #-----------------------------------------------------------------
2 # MOSES::MOBY::Def::ServiceType
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: ServiceType.pm,v 1.4 2008/04/29 19:41:46 kawas Exp $
8 #-----------------------------------------------------------------
9 package MOSES::MOBY::Def::ServiceType;
10 use base qw( MOSES::MOBY::Base );
11 use XML::LibXML;
12 use strict;
13  
14 # add versioning to this module
15 use vars qw /$VERSION/;
16 $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/;
17  
18 =head1 NAME
19  
20 MOSES::MOBY::Def::ServiceType - a BioMoby service type definition
21  
22 =head1 SYNOPSIS
23  
24 use MOSES::MOBY::Def::ServiceType;
25 # create a BioMoby service type
26 my $s_type = new MOSES::MOBY::Def::ServiceType
27 ( name => 'Homology',
28 );
29  
30 # get an LSID of a service type
31 print $s_type->lsid;
32  
33 # get the service type details as a string
34 print $s_type->toString;
35
36 # get the service type as a string of XML
37 #(same format used to register the service type)
38 print $s_type->toXML->toString (1);
39  
40 =cut
41  
42 =head1 DESCRIPTION
43  
44 This module contains a definition of a BioMoby Service Type. With
45 this module, you can create a service type, set its details and then
46 use the output from toXML to register this service type with a
47 mobycentral registry.
48  
49 =head1 AUTHORS
50  
51 Edward Kawas (edward.kawas [at] gmail [dot] com)
52 Martin Senger (martin.senger [at] gmail [dot] com)
53  
54 =cut
55  
56 #-----------------------------------------------------------------
57 # A list of allowed attribute names. See MOSES::MOBY::Base for details.
58 #-----------------------------------------------------------------
59  
60 =head1 ACCESSIBLE ATTRIBUTES
61  
62 Details are in L<MOSES::MOBY::Base>. Here just a list of them:
63  
64 =over
65  
66 =item B<name>
67  
68 =item B<authority>
69  
70 =item B<email>
71  
72 =item B<description>
73  
74 =item B<parent>
75  
76 =item B<lsid>
77  
78 =back
79  
80 =cut
81  
82 {
83 my %_allowed =
84 (
85 name => undef,
86 authority => undef,
87 email => undef,
88 description => undef,
89 parent => undef,
90 lsid => undef,
91 );
92  
93 sub _accessible {
94 my ( $self, $attr ) = @_;
95 exists $_allowed{$attr} or $self->SUPER::_accessible($attr);
96 }
97  
98 sub _attr_prop {
99 my ( $self, $attr_name, $prop_name ) = @_;
100 my $attr = $_allowed{$attr_name};
101 return ref($attr) ? $attr->{$prop_name} : $attr if $attr;
102 return $self->SUPER::_attr_prop( $attr_name, $prop_name );
103 }
104 }
105  
106 #-----------------------------------------------------------------
107  
108 =head1 SUBROUTINES
109  
110 =cut
111  
112 #-----------------------------------------------------------------
113 # init
114 #-----------------------------------------------------------------
115 sub init {
116 my ($self) = shift;
117 $self->SUPER::init();
118 $self->parent ('Service');
119 }
120  
121 #-----------------------------------------------------------------
122 # toXML
123 #-----------------------------------------------------------------
124 sub toXML {
125 my $self = shift;
126 my $root = $self->createXMLElement ('registerServiceType');
127
128 # service type name
129 my $node = $self->createXMLElement ("serviceType");
130 $node->appendTextNode ($self->name) if $self->name;
131 $root->addChild ($node);
132
133 # email
134 $node = $self->createXMLElement ("contactEmail");
135 $node->appendTextNode ($self->email) if $self->email;
136 $root->addChild ($node);
137
138 # authURI
139 $node = $self->createXMLElement ("authURI");
140 $node->appendTextNode ($self->authority) if $self->authority;
141 $root->addChild ($node);
142
143 # description
144 $node = $self->createXMLElement ("Description");
145 $node->addChild (XML::LibXML::CDATASection->new ($self->description)) if $self->description;
146 $root->addChild ($node);
147
148 # relationship
149 $node = $self->createXMLElement ("Relationship");
150 $node->setAttribute ("relationshipType", "ISA");
151 my $type = $self->createXMLElement ("serviceType");
152 $type->appendTextNode ($self->parent) if $self->parent;
153 $node->addChild ($type);
154 $root->addChild ($node);
155  
156 return $root;
157 }
158  
159 1;
160 __END__