| 1 | #----------------------------------------------------------------- | ||||||||||||||
| 2 | # MOSES::MOBY::Def::Service | ||||||||||||||
| 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: Service.pm,v 1.5 2009/08/27 19:39:26 kawas Exp $ | ||||||||||||||
| 8 | #----------------------------------------------------------------- | ||||||||||||||
| 9 | package MOSES::MOBY::Def::Service; | ||||||||||||||
| 10 | 1 | ▶ | use base qw( MOSES::MOBY::Base ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use XML::LibXML; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | # add versioning to this module | ||||||||||||||
| 15 | 1 | ▶ | use vars qw /$VERSION/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 1 | $VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /: (\d+)\.(\d+)/; | |||||||||||||
| 17 | |||||||||||||||
| 18 | =head1 NAME | ||||||||||||||
| 19 | |||||||||||||||
| 20 | MOSES::MOBY::Def::Service - a BioMoby service definition | ||||||||||||||
| 21 | |||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||
| 23 | |||||||||||||||
| 24 | use MOSES::MOBY::Def::MobyService; | ||||||||||||||
| 25 | |||||||||||||||
| 26 | # create a new BioMoby service definition | ||||||||||||||
| 27 | my $service = new MOSES::MOBY::Def::Service | ||||||||||||||
| 28 | ( name => 'myService', | ||||||||||||||
| 29 | authority => 'www.tulsoft.org', | ||||||||||||||
| 30 | email => 'george.bush@shame.gov', | ||||||||||||||
| 31 | description => 'Hello world service!', | ||||||||||||||
| 32 | url => 'http://my.service.com/endpoint', | ||||||||||||||
| 33 | signatureURL=> 'http://my.service.com/path/to/rdf,' | ||||||||||||||
| 34 | category => 'moby', | ||||||||||||||
| 35 | type => 'retrival', | ||||||||||||||
| 36 | inputs => ( {memberName => 'annotation', datatype => 'Feature'} ), | ||||||||||||||
| 37 | outputs => ( {memberName => 'annotation', datatype => 'Feature'} ), | ||||||||||||||
| 38 | secondarys => ( {memberName => 'annotation', datatype => 'Feature'} ), | ||||||||||||||
| 39 | ); | ||||||||||||||
| 40 | |||||||||||||||
| 41 | # get the LSID of this service | ||||||||||||||
| 42 | print $service->lsid; | ||||||||||||||
| 43 | |||||||||||||||
| 44 | # get the service details as a string | ||||||||||||||
| 45 | print $service->toString; | ||||||||||||||
| 46 | |||||||||||||||
| 47 | # get the service as a string of XML | ||||||||||||||
| 48 | # (same format used to register the service) | ||||||||||||||
| 49 | my $xml = $service->toXML->toString (1); | ||||||||||||||
| 50 | |||||||||||||||
| 51 | =cut | ||||||||||||||
| 52 | |||||||||||||||
| 53 | =head1 DESCRIPTION | ||||||||||||||
| 54 | |||||||||||||||
| 55 | This module contains a definition of a BioMoby Service. With this | ||||||||||||||
| 56 | module, you can create a service definition, set its details and then | ||||||||||||||
| 57 | use the output from toXML to register this service with a mobycentral | ||||||||||||||
| 58 | registry. | ||||||||||||||
| 59 | |||||||||||||||
| 60 | =head1 AUTHORS | ||||||||||||||
| 61 | |||||||||||||||
| 62 | Edward Kawas (edward.kawas [at] gmail [dot] com) | ||||||||||||||
| 63 | Martin Senger (martin.senger [at] gmail [dot] com) | ||||||||||||||
| 64 | |||||||||||||||
| 65 | =cut | ||||||||||||||
| 66 | |||||||||||||||
| 67 | #----------------------------------------------------------------- | ||||||||||||||
| 68 | # A list of allowed attribute names. See MOSES::MOBY::Base for details. | ||||||||||||||
| 69 | #----------------------------------------------------------------- | ||||||||||||||
| 70 | |||||||||||||||
| 71 | =head1 ACCESSIBLE ATTRIBUTES | ||||||||||||||
| 72 | |||||||||||||||
| 73 | Details are in L<MOSES::MOBY::Base>. Here just a list of them: | ||||||||||||||
| 74 | |||||||||||||||
| 75 | =over | ||||||||||||||
| 76 | |||||||||||||||
| 77 | =item B<name> | ||||||||||||||
| 78 | |||||||||||||||
| 79 | A name of this service. | ||||||||||||||
| 80 | |||||||||||||||
| 81 | =item B<authority> | ||||||||||||||
| 82 | |||||||||||||||
| 83 | =item B<email> | ||||||||||||||
| 84 | |||||||||||||||
| 85 | =item B<description> | ||||||||||||||
| 86 | |||||||||||||||
| 87 | =item B<type> | ||||||||||||||
| 88 | |||||||||||||||
| 89 | =item B<url> | ||||||||||||||
| 90 | |||||||||||||||
| 91 | =item B<signatureURL> | ||||||||||||||
| 92 | |||||||||||||||
| 93 | =item B<category> | ||||||||||||||
| 94 | |||||||||||||||
| 95 | The category of service. Must be one of moby, cgi, or wsdl. | ||||||||||||||
| 96 | |||||||||||||||
| 97 | =item B<inputs> | ||||||||||||||
| 98 | |||||||||||||||
| 99 | A list of inputs for this service. Must be of type | ||||||||||||||
| 100 | C<MOSES::MOBY::Def::PrimaryData>. | ||||||||||||||
| 101 | |||||||||||||||
| 102 | =item B<outputs> | ||||||||||||||
| 103 | |||||||||||||||
| 104 | A list of outputs for this service. Must be of type | ||||||||||||||
| 105 | C<MOSES::MOBY::Def::PrimaryData>. | ||||||||||||||
| 106 | |||||||||||||||
| 107 | =item B<secondarys> | ||||||||||||||
| 108 | |||||||||||||||
| 109 | A list of secondary parameters for this service. Must be of type | ||||||||||||||
| 110 | C<MOSES::MOBY::Def::SecondaryData>. | ||||||||||||||
| 111 | |||||||||||||||
| 112 | =item B<lsid> | ||||||||||||||
| 113 | |||||||||||||||
| 114 | =back | ||||||||||||||
| 115 | |||||||||||||||
| 116 | =cut | ||||||||||||||
| 117 | |||||||||||||||
| 118 | { | ||||||||||||||
| 119 | 1 | my %_allowed = | |||||||||||||
| 120 | ( | ||||||||||||||
| 121 | name => { type => MOSES::MOBY::Base->STRING, | ||||||||||||||
| 122 | post => \&_create__module_name }, | ||||||||||||||
| 123 | authority => { type => MOSES::MOBY::Base->STRING, | ||||||||||||||
| 124 | post => \&_create__module_name }, | ||||||||||||||
| 125 | email => undef, | ||||||||||||||
| 126 | description => undef, | ||||||||||||||
| 127 | signatureURL => undef, | ||||||||||||||
| 128 | url => undef, | ||||||||||||||
| 129 | rdf => undef, | ||||||||||||||
| 130 | category => { type => MOSES::MOBY::Base->STRING, | ||||||||||||||
| 131 | post => \&_check_category }, | ||||||||||||||
| 132 | authoritative => {type => MOSES::MOBY::Base->BOOLEAN }, | ||||||||||||||
| 133 | type => undef, | ||||||||||||||
| 134 | inputs => {type => 'MOSES::MOBY::Def::PrimaryData', is_array => 1}, | ||||||||||||||
| 135 | outputs => {type => 'MOSES::MOBY::Def::PrimaryData', is_array => 1}, | ||||||||||||||
| 136 | secondarys => {type => 'MOSES::MOBY::Def::SecondaryData', is_array => 1}, | ||||||||||||||
| 137 | lsid => undef, | ||||||||||||||
| 138 | |||||||||||||||
| 139 | # used internally (but cannot start with underscore - Template would ignore them) | ||||||||||||||
| 140 | module_name => undef, | ||||||||||||||
| 141 | ); | ||||||||||||||
| 142 | |||||||||||||||
| 143 | 0 | ▶ | sub _accessible { | ||||||||||||
|
Subroutine
_accessible: not called CC=2 SCAR=17.9
| |||||||||||||||
| 144 | 0 | my ($self, $attr) = @_; | |||||||||||||
| 145 | 0 | ▶ | exists $_allowed{$attr} or $self->SUPER::_accessible ($attr); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 146 | } | ||||||||||||||
| 147 | 0 | ▶ | sub _attr_prop { | ||||||||||||
|
Subroutine
_attr_prop: not called CC=3 SCAR=24.8
| |||||||||||||||
| 148 | 0 | my ($self, $attr_name, $prop_name) = @_; | |||||||||||||
| 149 | 0 | my $attr = $_allowed {$attr_name}; | |||||||||||||
| 150 | 0 | ▶ | return ref ($attr) ? $attr->{$prop_name} : $attr if $attr; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 151 | 0 | return $self->SUPER::_attr_prop ($attr_name, $prop_name); | |||||||||||||
| 152 | } | ||||||||||||||
| 153 | } | ||||||||||||||
| 154 | |||||||||||||||
| 155 | 1 | ▶ | sub _create__module_name { | ||||||||||||
|
Subroutine
_create__module_name: not called CC=1 SCAR=2.6
| |||||||||||||||
| 156 | 0 | my ($self) = shift; | |||||||||||||
| 157 | $self->{module_name} = | ||||||||||||||
| 158 | 0 | $self->service2module ($self->{authority}, $self->{name}); | |||||||||||||
| 159 | } | ||||||||||||||
| 160 | |||||||||||||||
| 161 | |||||||||||||||
| 162 | #----------------------------------------------------------------- | ||||||||||||||
| 163 | |||||||||||||||
| 164 | =head1 SUBROUTINES | ||||||||||||||
| 165 | |||||||||||||||
| 166 | =cut | ||||||||||||||
| 167 | |||||||||||||||
| 168 | #----------------------------------------------------------------- | ||||||||||||||
| 169 | # init | ||||||||||||||
| 170 | #----------------------------------------------------------------- | ||||||||||||||
| 171 | 0 | ▶ | sub init { | ||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 172 | 0 | my ($self) = shift; | |||||||||||||
| 173 | 0 | $self->SUPER::init(); | |||||||||||||
| 174 | 0 | $self->inputs ([]); | |||||||||||||
| 175 | 0 | $self->outputs ([]); | |||||||||||||
| 176 | 0 | $self->secondarys ([]); | |||||||||||||
| 177 | 0 | $self->category ('moby'); | |||||||||||||
| 178 | 0 | $self->authoritative('true'); | |||||||||||||
| 179 | } | ||||||||||||||
| 180 | |||||||||||||||
| 181 | #----------------------------------------------------------------- | ||||||||||||||
| 182 | # toXML | ||||||||||||||
| 183 | #----------------------------------------------------------------- | ||||||||||||||
| 184 | 0 | ▶ | sub toXML { | ||||||||||||
|
Subroutine
toXML: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||
| 185 | 0 | my $self = shift; | |||||||||||||
| 186 | 0 | my $root = $self->createXMLElement ('registerService'); | |||||||||||||
| 187 | |||||||||||||||
| 188 | # category | ||||||||||||||
| 189 | 0 | my $node = $self->createXMLElement ("Category"); | |||||||||||||
| 190 | 0 | ▶ | $node->appendTextNode ($self->category) if $self->category; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 191 | 0 | $root->addChild ($node); | |||||||||||||
| 192 | |||||||||||||||
| 193 | # service name | ||||||||||||||
| 194 | 0 | $node = $self->createXMLElement ("serviceName"); | |||||||||||||
| 195 | 0 | ▶ | $node->appendTextNode ($self->name) if $self->name; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 196 | 0 | $root->addChild ($node); | |||||||||||||
| 197 | |||||||||||||||
| 198 | # service type | ||||||||||||||
| 199 | 0 | $node = $self->createXMLElement ("serviceType"); | |||||||||||||
| 200 | 0 | ▶ | $node->appendTextNode ($self->type) if $self->type; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 201 | 0 | $root->addChild ($node); | |||||||||||||
| 202 | |||||||||||||||
| 203 | |||||||||||||||
| 204 | 0 | $node = $self->createXMLElement ("contactEmail"); | |||||||||||||
| 205 | 0 | ▶ | $node->appendTextNode ($self->email) if $self->email; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 206 | 0 | $root->addChild ($node); | |||||||||||||
| 207 | |||||||||||||||
| 208 | # authURI | ||||||||||||||
| 209 | 0 | $node = $self->createXMLElement ("authURI"); | |||||||||||||
| 210 | 0 | ▶ | $node->appendTextNode ($self->authority) if $self->authority; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 211 | 0 | $root->addChild ($node); | |||||||||||||
| 212 | |||||||||||||||
| 213 | # description | ||||||||||||||
| 214 | 0 | $node = $self->createXMLElement ("Description"); | |||||||||||||
| 215 | 0 | ▶ | $node->addChild (XML::LibXML::CDATASection->new ($self->description)) if $self->description; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 216 | 0 | $root->addChild ($node); | |||||||||||||
| 217 | |||||||||||||||
| 218 | # signature url | ||||||||||||||
| 219 | 0 | $node = $self->createXMLElement ("signatureURL"); | |||||||||||||
| 220 | 0 | ▶ | $node->appendTextNode ($self->signatureURL) if $self->signatureURL; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 221 | 0 | $root->addChild ($node); | |||||||||||||
| 222 | |||||||||||||||
| 223 | # URL | ||||||||||||||
| 224 | 0 | $node = $self->createXMLElement ("URL"); | |||||||||||||
| 225 | 0 | ▶ | $node->appendTextNode ($self->url) if $self->url; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 226 | 0 | $root->addChild ($node); | |||||||||||||
| 227 | |||||||||||||||
| 228 | # authoritative | ||||||||||||||
| 229 | 0 | $node = $self->createXMLElement ("authoritativeService"); | |||||||||||||
| 230 | 0 | ▶ | $node->appendTextNode ($self->authoritative ? '1' : '0'); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 231 | 0 | $root->addChild ($node); | |||||||||||||
| 232 | |||||||||||||||
| 233 | # add inputs | ||||||||||||||
| 234 | 0 | $node = $self->createXMLElement ("Input"); | |||||||||||||
| 235 | 0 | foreach my $input (@{ $self->inputs }) { | |||||||||||||
| 236 | 0 | $node->addChild ($input->toXML); | |||||||||||||
| 237 | } | ||||||||||||||
| 238 | 0 | $root->addChild ($node); | |||||||||||||
| 239 | |||||||||||||||
| 240 | # add secondaries | ||||||||||||||
| 241 | 0 | $node = $self->createXMLElement ("secondaryArticles"); | |||||||||||||
| 242 | 0 | foreach my $sec (@{ $self->secondarys }) { | |||||||||||||
| 243 | 0 | $node->addChild ($sec->toXML); | |||||||||||||
| 244 | } | ||||||||||||||
| 245 | 0 | $root->addChild ($node); | |||||||||||||
| 246 | |||||||||||||||
| 247 | # add outputs | ||||||||||||||
| 248 | 0 | $node =$self->createXMLElement ("Output"); | |||||||||||||
| 249 | 0 | foreach my $output (@{ $self->outputs }) { | |||||||||||||
| 250 | 0 | $node->addChild ($output->toXML); | |||||||||||||
| 251 | } | ||||||||||||||
| 252 | 0 | $root->addChild ($node); | |||||||||||||
| 253 | |||||||||||||||
| 254 | 0 | return $root; | |||||||||||||
| 255 | } | ||||||||||||||
| 256 | |||||||||||||||
| 257 | #----------------------------------------------------------------- | ||||||||||||||
| 258 | # Checking service type. | ||||||||||||||
| 259 | #----------------------------------------------------------------- | ||||||||||||||
| 260 | 0 | ▶ | sub _check_category { | ||||||||||||
|
Subroutine
_check_category: not called CC=2 SCAR=17.9
| |||||||||||||||
| 261 | 0 | my ($self, $attr) = @_; | |||||||||||||
| 262 | 0 | ▶ | $self->throw ('Invalid service category: ' . $self->category) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 263 | unless $self->category =~ /^cgi|wsdl|moby|moby\-async|post|cgi\-async$/i; | ||||||||||||||
| 264 | } | ||||||||||||||
| 265 | |||||||||||||||
| 266 | 1 | 1; | |||||||||||||
| 267 | __END__ | ||||||||||||||