| 1 | #----------------------------------------------------------------- | ||||||||||||||
| 2 | # MOSES::MOBY::Def::Namespace | ||||||||||||||
| 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: Namespace.pm,v 1.4 2008/04/29 19:41:25 kawas Exp $ | ||||||||||||||
| 8 | #----------------------------------------------------------------- | ||||||||||||||
| 9 | package MOSES::MOBY::Def::Namespace; | ||||||||||||||
| 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.4 $ =~ /: (\d+)\.(\d+)/; | |||||||||||||
| 17 | |||||||||||||||
| 18 | =head1 NAME | ||||||||||||||
| 19 | |||||||||||||||
| 20 | MOSES::MOBY::Def::Namespace - a definition of a BioMoby Namespace | ||||||||||||||
| 21 | |||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||
| 23 | |||||||||||||||
| 24 | use MOSES::MOBY::Def::Namespace; | ||||||||||||||
| 25 | |||||||||||||||
| 26 | # create a new BioMoby namespace definition | ||||||||||||||
| 27 | my $namespace = new MOSES::MOBY::Def::Namespace | ||||||||||||||
| 28 | ( name => 'NCGR', | ||||||||||||||
| 29 | authority => 'generationcp.org', | ||||||||||||||
| 30 | email => 'yes@no', | ||||||||||||||
| 31 | description => 'This is a namespace that...', | ||||||||||||||
| 32 | ); | ||||||||||||||
| 33 | |||||||||||||||
| 34 | # get an LSID of a namespace | ||||||||||||||
| 35 | print $namespace->lsid; | ||||||||||||||
| 36 | |||||||||||||||
| 37 | # get the namespace details as a string | ||||||||||||||
| 38 | print $namespace->toString; | ||||||||||||||
| 39 | |||||||||||||||
| 40 | # get the namespace as a string of XML | ||||||||||||||
| 41 | # (same format used to register the namespace) | ||||||||||||||
| 42 | my $xml = $namespace->toXML->toString (1); | ||||||||||||||
| 43 | |||||||||||||||
| 44 | =cut | ||||||||||||||
| 45 | |||||||||||||||
| 46 | =head1 DESCRIPTION | ||||||||||||||
| 47 | |||||||||||||||
| 48 | This module contains a definition of a BioMoby Namespace. With this | ||||||||||||||
| 49 | module, you can create a namespace, set its details and then use the | ||||||||||||||
| 50 | output from toXML to register this namespace with a mobycentral | ||||||||||||||
| 51 | registry. | ||||||||||||||
| 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: | ||||||||||||||
| 67 | |||||||||||||||
| 68 | =over | ||||||||||||||
| 69 | |||||||||||||||
| 70 | =item B<name> | ||||||||||||||
| 71 | |||||||||||||||
| 72 | =item B<authority> | ||||||||||||||
| 73 | |||||||||||||||
| 74 | =item B<email> | ||||||||||||||
| 75 | |||||||||||||||
| 76 | =item B<description> | ||||||||||||||
| 77 | |||||||||||||||
| 78 | =item B<lsid> | ||||||||||||||
| 79 | |||||||||||||||
| 80 | =back | ||||||||||||||
| 81 | |||||||||||||||
| 82 | =cut | ||||||||||||||
| 83 | |||||||||||||||
| 84 | { | ||||||||||||||
| 85 | 1 | my %_allowed = | |||||||||||||
| 86 | ( | ||||||||||||||
| 87 | name => undef, | ||||||||||||||
| 88 | authority => undef, | ||||||||||||||
| 89 | email => undef, | ||||||||||||||
| 90 | description => undef, | ||||||||||||||
| 91 | lsid => undef, | ||||||||||||||
| 92 | ); | ||||||||||||||
| 93 | |||||||||||||||
| 94 | 0 | ▶ | sub _accessible { | ||||||||||||
|
Subroutine
_accessible: not called CC=2 SCAR=17.9
| |||||||||||||||
| 95 | 0 | my ($self, $attr) = @_; | |||||||||||||
| 96 | 0 | ▶ | exists $_allowed{$attr} or $self->SUPER::_accessible ($attr); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 97 | } | ||||||||||||||
| 98 | 0 | ▶ | sub _attr_prop { | ||||||||||||
|
Subroutine
_attr_prop: not called CC=3 SCAR=24.8
| |||||||||||||||
| 99 | 0 | my ($self, $attr_name, $prop_name) = @_; | |||||||||||||
| 100 | 0 | my $attr = $_allowed {$attr_name}; | |||||||||||||
| 101 | 0 | ▶ | return ref ($attr) ? $attr->{$prop_name} : $attr if $attr; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 102 | 0 | 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 | #} | ||||||||||||||
| 119 | |||||||||||||||
| 120 | #----------------------------------------------------------------- | ||||||||||||||
| 121 | # toXML | ||||||||||||||
| 122 | #----------------------------------------------------------------- | ||||||||||||||
| 123 | 1 | ▶ | sub toXML { | ||||||||||||
|
Subroutine
toXML: not called CC=5 SCAR=33.0
Pod
undocumented
| |||||||||||||||
| 124 | 0 | my $self = shift; | |||||||||||||
| 125 | 0 | my $root = $self->createXMLElement ('registerNamespace'); | |||||||||||||
| 126 | |||||||||||||||
| 127 | # namespace name | ||||||||||||||
| 128 | 0 | my $node = $self->createXMLElement ("namespaceType"); | |||||||||||||
| 129 | 0 | ▶ | $node->appendTextNode ($self->name) if $self->name; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 130 | 0 | $root->addChild ($node); | |||||||||||||
| 131 | |||||||||||||||
| 132 | |||||||||||||||
| 133 | 0 | $node = $self->createXMLElement ("contactEmail"); | |||||||||||||
| 134 | 0 | ▶ | $node->appendTextNode ($self->email) if $self->email; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 135 | 0 | $root->addChild ($node); | |||||||||||||
| 136 | |||||||||||||||
| 137 | # authURI | ||||||||||||||
| 138 | 0 | $node = $self->createXMLElement ("authURI"); | |||||||||||||
| 139 | 0 | ▶ | $node->appendTextNode ($self->authority) if $self->authority; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 140 | 0 | $root->addChild ($node); | |||||||||||||
| 141 | |||||||||||||||
| 142 | # description | ||||||||||||||
| 143 | 0 | $node = $self->createXMLElement ("Description"); | |||||||||||||
| 144 | 0 | ▶ | $node->addChild (XML::LibXML::CDATASection->new ($self->description)) if $self->description; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 145 | 0 | $root->addChild ($node); | |||||||||||||
| 146 | |||||||||||||||
| 147 | 0 | return $root; | |||||||||||||
| 148 | } | ||||||||||||||
| 149 | |||||||||||||||
| 150 | 1 | 1; | |||||||||||||
| 151 | __END__ | ||||||||||||||