blib/lib/W3C/SOAP/WSDL.pm

filter: Statementstmt 76.8% 83 / 108 Branchbran 43.7% 14 / 32 Conditioncond 41.1% 7 / 17 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 93.3% 14 / 15 Podpod 100% 3 / 3 totaltotal 66.1% 123 / 186 CC 25 SCAR 23.0
CC
25
Cov
66%
_get_operation_method
27.7
_request
11.3
send
7.0
CRAP 10.0
« blib/lib/W3C/SOAP/XSD/Parser.pm ↑ Summary blib/lib/W3C/SOAP/WSDL/Parser.pm »
1 package W3C::SOAP::WSDL;
2  
3 # Created on: 2012-05-27 18:57:16
4 # Create by: Ivan Wills
5 # $Id$
6 # $Revision$, $HeadURL$, $Date$
7 # $Revision$, $Source$, $Date$
8  
9 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Data::Dumper qw/Dumper/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 5 extends 'W3C::SOAP::Client';
17  
18 5 our $VERSION = 0.13;
19  
20 5 has header => (
21 is => 'rw',
22 isa => 'W3C::SOAP::Header',
23 predicate => 'has_header',
24 builder => '_header',
25 );
26  
27 sub _request {
28 3 ▶ my ($self, $action, @args) = @_;
Subroutine _request: called CC=10 SCAR=24.2
29 3 my $meta = $self->meta;
30 3 my $method = $self->_get_operation_method($action);
31 3 my $operation = $method->wsdl_operation;
32 3 my $resp;
33  
34 3 ▶ if ( $method->has_in_class && $method->has_in_attribute ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method->has_in_class and $method->has_in_attribute) { } 3 0 3
Condition33%1/3
$method->has_in_class and $method->has_in_attribute
!ll&&!rl&&r
003
MC/DC0%0/2
$method->has_in_class and $method->has_in_attribute
$method->has_in_class $method->has_in_attribute
Truth table33%1/3
A and B
A= $method->has_in_classB= $method->has_in_attribute
ABresult
0X0
100
111
35 3 my $class = $method->in_class;
36 3 my $att = $method->in_attribute;
37  
38 3 ▶ my $att_args = @args == 1 ? $args[0] : {@args};
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 ? : 0 3 3
39  
40 3 ▶ my $header_args = delete $att_args->{header} || {};
Condition100%2/2
delete $att_args->{'header'} || {}
l!l
12
MC/DC100%1/1
delete $att_args->{'header'} || {}
delete $att_args->{'header'}
Truth table100%2/2
A
A= delete $att_args->{'header'}
Aresult
11
00
41  
42 3 my $xsd = $class->new( $att => $att_args);
43  
44 3 ▶ if ( $method->has_in_header_class && $method->has_in_header_attribute) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method->has_in_header_class and $method->has_in_header_attribute) 1 2 3
Condition66%2/3
$method->has_in_header_class and $method->has_in_header_attribute
!ll&&!rl&&r
201
MC/DC50%1/2
$method->has_in_header_class and $method->has_in_header_attribute
$method->has_in_header_class $method->has_in_header_attribute
Truth table66%2/3
A and B
A= $method->has_in_header_classB= $method->has_in_header_attribute
ABresult
0X0
100
111
45 1 my $header_class = $method->in_header_class;
46 1 my $header_att = $method->in_header_attribute;
47  
48 1 my $header = $header_class->new($header_att => $header_args);
49  
50 1 $self->header->message($header);
51 }
52 3 my $xsd_ns = $xsd->xsd_ns;
53 3 ▶ if ( $xsd_ns !~ m{/$} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($xsd_ns =~ m[/$]) 3 0 3
54 3 $xsd_ns .= '/';
55 }
56 3 $resp = $self->request( "$xsd_ns$operation" => $xsd );
57 }
58 else {
59 0 $resp = $self->request( $operation, @args );
60 }
61  
62 3 ▶ if ( $method->has_out_class && $method->has_out_attribute ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method->has_out_class and $method->has_out_attribute) { } 3 0 3
Condition33%1/3
$method->has_out_class and $method->has_out_attribute
!ll&&!rl&&r
003
MC/DC0%0/2
$method->has_out_class and $method->has_out_attribute
$method->has_out_class $method->has_out_attribute
Truth table33%1/3
A and B
A= $method->has_out_classB= $method->has_out_attribute
ABresult
0X0
100
111
63 3 my $class = $method->out_class;
64 3 my $att = $method->out_attribute;
65 3 return $class->new($resp)->$att;
66 }
67 else {
68 0 return $resp;
69 }
70 }
71  
72 sub request {
73 3 ▶ my ($self, $action, $body) = @_;
Subroutine request: called CC=2 SCAR=7.0
Pod documented
74 3 my $xml = $self->build_request_xml($body);
75  
76 3 ▶ if ( $self->has_header ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_header) 3 0 3
77 3 my $node = $self->header->to_xml($xml);
78 3 $xml->firstChild->insertBefore($node, $xml->getDocumentElement->firstChild);
79 }
80  
81 3 return $self->send($action, $xml);
82 }
83  
84 sub build_request_xml {
85 3 ▶ my ($self, $body) = @_;
Subroutine build_request_xml: called CC=5 SCAR=17.8
Pod documented
86 3 my $xml = XML::LibXML->load_xml(string => <<'XML');
87 <?xml version="1.0" encoding="UTF-8"?>
88 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
89 <soapenv:Body/>
90 </soapenv:Envelope>
91 XML
92  
93 3 my $xc = XML::LibXML::XPathContext->new($xml);
94 3 $xc->registerNs('soapenv' => 'http://schemas.xmlsoap.org/soap/envelope/' );
95 3 my ($soap_body) = $xc->findnodes('//soapenv:Body');
96 3 ▶ if ( !blessed $body ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not builtin::blessed($body)) { } 0 3 3
elsif ($body->isa('XML::LibXNL::Node')) { } 0 3 3
elsif ($body->can('to_xml')) { } 3 0 3
97 0 $soap_body->appendChild( $xml->createTextNode($body) );
98 }
99 elsif ( $body->isa('XML::LibXNL::Node') ) {
100 0 $soap_body->appendChild( $body );
101 }
102 elsif ( $body->can('to_xml') ) {
103 3 for my $node ( $body->to_xml($xml) ) {
104 3 $soap_body->appendChild( $node );
105 }
106 }
107 else {
108 0 W3C::SOAP::Exception::BadInput->throw(
109 faultcode => 'UNKNOWN SOAP BODY',
110 message => "Don't know how to process ". (ref $body) ."\n",
111 error => '',
112 );
113 }
114  
115 3 return $xml;
116 }
117  
118 sub send {
119 3 ▶ my ($self, $action, $xml) = @_;
Subroutine send: called CC=4 SCAR=19.4
Pod documented
120 3 my $content;
121  
122 3 ▶ $self->log->debug("$action REQUEST\n" . $xml->toString) if $self->has_log;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_log 0 3 3
123 try {
124 3 ▶ $content = $self->post($action, $xml);
Subroutine __ANON__: called CC=1 SCAR=0.0
125 }
126 catch {
127 0 ▶ $self->log->error("$action RESPONSE \n" . $self->response->decoded_content) if $self->has_log;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_log 0 0 0
128  
129 0 W3C::SOAP::Exception::HTTP->throw(
130 faultcode => $self->response->code,
131 message => $self->response->message,
132 error => $_,
133 );
134 3 };
135 3 ▶ $self->log->debug("$action RESPONSE \n$content") if $self->has_log;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_log 0 3 3
136  
137 3 my $xml_response = XML::LibXML->load_xml( string => $content );
138 3 my $ns = $self->_envelope_ns($xml_response);
139  
140 3 my ($fault) = $xml_response->findnodes("//$ns\:Body/$ns:Fault");
141 3 ▶ if ($fault) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fault) 0 3 3
142 0 my $faultcode = join ' ', map {$_->toString} map {$_->childNodes} $fault->findnodes("faultcode");
143 0 my $faultstring = join ' ', map {$_->toString} map {$_->childNodes} $fault->findnodes("faultstring");
144 0 my $faultactor = join ' ', map {$_->toString} map {$_->childNodes} $fault->findnodes("faultactor");
145 0 my $detail = join ' ', map {$_->toString} map {$_->childNodes} $fault->findnodes("detail");
146  
147 0 W3C::SOAP::Exception->throw(
148 faultcode => $faultcode,
149 faultstring => $faultstring,
150 faultactor => $faultactor,
151 detail => $detail,
152 );
153 }
154  
155 3 my ($node) = $xml_response->findnodes("//$ns\:Body");
156  
157 3 return $node;
158 }
159  
160 sub _get_operation_method {
161 3 ▶ my ($self, $action) = @_;
Subroutine _get_operation_method: called CC=7 SCAR=33.2
162  
163 3 my $method = $self->meta->get_method($action);
164 3 ▶ return $method if $method && $method->meta->name eq 'W3C::SOAP::WSDL::Meta::Method';
Branch: 1 branch
BranchTrueFalseTotal
if $method and $method->meta->name eq "W3C::SOAP::WSDL::Meta::Method" 3 0 3
Condition33%1/3
$method and $method->meta->name eq "W3C::SOAP::WSDL::Meta::Method"
!ll&&!rl&&r
003
MC/DC0%0/2
$method and $method->meta->name eq "W3C::SOAP::WSDL::Meta::Method"
$method $method->meta->name eq "W3C::SOAP::WSDL::Meta::Method"
Truth table33%1/3
A and B
A= $methodB= $method->meta->name eq "W3C::SOAP::WSDL::Meta::Method"
ABresult
0X0
100
111
165  
166 0 for my $super ( $self->meta->superclasses ) {
167 0 ▶ next unless $super->can('_get_operation_method');
Branch: 1 branch
BranchTrueFalseTotal
unless $super->can("_get_operation_method") 0 0 0
168 0 $method = $super->_get_operation_method($action);
169 0 ▶ return $method if $method && $method->meta->name eq 'W3C::SOAP::WSDL::Meta::Method';
Branch: 1 branch
BranchTrueFalseTotal
if $method and $method->meta->name eq "W3C::SOAP::WSDL::Meta::Method" 0 0 0
Condition0%0/3
$method and $method->meta->name eq "W3C::SOAP::WSDL::Meta::Method"
!ll&&!rl&&r
000
MC/DC0%0/2
$method and $method->meta->name eq "W3C::SOAP::WSDL::Meta::Method"
$method $method->meta->name eq "W3C::SOAP::WSDL::Meta::Method"
Truth table0%0/3
A and B
A= $methodB= $method->meta->name eq "W3C::SOAP::WSDL::Meta::Method"
ABresult
0X0
100
111
170 }
171  
172 0 confess "Could not find any methods called $action!";
173 }
174  
175 sub _envelope_ns {
176 3 ▶ my ($self, $xml) = @_;
Subroutine _envelope_ns: called CC=1 SCAR=0.0
177 my %map
178 5 = map {$_->name =~ /^xmlns:?(.*)$/; ($_->value => $1)}
179 3 grep { $_->name =~ /^xmlns/ }
180 $xml->firstChild->getAttributes;
181  
182 3 return $map{'http://schemas.xmlsoap.org/soap/envelope/'};
183 }
184  
185 sub _header {
186 4 ▶ return W3C::SOAP::Header->new;
Subroutine _header: called CC=1 SCAR=0.0
187 }
188  
189 5 1;
190  
191 __END__
192  
193 =head1 NAME
194  
195 W3C::SOAP::WSDL - A SOAP WSDL Client object
196  
197 =head1 VERSION
198  
199 This documentation refers to W3C::SOAP::WSDL version 0.13.
200  
201  
202 =head1 SYNOPSIS
203  
204 use W3C::SOAP::WSDL;
205  
206 # Brief but working code example(s) here showing the most common usage(s)
207 # This section will be as far as many users bother reading, so make it as
208 # educational and exemplary as possible.
209  
210  
211 =head1 DESCRIPTION
212  
213 Inherits from L<W3C::SOAP::Client>
214  
215 =head1 SUBROUTINES/METHODS
216  
217 =over 4
218  
219 =item C<request ($action, $body)>
220  
221 Converts the body object to XML and adds any headers, then calls C<send()>
222  
223 =item C<build_request_xml ($action, $body)>
224  
225 Creates the XML representation of C<$body>
226  
227 =item C<send ($action, $xml)>
228  
229 Makes the HTTP request of the soap action and returns the resultant body node
230  
231 =back
232  
233 =head1 DIAGNOSTICS
234  
235 =head1 CONFIGURATION AND ENVIRONMENT
236  
237 =head1 DEPENDENCIES
238  
239 =head1 INCOMPATIBILITIES
240  
241 =head1 BUGS AND LIMITATIONS
242  
243 There are no known bugs in this module.
244  
245 Please report problems to Ivan Wills (ivan.wills@gmail.com).
246  
247 Patches are welcome.
248  
249 =head1 AUTHOR
250  
251 Ivan Wills - (ivan.wills@gmail.com)
252  
253 =head1 LICENSE AND COPYRIGHT
254  
255 Copyright (c) 2012 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
256 All rights reserved.
257  
258 This module is free software; you can redistribute it and/or modify it under
259 the same terms as Perl itself. See L<perlartistic>. This program is
260 distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
261 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
262 PARTICULAR PURPOSE.
263  
264 =cut
« blib/lib/W3C/SOAP/XSD/Parser.pm ↑ Summary blib/lib/W3C/SOAP/WSDL/Parser.pm »