blib/lib/MOBY/Client/CollectionArticle.pm

filter: Statementstmt 94.6% 88 / 93 Branchbran 65.6% 21 / 32 Conditioncond 44.4% 8 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 94.7% 18 / 19 Podpod 50.0% 2 / 4 totaltotal 76.9% 137 / 178 CC 25 SCAR 18.3
CC
25
Cov
82%
new
14.8
createFromDOM
6.6
AUTOLOAD
4.0
CRAP 6.2
« blib/lib/auto/share/dist/MOBY/cgi/authority.pl ↑ Summary blib/lib/MOBY/Client/ServiceInstance.pm »
1 package MOBY::Client::CollectionArticle;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use MOBY::MobyXMLConstants;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use vars qw($AUTOLOAD @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use MOBY::Client::SimpleArticle;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶use vars qw /$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 $VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /: (\d+)\.(\d+)/;
11  
12 =head1 NAME
13  
14 MOBY::Client::CollectionArticle - a small object describing the
15 Collection articles from the findService Response message of MOBY
16 Central or representing the collection part of a MOBY invocation or
17 response block
18  
19 =head1 SYNOPSIS
20  
21 This module can be used in two ways. One is to represent the Collection
22 portion of a findService response. The other is to represent the Collecion
23 portion of a MOBY service invocation or response message.
24  
25 Parsing a MOBY Service Invocation
26  
27 use MOBY::CommonSubs qw(:all);
28  
29 sub myService {
30 my ($caller, $data) = @_;
31  
32  
33 Can be used either in this way:
34  
35 use MOBY::CommonSubs qw{:all};
36  
37 foreach my $queryID(keys %$inputs){
38 my $this_invocation = $inputs->{$queryID}; # this is the <mobyData> block with this queryID
39 my $invocation_output = "";
40 if (my $input = $this_invocation->{'This_articleName'}){
41 # $input contains a MOBY::Client::SimpleArticle, ::CollectionArticle or ::SecondaryArticle
42 next unless $input->isCollection;
43 @simples= @{$input->Simples};
44 # @simples contains a list of MOBY::Client::SimpleArticles
45 # do your business here and fill $invocation_output
46 }
47  
48 $MOBY_RESPONSE .= simpleResponse( # create an empty response for this queryID
49 $invocation_output # response for this query
50 , "myOutput" # the article name of that output object
51 , $queryID); # the queryID of the input that we are responding to
52 }
53 return SOAP::Data->type('base64' => (responseHeader("illuminae.com") . $MOBY_RESPONSE . responseFooter));
54  
55  
56 or to construct a representation of a collection article from a findService call
57 to MOBY::Central
58  
59  
60 =head1 DESCRIPTION
61  
62 This describes the Collection articles from either the findService Response of MOBY Central
63 (i.e. the description of the service), or Collection articles
64 as provided in a service invocation or response message
65 (i.e. simple articles containing data)
66  
67 Basically it parses the following part of a findService response:
68  
69 <Collection articleName="foo">
70 <Simple>
71 <objectType>someNbject</objectType>
72 <Namespace>someNamespace</Namespace>
73 <Namespace>someNamespace2</Namespace>
74 </Simple>
75 <Simple>
76 <objectType>someNbject</objectType>
77 <Namespace>someNamespace</Namespace>
78 <Namespace>someNamespace2</Namespace>
79 </Simple>
80 </Collection>
81  
82 OR it parses the following part of a service invocation or response message:
83  
84 <Collection articleName="foo">
85 <Simple>
86 <SomeObject namespace='someNamespace' id='someID'>.....</SomeObject>
87 </Simple>
88 <Simple>
89 <SomeObject namespace='someNamespace' id='someID'>.....</SomeObject>
90 </Simple>
91 </Collection>
92  
93  
94 The articleName is retrieved with ->articleName
95 The contained Simples are retrieved as MOBY::Client::SimpleArticle objects
96 using the ->Simples method call.
97  
98  
99 =head1 AUTHORS
100  
101 Mark Wilkinson (markw at illuminae dot com)
102  
103 =head1 METHODS
104  
105  
106 =head2 new
107  
108 Usage : my $IN = MOBY::Client::CollectionArticle->new(%args)
109 Function : create CollectionArticle object
110 Returns : MOBY::Client::SimpleArticle object
111 Args : either of the following two methods may be used to auto-generate the
112 object by passing the appropriate XML node as a string, or XML::DOM node object
113  
114 XML => $XML
115 XML_DOM => $XML::DOM::NODE
116  
117 =head2 articleName
118  
119 Usage : $name = $IN->articleName($name)
120 Function : get/set articleName
121 Returns : string
122 Arguments : (optional) string to set articleName
123  
124 =head2 Simples
125  
126 Usage : $simples = $IN->Simples(\@SimpleArticles)
127 Function : get/set simple articles
128 Returns : arrayRef of MOBY::Client::SimpleArticle's in this collection
129 Arguments : (optional) arrayRef of MOBY::Client::SimpleArticle's in this collection
130  
131 =head2 addSimple
132  
133 Usage : $simples = $IN->addSimple($SimpleArticle)
134 Function : add another SimpleArticle
135 Returns : arrayref of MOBY::Client::SimpleArticle's or 0 if argument
136 was not a MOBY::Client::SimpleArticle (or other failure)
137 Arguments : a new MOBY::Client::SimpleArticle to add to collection
138  
139 =head2 XML
140  
141 Usage : $SA = $SA->XML($XML)
142 Function : set/reset all parameters for this object from the XML
143 Returns : MOBY::Client::SimpleArticle
144 Arguments : (optional) XML fragment from and including <Simple>...</Simple>
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 =head2 isSimple
154  
155 Usage : $boolean = $IN->isSimple()
156 Function : is this a SimpleArticle type
157 (yes, I know this is obvious, but since you can
158 get both Simple and Collection objects in your
159 Input and output lists, it is good to be able
160 to test what you have in-hand)
161 Returns : 0 (false)
162  
163 =head2 isCollection
164  
165 Usage : $boolean = $IN->isCollection()
166 Function : is this a CollectionArticle type
167 (yes, I know this is obvious, but since you can
168 get both Simple and Collection objects in your
169 Input and output lists, it is good to be able
170 to test what you have in-hand)
171 Returns : 1 (true)
172  
173 =head2 isSecondary
174  
175 Usage : $boolean = $IN->isSecondary()
176 Function : is this a SecondaryArticle type?
177 (yes, I know this is obvious)
178 Returns : 0 (true)
179  
180 =cut
181  
182 {
183  
184 # Encapsulated:
185 # DATA
186 #___________________________________________________________
187 #ATTRIBUTES
188 5 my %_attr_data = # DEFAULT ACCESSIBILITY
189 (
190 articleName => [ undef, 'read/write' ],
191 Simples => [ undef, 'read/write' ],
192 isSimple => [ 0, 'read' ],
193 isSecondary => [ 0, 'read' ],
194 isCollection => [ 1, 'read' ],
195 XML => [ undef, 'read/write' ],
196 XML_DOM => [ undef, 'read/write' ],
197 );
198  
199 #_____________________________________________________________
200 # METHODS, to operate on encapsulated class data
201 # Is a specified object attribute accessible in a given mode
202 10 ▶ sub _accessible {
Subroutine _accessible: called CC=1 SCAR=0.0
203 10 my ( $self, $attr, $mode ) = @_;
204 10 $_attr_data{$attr}[1] =~ /$mode/;
205 }
206  
207 # Classwide default value for a specified object attribute
208 26 ▶ sub _default_for {
Subroutine _default_for: called CC=1 SCAR=0.0
209 26 my ( $self, $attr ) = @_;
210 26 $_attr_data{$attr}[0];
211 }
212  
213 # List of names of all specified object attributes
214 4 ▶ sub _standard_keys {
Subroutine _standard_keys: called CC=1 SCAR=0.0
215 4 keys %_attr_data;
216 }
217  
218 4 ▶ sub addSimple {
Subroutine addSimple: called CC=3 SCAR=11.2
Pod documented
219 4 my ( $self, $s ) = @_;
220 4 ▶ return $self->{Simples} unless $s;
Branch: 1 branch
BranchTrueFalseTotal
unless $s 0 4 4
221 4 ▶ return 0 unless $s->isa( "MOBY::Client::SimpleArticle" );
Branch: 1 branch
BranchTrueFalseTotal
unless $s->isa("MOBY::Client::SimpleArticle") 0 4 4
222 4 push @{ $self->{Simples} }, $s;
223 4 return $self->{Simples};
224 }
225 }
226  
227 5 ▶sub new {
Subroutine new: called CC=12 SCAR=26.9
Pod documented
228 4 my ( $caller, %args ) = @_;
229 4 my $caller_is_obj = ref( $caller );
230 4 ▶ return $caller if $caller_is_obj;
Branch: 1 branch
BranchTrueFalseTotal
if $caller_is_obj 0 4 4
231 4 ▶ my $class = $caller_is_obj || $caller;
Condition33%1/3
$caller_is_obj || $caller
l!l&&r!l&&!r
040
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
232 4 my $proxy;
233 4 my $self = bless {}, $class;
234 4 foreach my $attrname ( $self->_standard_keys ) {
235 28 ▶ if ( exists $args{$attrname} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $args{$attrname}) { } 2 26 28
elsif ($caller_is_obj) { } 0 26 26
236 2 $self->{$attrname} = $args{$attrname};
237 } elsif ( $caller_is_obj ) {
238 0 $self->{$attrname} = $caller->{$attrname};
239 } else {
240 26 $self->{$attrname} = $self->_default_for( $attrname );
241 }
242 }
243 4 ▶ if ( $self->XML && ref( $self->XML ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->XML and ref $self->XML) { } 0 4 4
elsif ($self->XML_DOM and not ref($self->XML_DOM) =~ /libxml/i) { } 0 7 7
Condition66%2/3
$self->XML and ref $self->XML
!ll&&!rl&&r
310
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
244 0 return 0;
245 ▶ } elsif ( $self->XML_DOM && !( ref( $self->XML_DOM ) =~ /libxml/i ) ) {
Condition66%2/3
$self->XML_DOM and not ref($self->XML_DOM) =~ /libxml/i
!ll&&!rl&&r
310
MC/DC0%0/2
$self->XML_DOM and not ref($self->XML_DOM) =~ /libxml/i
$self->XML_DOM not ref($self->XML_DOM) =~ /libxml/i
Truth table66%2/3
A and not(B)
A= $self->XML_DOMB= not ref($self->XML_DOM) =~ /libxml/i
ABresult
0X0
100
111
246 0 return 0;
247 }
248 4 ▶ $self->createFromXML if ( $self->XML );
Branch: 1 branch
BranchTrueFalseTotal
if $self->XML 1 3 4
249 4 ▶ $self->createFromDOM( $self->XML_DOM ) if ( $self->XML_DOM );
Branch: 1 branch
BranchTrueFalseTotal
if $self->XML_DOM 1 3 4
250 4 return $self;
251 }
252  
253 1 ▶sub createFromXML {
Subroutine createFromXML: called CC=3 SCAR=11.6
Pod undocumented
254 1 my ( $self ) = @_;
255 1 my $p = XML::LibXML->new;
256 1 my $doc = $p->parse_string( $self->XML );
257 1 my $root = $doc->getDocumentElement;
258 1 ▶ return 0 unless ( $root && ( $root->localname eq "Collection" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $root and $root->localname eq "Collection" 0 1 1
Condition33%1/3
$root and $root->localname eq "Collection"
!ll&&!rl&&r
001
MC/DC0%0/2
$root and $root->localname eq "Collection"
$root $root->localname eq "Collection"
Truth table33%1/3
A and B
A= $rootB= $root->localname eq "Collection"
ABresult
0X0
100
111
259 1 return $self->createFromDOM( $root );
260 }
261  
262 2 ▶sub createFromDOM {
Subroutine createFromDOM: called CC=6 SCAR=18.8
Pod undocumented
263 2 my ( $self, $dom ) = @_;
264 2 ▶ return 0 unless ( $dom && ( $dom->localname eq "Collection" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $dom and $dom->localname eq "Collection" 0 2 2
Condition33%1/3
$dom and $dom->localname eq "Collection"
!ll&&!rl&&r
002
MC/DC0%0/2
$dom and $dom->localname eq "Collection"
$dom $dom->localname eq "Collection"
Truth table33%1/3
A and B
A= $domB= $dom->localname eq "Collection"
ABresult
0X0
100
111
265 2 $self->XML( $dom->toString ); # set the string version of the DOM
266 2 $self->articleName( "" );
267 2 $self->Simples( [] );
268 2 my $attr = $dom->getAttributeNode( 'articleName' );
269 2 ▶ $attr ||= $dom->getAttributeNode( 'moby:articleName' );
Condition33%1/3
$attr ||= $dom->getAttributeNode("moby:articleName")
l!l&&r!l&&!r
200
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
270 2 my $articleName = "";
271 2 ▶ $articleName = $attr->getValue if $attr;
Branch: 1 branch
BranchTrueFalseTotal
if $attr 2 0 2
272 2 $self->articleName( $articleName );
273 2 my $objects = $dom->getElementsByLocalName( "Simple" );
274
275 2 for my $n ( 1 .. $objects->size ) {
276 4 $self->addSimple(
277 MOBY::Client::SimpleArticle->new(
278 articleName => $self->articleName,
279 XML_DOM => $objects->get_node( $n )
280 )
281 );
282 }
283 2 return $self;
284 }
285  
286 7 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=14.0
287 5 ▶ no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
288 7 my ( $self, $newval ) = @_;
289 7 $AUTOLOAD =~ /.*::(\w+)/;
290 7 my $attr = $1;
291 7 ▶ if ( $self->_accessible( $attr, 'write' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_accessible($attr, 'write')) { } 4 3 7
elsif ($self->_accessible($attr, 'read')) { } 3 0 3
292 4 ▶ *{$AUTOLOAD} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
293 37 ▶ if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 9 28 37
294 37 return $_[0]->{$attr};
295 4 }; ### end of created subroutine
296 ### this is called first time only
297 4 ▶ if ( defined $newval ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newval) 0 4 4
298 0 $self->{$attr} = $newval;
299 }
300 4 return $self->{$attr};
301 } elsif ( $self->_accessible( $attr, 'read' ) ) {
302 3 ▶ *{$AUTOLOAD} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
303 3 return $_[0]->{$attr};
304 3 }; ### end of created subroutine
305 3 return $self->{$attr};
306 }
307  
308 # Must have been a mistake then...
309 0 croak "No such method: $AUTOLOAD";
310 }
311 0 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
312 5 1;
« blib/lib/auto/share/dist/MOBY/cgi/authority.pl ↑ Summary blib/lib/MOBY/Client/ServiceInstance.pm »