lib/MOSES/MOBY/Data/ProvisionInformation.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 69 CC 10 SCAR 36.6
CC
10
Cov
0%
toXML
72.0
_attr_prop
12.0
_accessible
2.0
CRAP 38.9
1 #-----------------------------------------------------------------
2 # MOSES::MOBY::Data::ProvisionInformation
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: ProvisionInformation.pm,v 1.4 2008/04/29 19:35:57 kawas Exp $
8 #-----------------------------------------------------------------
9  
10 package MOSES::MOBY::Data::ProvisionInformation;
11 use base ("MOSES::MOBY::Base");
12 use MOSES::MOBY::Tags;
13 use strict;
14  
15 # add versioning to this module
16 use vars qw /$VERSION/;
17 $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/;
18  
19 =head1 NAME
20  
21 MOSES::MOBY::Data::ProvisionInformation - a provision information block (PIB)
22  
23 =head1 SYNOPSIS
24  
25 use MOSES::MOBY::Data::ProvisionInformation;
26 my $provision = new MOSES::MOBY::Data::ProvisionInformation
27 ( dbComment => 'a comment here',
28 dbName => 'myDBname',
29 dbVersion => 'myVersion',
30 );
31
32 # get the version
33 print $provision->dbVersion();
34  
35 # add software specific info
36 $provision->softwareComment ('a comment here');
37 print $provision->softwareComment();
38  
39 # add a comment about your service
40 $provision->serviceComment ('a comment here');
41
42 # retrieve an XML representation of the PIB
43 print $provision->toXML->toString (2);
44  
45 =cut
46  
47 =head1 DESCRIPTION
48  
49 This module encapsulates a Moby PIB, thus allowing you to create a
50 syntacticly correct PIB block. For more information regarding the PIB
51 block, please visit the biomoby.org website and read the Moby-S API.
52  
53 =head1 AUTHORS
54  
55 Edward Kawas (edward.kawas [at] gmail [dot] com)
56 Martin Senger (martin.senger [at] gmail [dot] com)
57  
58 =cut
59  
60 #-----------------------------------------------------------------
61 # A list of allowed attribute names. See MOSES::MOBY::Base for details.
62 #-----------------------------------------------------------------
63  
64 =head1 ACCESSIBLE ATTRIBUTES
65  
66 Details are in L<MOSES::MOBY::Base>. Here just a list of them. All of them
67 are of type string.
68  
69 =over
70  
71 =item B<softwareName>
72  
73 =item B<softwareVersion>
74  
75 =item B<softwareComment>
76  
77 =item B<dbName>
78  
79 =item B<dbVersion>
80  
81 =item B<dbComment>
82  
83 =item B<serviceComment>
84  
85 =back
86  
87 =cut
88  
89 {
90 my %_allowed =
91 (
92 softwareName => undef,
93 softwareVersion => undef,
94 softwareComment => undef,
95 dbName => undef,
96 dbVersion => undef,
97 dbComment => undef,
98 serviceComment => undef,
99 );
100  
101 sub _accessible {
102 my ($self, $attr) = @_;
103 exists $_allowed{$attr} or $self->SUPER::_accessible ($attr);
104 }
105 sub _attr_prop {
106 my ($self, $attr_name, $prop_name) = @_;
107 my $attr = $_allowed {$attr_name};
108 return ref ($attr) ? $attr->{$prop_name} : $attr if $attr;
109 return $self->SUPER::_attr_prop ($attr_name, $prop_name);
110 }
111 }
112  
113 #-----------------------------------------------------------------
114  
115 =head1 SUBROUTINES
116  
117 =cut
118  
119 #-----------------------------------------------------------------
120 # toXML
121 #-----------------------------------------------------------------
122  
123 =head2 toXML
124  
125 Return an XML::LibXML::Element representing this data object.
126  
127 =cut
128  
129 sub toXML {
130 my $self = shift;
131 $self->increaseXMLCounter;
132  
133 my $root =
134 XML::LibXML::Element->new (PROVISIONINFORMATION);
135 $root->setNamespace (MOBY_XML_NS, MOBY_XML_NS_PREFIX);
136  
137 my $software = $root->addNewChild (MOBY_XML_NS, SERVICESOFTWARE);
138 $software->setAttributeNS (MOBY_XML_NS, SOFTWARENAME, $self->softwareName)
139 if $self->softwareName;
140 $software->setAttributeNS (MOBY_XML_NS, SOFTWAREVERSION, $self->softwareVersion)
141 if $self->softwareVersion;
142 $software->setAttributeNS (MOBY_XML_NS, SOFTWARECOMMENT, $self->softwareComment)
143 if $self->softwareComment;
144  
145 my $db = $root->addNewChild (MOBY_XML_NS, SERVICEDATABASE);
146 $db->setAttributeNS (MOBY_XML_NS, DATABASENAME, $self->dbName)
147 if $self->dbName;
148 $db->setAttributeNS (MOBY_XML_NS, DATABASEVERSION, $self->dbVersion)
149 if $self->dbVersion;
150 $db->setAttributeNS (MOBY_XML_NS, DATABASECOMMENT, $self->dbComment)
151 if $self->dbComment;
152
153 $root->appendTextChild (SERVICECOMMENT, $self->serviceComment)
154 if $self->serviceComment;
155  
156 # return it (TBD: cleaning namespaces happens several times...)
157 return $self->closeXML ($root);
158 }
159  
160 1;
161  
162 __END__