blib/lib/MOBY/Client/SimpleArticle.pm

filter: Statementstmt 76.5% 98 / 128 Branchbran 55.7% 29 / 52 Conditioncond 38.4% 10 / 26 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 78.2% 18 / 23 Podpod 57.1% 4 / 7 totaltotal 62.8% 159 / 253 CC 42 SCAR 25.5
CC
42
Cov
67%
_createTemplateArticle
56.0
new
14.8
content
12.0
CRAP 12.9
« blib/lib/MOBY/Client/SimpleInput.pm ↑ Summary blib/lib/MOBY/Config.pm »
1 package MOBY::Client::SimpleArticle;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use MOBY::MobyXMLConstants;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use vars qw($AUTOLOAD @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 ▶use vars qw /$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/;
10  
11 =head1 NAME
12  
13 MOBY::Client::SimpleArticle - a small object describing the Simple articles from the findService Response message of MOBY Central
14  
15 =head1 SYNOPSIS
16  
17  
18 foreach my $queryID(keys %$inputs){
19 my $this_invocation = $inputs->{$queryID}; # this is the <mobyData> block with this queryID
20 my $invocation_output = "";
21 if (my $input = $this_invocation->{'This_articleName'}){
22 # $input contains a MOBY::Client::SimpleArticle, ::CollectionArticle or ::SecondaryArticle
23 next unless $input->isSimple;
24 $XML = $input->XML; # get the raw XML of the object, including <Simple> or <Collection> elements
25 $moby_object = $input->content; # get the raw XML of the object EXCLUDING <Simple> or <Collection> elements
26 $DOM = $input->XML_DOM; # get the XML as a LibXML DOM object
27 $namespace = $input->namespace; # get the namespace of the object
28 $id = $input->id; # get the id of the object (the id of the outermost MOBY object XML block)
29  
30 # do your business here and fill $invocation_output
31 }
32  
33 $MOBY_RESPONSE .= simpleResponse( # create an empty response for this queryID
34 $invocation_output # response for this query
35 , "myOutput" # the article name of that output object
36 , $queryID); # the queryID of the input that we are responding to
37 }
38 return SOAP::Data->type('base64' => (responseHeader("illuminae.com") . $MOBY_RESPONSE . responseFooter));
39  
40  
41 or to construct a representation of a simple article from a findService call
42 to MOBY::Central
43  
44  
45 =cut
46  
47 =head1 DESCRIPTION
48  
49 This describes the Simple articles from either the findService Response of MOBY Central
50 (i.e. the description of the service), or Simple articles
51 as provided in a service invocation or response message
52 (i.e. simple articles containing data)
53  
54 Basically it parses the following part of a findService response:
55  
56 <Simple articleName='foo'>
57 <objectType>someNbject</objectType>
58 <Namespace>someNamespace</Namespace>
59 <Namespace>someNamespace2</Namespace>
60 </Simple>
61  
62 OR it parses the following part of a service invocation or response message:
63  
64 <Simple articleName='foo'>
65 <SomeObject namespace='someNamespace' id='someID'>.....</SomeObject>
66 </Simple>
67  
68 The articleName is retrieved with ->articleName
69 The namespace(s) are retrieved with ->namespaces
70 The objectType is retrieved with ->objectType
71 the id (if instantiated) is retrieved with ->id
72  
73  
74 =head1 AUTHORS
75  
76 Mark Wilkinson (markw at illuminae dot com)
77  
78 =cut
79  
80 =head1 METHODS
81  
82  
83 =head2 new
84  
85 Usage : my $SA = MOBY::Client::SimpleArticle->new(%args)
86 Function : create SimpleArticle object
87 Returns : MOBY::Client::SimpleArticle object
88 Args : either of the following two methods may be used to auto-generate the
89 object by passing the appropriate XML node as a string, or XML::DOM node object
90  
91 XML => $XML
92 XML_DOM => $XML::LibXML::Node
93  
94  
95  
96 =head2 articleName
97  
98 Usage : $name = $SA->articleName($name)
99 Function : get/set articleName
100 Returns : string
101 Arguments : (optional) string representing articleName to set
102  
103 =head2 objectType
104  
105 Usage : $type = $SA->objectType($type)
106 Function : get/set name
107 Returns : string
108 Arguments : (optional) string representing objectType to set
109  
110 =head2 objectLSID
111  
112 Usage : $type = $SA->objectLSID($type)
113 Function : get/set LSID
114 Returns : string
115 Arguments : (optional) string representing objectLSID to set
116  
117 =head2 namespace
118  
119 Usage : $namespace = $SA->namespace
120 Function : get namespace for the MOBY Object
121 Returns : namespace as a string
122 Arguments : none
123  
124 =head2 namespaces
125  
126 Usage : $namespaces = $SA->namespaces(\@namespaces)
127 Function : get/set namespaces for the objectType in a service instance object
128 Returns : arrayref of namespace strings
129 Arguments : (optional) arrayref of namespace strings to set
130  
131 =head2 XML
132  
133 Usage : $SA = $SA->XML($XML)
134 Function : set/reset all parameters for this object from the XML
135 Returns : MOBY::Client::SimpleArticle
136 Arguments : (optional) XML fragment from and including <Simple>...</Simple>
137  
138 =head2 content
139  
140 Usage : $XML = $SA->content
141 Function : get XML of the article EXCLUDING the <Simple>..</Simple> tags
142 Returns : string
143 Arguments : none
144  
145  
146 =head2 XML_DOM
147  
148 Usage : $namespaces = $SA->XML_DOM($XML_DOM_NODE)
149 Function : set/reset all parameters for this object from the XML::DOM node for <Simple>
150 Returns : MOBY::Client::SimpleArticle
151 Arguments : (optional) an $XML::DOM node from the <Simple> article of a DOM
152  
153  
154 =head2 addNamespace
155  
156 Usage : $namespaces = $IN->addNamespace($namespace)
157 Function : add another namespace for the objectType
158 Returns : namespace string
159  
160 =head2 isSimple
161  
162 Usage : $boolean = $IN->isSimple()
163 Function : is this a SimpleArticle type
164 (yes, I know this is obvious, but since you can
165 get both Simple and Collection objects in your
166 Input and output lists, it is good to be able
167 to test what you have in-hand)
168 Returns : 1 (true)
169  
170  
171 =head2 isCollection
172  
173 Usage : $boolean = $IN->isCollection()
174 Function : is this a CollectionArticle type
175 (yes, I know this is obvious, but since you can
176 get both Simple and Collection objects in your
177 Input and output lists, it is good to be able
178 to test what you have in-hand)
179 Returns : 0 for false
180  
181 =head2 isSecondary
182  
183 Usage : $boolean = $IN->isSecondary()
184 Function : is this a SecondaryArticle type?
185 (yes, I know this is obvious)
186 Returns : 0 (true)
187  
188 =cut
189  
190 {
191  
192 # Encapsulated:
193 # DATA
194 #___________________________________________________________
195 #ATTRIBUTES
196 6 my %_attr_data = # DEFAULT ACCESSIBILITY
197 (
198 articleName => [ undef, 'read/write' ],
199 objectType => [ undef, 'read/write' ],
200 objectLSID => [ undef, 'read/write' ],
201 namespaces => [ undef, 'read/write' ],
202 id => [ undef, 'read/write' ],
203 XML_DOM => [ undef, 'read/write' ],
204 XML => [ undef, 'read/write' ],
205 isSecondary => [ 0, 'read' ],
206 isSimple => [ 1, 'read' ],
207 isCollection => [ 0, 'read' ],
208 );
209  
210 #_____________________________________________________________
211 # METHODS, to operate on encapsulated class data
212 # Is a specified object attribute accessible in a given mode
213 20 ▶ sub _accessible {
Subroutine _accessible: called CC=1 SCAR=0.0
214 20 my ( $self, $attr, $mode ) = @_;
215 20 $_attr_data{$attr}[1] =~ /$mode/;
216 }
217  
218 # Classwide default value for a specified object attribute
219 70 ▶ sub _default_for {
Subroutine _default_for: called CC=1 SCAR=0.0
220 70 my ( $self, $attr ) = @_;
221 70 $_attr_data{$attr}[0];
222 }
223  
224 # List of names of all specified object attributes
225 8 ▶ sub _standard_keys {
Subroutine _standard_keys: called CC=1 SCAR=0.0
226 8 keys %_attr_data;
227 }
228  
229 7 ▶ sub addNamespace {
Subroutine addNamespace: called CC=2 SCAR=7.0
Pod documented
230 7 my ( $self, $ns ) = @_;
231 7 ▶ return $self->{namespaces} unless $ns;
Branch: 1 branch
BranchTrueFalseTotal
unless $ns 0 7 7
232 7 push @{ $self->{namespaces} }, $ns;
233 7 return $self->{namespaces};
234 }
235 }
236  
237 6 ▶sub new {
Subroutine new: called CC=12 SCAR=26.9
Pod documented
238 8 my ( $caller, %args ) = @_;
239 8 my $caller_is_obj = ref( $caller );
240 8 ▶ return $caller if $caller_is_obj;
Branch: 1 branch
BranchTrueFalseTotal
if $caller_is_obj 0 8 8
241 8 ▶ my $class = $caller_is_obj || $caller;
Condition33%1/3
$caller_is_obj || $caller
l!l&&r!l&&!r
080
MC/DC0%0/2
$caller_is_obj || $caller
$caller_is_obj $caller
Truth table33%1/3
A || B
A= $caller_is_objB= $caller
ABresult
1X1
011
000
242 8 my $proxy;
243 8 my $self = bless {}, $class;
244 8 foreach my $attrname ( $self->_standard_keys ) {
245 80 ▶ if ( exists $args{$attrname} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $args{$attrname}) { } 10 70 80
elsif ($caller_is_obj) { } 0 70 70
246 10 $self->{$attrname} = $args{$attrname};
247 } elsif ( $caller_is_obj ) {
248 0 $self->{$attrname} = $caller->{$attrname};
249 } else {
250 70 $self->{$attrname} = $self->_default_for( $attrname );
251 }
252 }
253 8 ▶ if ( $self->XML && ref( $self->XML ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->XML and ref $self->XML) { } 0 8 8
elsif ($self->XML_DOM and not ref($self->XML_DOM) =~ /XML\:\:LibXML/) { } 0 11 11
Condition66%2/3
$self->XML and ref $self->XML
!ll&&!rl&&r
710
MC/DC0%0/2
$self->XML and ref $self->XML
$self->XML ref $self->XML
Truth table66%2/3
A and B
A= $self->XMLB= ref $self->XML
ABresult
0X0
100
111
254 0 return 0;
255 ▶ } elsif ( $self->XML_DOM && !( ref( $self->XML_DOM ) =~ /XML\:\:LibXML/ ) ) {
Condition66%2/3
$self->XML_DOM and not ref($self->XML_DOM) =~ /XML\:\:LibXML/
!ll&&!rl&&r
350
MC/DC0%0/2
$self->XML_DOM and not ref($self->XML_DOM) =~ /XML\:\:LibXML/
$self->XML_DOM not ref($self->XML_DOM) =~ /XML\:\:LibXML/
Truth table66%2/3
A and not(B)
A= $self->XML_DOMB= not ref($self->XML_DOM) =~ /XML\:\:LibXML/
ABresult
0X0
100
111
256 0 return 0;
257 }
258  
259 8 ▶ $self->createFromXML if ( $self->XML );
Branch: 1 branch
BranchTrueFalseTotal
if $self->XML 1 7 8
260 8 ▶ $self->createFromDOM( $self->XML_DOM ) if ( $self->XML_DOM );
Branch: 1 branch
BranchTrueFalseTotal
if $self->XML_DOM 5 3 8
261 8 return $self;
262 }
263  
264 1 ▶sub createFromXML {
Subroutine createFromXML: called CC=3 SCAR=11.6
Pod undocumented
265 1 my ( $self ) = @_;
266 1 my $p = XML::LibXML->new;
267 1 my $doc = $p->parse_string( $self->XML );
268 1 my $root = $doc->getDocumentElement;
269 1 ▶ return 0 unless ( $root && ( $root->localname eq "Simple" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $root and $root->localname eq "Simple" 0 1 1
Condition33%1/3
$root and $root->localname eq "Simple"
!ll&&!rl&&r
001
MC/DC0%0/2
$root and $root->localname eq "Simple"
$root $root->localname eq "Simple"
Truth table33%1/3
A and B
A= $rootB= $root->localname eq "Simple"
ABresult
0X0
100
111
270 1 return $self->createFromDOM( $root );
271 }
272  
273 6 ▶sub createFromDOM {
Subroutine createFromDOM: called CC=9 SCAR=24.4
Pod undocumented
274 6 my ( $self, $dom ) = @_;
275 6 ▶ return 0 unless ( $dom && ( $dom->localname eq "Simple" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $dom and $dom->localname eq "Simple" 0 6 6
Condition33%1/3
$dom and $dom->localname eq "Simple"
!ll&&!rl&&r
006
MC/DC0%0/2
$dom and $dom->localname eq "Simple"
$dom $dom->localname eq "Simple"
Truth table33%1/3
A and B
A= $domB= $dom->localname eq "Simple"
ABresult
0X0
100
111
276 6 $self->XML($dom->toString);
277 6 $self->namespaces( [] ); # reset!
278 6 $self->articleName( "" );
279 6 $self->objectType( "" );
280 6 my $attr = $dom->getAttributeNode( 'articleName' );
281 6 ▶ $attr ||= $dom->getAttributeNode( 'moby:articleName' );
Condition33%1/3
$attr ||= $dom->getAttributeNode("moby:articleName")
l!l&&r!l&&!r
600
MC/DC0%0/2
$attr ||= $dom->getAttributeNode("moby:articleName")
$attr $dom->getAttributeNode("moby:articleName")
Truth table33%1/3
A ||= B
A= $attrB= $dom->getAttributeNode("moby:articleName")
ABresult
1X1
011
000
282 6 ▶ my $articleName = $attr ? $attr->getValue : "";
Branch: 1 branch
BranchTrueFalseTotal
$attr ? : 6 0 6
283 6 $attr = $dom->getAttributeNode( 'lsid' );
284 6 ▶ my $lsid = $attr ? $attr->getValue : "";
Branch: 1 branch
BranchTrueFalseTotal
$attr ? : 6 0 6
285  
286 6 ▶ $self->articleName( $articleName )
Branch: 1 branch
BranchTrueFalseTotal
if $articleName 6 0 6
287 if $articleName; # it may have already been set if this Simple is part of a Collection...
288 6 ▶ $self->objectLSID( $lsid) if $lsid;
Branch: 1 branch
BranchTrueFalseTotal
if $lsid 6 0 6
289  
290 # fork here - it may be an instantiated object (coming from a service invocation/response)
291 # or it may be a template object as in the SimpleArticle element of a registration call
292 # if the objectType tag exists, then it is a template object
293 6 ▶ if ( @{ $dom->getElementsByLocalName( "objectType" ) }[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$dom->getElementsByLocalName('objectType');}[0]) { } 0 6 6
294 0 return $self->_createTemplateArticle( $dom );
295 } else {
296 6 return $self->_createInstantiatedArticle( $dom );
297 }
298 # otherwise it should simpy contain an instantiated MOBY object
299 }
300  
301 0 ▶sub namespace {
Subroutine namespace: not called CC=2 SCAR=17.9
Pod documented
302 0 my ( $self) = @_;
303 0 my $namespaces = $self->namespaces;
304 0 my @namespace = @{$namespaces};
305 0 ▶ return $namespace[0] || "";
Condition0%0/2
$namespace[0] || ''
l!l
00
MC/DC0%0/1
$namespace[0] || ''
$namespace[0]
Truth table0%0/2
A
A= $namespace[0]
Aresult
11
00
306 }
307  
308 0 ▶sub content {
Subroutine content: not called CC=3 SCAR=24.8
Pod documented
309 0 my ( $self) = @_;
310 0 my $DOM = $self->XML_DOM;
311 0 my $XML;
312 0 foreach my $child ( $DOM->childNodes )
313 { # there should be only one child node, and that is the data object itself; ignore whitespace
314 0 ▶ next unless $child->nodeType == ELEMENT_NODE;
Branch: 1 branch
BranchTrueFalseTotal
unless $child->nodeType == 1 0 0 0
315 0 $XML .= $child->toString;
316 }
317 0 return $XML;
318 }
319
320 6 ▶sub _createInstantiatedArticle {
Subroutine _createInstantiatedArticle: called CC=7 SCAR=20.6
321 6 my ( $self, $dom ) = @_;
322  
323 # this will take a <Simple> node from a MOBY invocation message
324 # and extract the object-type and namespace from the
325 # contained data object
326 6 foreach my $child ( $dom->childNodes )
327 { # there should be only one child node, and that is the data object itself; ignore whitespace
328 18 ▶ next unless $child->nodeType == ELEMENT_NODE;
Branch: 1 branch
BranchTrueFalseTotal
unless $child->nodeType == 1 12 6 18
329 6 $self->objectType( $child->localname );
330 6 my $attr = $child->getAttributeNode( 'namespace' );
331 6 ▶ $attr ||= $child->getAttributeNode( 'moby:namespace' );
Condition33%1/3
$attr ||= $child->getAttributeNode("moby:namespace")
l!l&&r!l&&!r
600
MC/DC0%0/2
$attr ||= $child->getAttributeNode("moby:namespace")
$attr $child->getAttributeNode("moby:namespace")
Truth table33%1/3
A ||= B
A= $attrB= $child->getAttributeNode("moby:namespace")
ABresult
1X1
011
000
332 6 ▶ $self->addNamespace( $attr->getValue ) if $attr;
Branch: 1 branch
BranchTrueFalseTotal
if $attr 6 0 6
333 6 my $id = $child->getAttributeNode( 'id' );
334 6 ▶ $id ||= $child->getAttributeNode( 'moby:id' );
Condition33%1/3
$id ||= $child->getAttributeNode("moby:id")
l!l&&r!l&&!r
600
MC/DC0%0/2
$id ||= $child->getAttributeNode("moby:id")
$id $child->getAttributeNode("moby:id")
Truth table33%1/3
A ||= B
A= $idB= $child->getAttributeNode("moby:id")
ABresult
1X1
011
000
335 6 ▶ $self->id( $id->getValue ) if $id;
Branch: 1 branch
BranchTrueFalseTotal
if $id 6 0 6
336 }
337 6 return $self;
338 }
339  
340 0 ▶sub _createTemplateArticle {
Subroutine _createTemplateArticle: not called CC=7 SCAR=40.3
341 0 my ( $self, $dom ) = @_;
342  
343 # this will take a <Simple> node from a MOBY findServiceResponse
344 # message and extract the objectType and namespace array
345 # from the service signature.
346 0 my $objects = $dom->getElementsByLocalName( "objectType" );
347 0 foreach my $child ( $objects->get_node( 1 )->getChildNodes )
348 { # there must be only one in a simple! so take first element
349 0 ▶ next unless $child->nodeType == TEXT_NODE;
Branch: 1 branch
BranchTrueFalseTotal
unless $child->nodeType == 3 0 0 0
350 0 $self->objectType( $child->toString );
351 }
352 0 $objects = $dom->getElementsByLocalName( "Namespace" );
353 0 foreach ( 1 .. $objects->size() ) {
354 0 foreach my $child ( $objects->get_node( $_ )->childNodes )
355 { # there must be only one in a simple! so take element 0
356 0 ▶ next unless $child->nodeType == TEXT_NODE;
Branch: 1 branch
BranchTrueFalseTotal
unless $child->nodeType == 3 0 0 0
357 0 ▶ next unless $child->toString;
Branch: 1 branch
BranchTrueFalseTotal
unless $child->toString 0 0 0
358 0 $self->addNamespace( $child->toString );
359 }
360 }
361 0 return $self;
362 }
363  
364 0 ▶sub value {
Subroutine value: not called CC=1 SCAR=6.9
Pod undocumented
365 0 my ( $self ) = @_;
366  
367 # ????? what to do here ????
368 }
369  
370 17 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
371 # It seems desirable that if the XML() method is called, the XML should be parsed, rather than just being
372 6 ▶ no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
373 17 my ( $self, $newval ) = @_;
374 17 $AUTOLOAD =~ /.*::(\w+)/;
375 17 my $attr = $1;
376 17 ▶ if ( $self->_accessible( $attr, 'write' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_accessible($attr, 'write')) { } 14 3 17
elsif ($self->_accessible($attr, 'read')) { } 3 0 3
377 14 ▶ *{$AUTOLOAD} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
378 110 ▶ if ( defined $_[1] ) { $_[0]->{$attr} = $_[1]; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 48 62 110
379 110 return $_[0]->{$attr};
380 14 }; ### end of created subroutine
381 ### this is called first time only
382 14 ▶ if ( defined $newval ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newval) 5 9 14
383 5 $self->{$attr} = $newval;
384 }
385 14 return $self->{$attr};
386 } elsif ( $self->_accessible( $attr, 'read' ) ) {
387 3 ▶ *{$AUTOLOAD} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
388 3 return $_[0]->{$attr};
389 3 }; ### end of created subroutine
390 3 return $self->{$attr};
391 }
392
393 # Must have been a mistake then...
394 0 croak "No such method: $AUTOLOAD";
395 }
396 0 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
397 6 1;
« blib/lib/MOBY/Client/SimpleInput.pm ↑ Summary blib/lib/MOBY/Config.pm »