lib/XML/Compile/SOAP/WSA.pm

filter: Statementstmt 93.0% 94 / 101 Branchbran 50.0% 9 / 18 Conditioncond 40.0% 6 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 91.3% 21 / 23 Podpod 87.5% 7 / 8 totaltotal 78.7% 137 / 174 SCAR 28.7
CC
16
Cov
81%
soap11HandlerWrapper
6.0
__ANON__
5.5
__ANON__
5.2
CRAP 17.7
« blib/lib/XML/Compile/SOAP/WSA.pm ↑ Summary blib/lib/XML/Compile/WSA.pm »
1 # Copyrights 2010-2015 by [Mark Overmeer].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.01.
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package XML::Compile::SOAP::WSA;
9 3 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 $VERSION = '0.94';
11  
12 3 ▶use base 'XML::Compile::SOAP::Extension';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use Log::Report 'xml-compile-soap-wsa';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶use XML::Compile::WSA::Util qw/WSA10MODULE WSA09 WSA10 WSDL11WSAW/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use XML::Compile::SOAP::Util qw/WSDL11/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use XML::Compile::Util qw/pack_type/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 3 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use File::Basename qw/dirname/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 my @common_hdr_elems = qw/To From Action ReplyTo FaultTo MessageID
24 RelatesTo RetryAfter/;
25 3 my @wsa09_hdr_elems = (@common_hdr_elems, qw/ReplyAfter/);
26 3 my @wsa10_hdr_elems = (@common_hdr_elems, qw/ReferenceParameters/);
27  
28 3 my %versions =
29 ( '0.9' => { xsd => '20070619-wsa09.xsd', wsa => WSA09
30 , hdr => \@wsa09_hdr_elems }
31 , '1.0' => { xsd => '20080723-wsa10.xsd', wsa => WSA10
32 , hdr => \@wsa10_hdr_elems }
33 );
34  
35 3 my $xsddir = File::Spec->catdir((dirname dirname __FILE__), 'WSA', 'xsd');
36  
37  
38 sub init($)
39 2 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=4 SCAR=14.2
Pod undocumented
40  
41 2 $self->SUPER::init($args);
42 my $version = $args->{version}
43 2 ▶ or error __x"explicit wsa_version required";
Branch: 1 branch
BranchTrueFalseTotal
my $version = $args->{"version"} or &error(&__x("explicit wsa_version required")) 0 2 2
44 2 trace "initializing wsa $version";
45  
46 2 ▶ $version = '1.0' if $version eq WSA10MODULE;
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "http://www.w3.org/2005/08/addressing/module" 0 2 2
47 2 ▶ $versions{$version}
Branch: 1 branch
BranchTrueFalseTotal
$versions{$version} or &error(&__x("unknown wsa version {v}, pick from {vs}", "v", $version, "vs", [keys %versions])) 0 2 2
48 or error __x"unknown wsa version {v}, pick from {vs}"
49 , v => $version, vs => [keys %versions];
50 2 $self->{version} = $version;
51 2 $self;
52 }
53  
54 #-----------
55  
56  
57 2 ▶sub version() {shift->{version}}
Subroutine version: called CC=1 SCAR=0.0
Pod documented
58 4 ▶sub wsaNS() {$versions{shift->{version}}{wsa}}
Subroutine wsaNS: called CC=1 SCAR=0.0
Pod documented
59  
60 # This is not uglier than the WSA specification does: if you do not
61 # specify these attributes cleanly in the WSDL specs, then everyone
62 # needs hacks.
63 # Documented in XML::Compile::SOAP::Operation
64  
65 sub XML::Compile::SOAP::Operation::wsaAction($)
66 4 ▶{ my ($self, $dir) = @_;
Subroutine wsaAction: called CC=2 SCAR=6.9
Pod documented
67 4 ▶ $dir eq 'INPUT' ? $self->{wsa}{action_input} : $self->{wsa}{action_output};
Branch: 1 branch
BranchTrueFalseTotal
$dir eq 'INPUT' ? : 3 1 4
68 }
69  
70 #-----------
71  
72 sub _load_ns($$)
73 4 ▶{ my ($self, $schema, $fn) = @_;
Subroutine _load_ns: called CC=1 SCAR=0.0
74 4 $schema->importDefinitions(File::Spec->catfile($xsddir, $fn));
75 }
76  
77 sub wsdl11Init($$)
78 2 ▶{ my ($self, $wsdl, $args) = @_;
Subroutine wsdl11Init: called CC=2 SCAR=7.1
Pod documented
79 2 my $def = $versions{$self->{version}};
80  
81 2 my $ns = $self->wsaNS;
82 2 $wsdl->addPrefixes(wsa => $ns, wsaw => WSDL11WSAW);
83 2 $wsdl->addKeyRewrite('PREFIXED(wsa,wsaw)');
84  
85 2 $wsdl->addCompileOptions('READERS'
86 , anyElement => 'TAKE_ALL'
87 , anyAttribute => 'TAKE_ALL'
88 );
89  
90 2 trace "loading wsa $self->{version}";
91 2 $self->_load_ns($wsdl, $def->{xsd});
92 2 $self->_load_ns($wsdl, '20060512-wsaw.xsd');
93  
94 2 ▶ my $wsa_action_ns = $self->version eq '0.9' ? $ns : WSDL11WSAW;
Branch: 1 branch
BranchTrueFalseTotal
$self->version eq '0.9' ? : 0 2 2
95 $wsdl->addHook
96 ( action => 'READER'
97 , type => pack_type(WSDL11, 'tParam')
98 , after => sub
99 4 ▶ { my ($xml, $data, $path) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
100 4 $data->{wsa_action} = $xml->getAttributeNS($wsa_action_ns,'Action');
101 4 $data;
102 }
103 2 );
104  
105 # [0.94] Many headers may contain attributes (which are usually not auto-
106 # detected anyway), which will cause the field to be a HASH. Older
107 # versions of this module would always simply return the content, not a
108 # HASH. Let's not break those.
109 $wsdl->addHook
110 ( action => 'READER'
111 , type => 'wsa:AttributedURIType'
112 , after => sub
113 3 ▶ { my ($xml, $data, $path) = @_;
Subroutine __ANON__: called CC=4 SCAR=17.1
114 $data = $data->{_}
115 3 ▶ if ref $data eq 'HASH' && keys %$data==1 && $data->{_};
Branch: 1 branch
BranchTrueFalseTotal
if ref $data eq "HASH" and keys %$data == 1 and $data->{"_"} 3 0 3
Condition33%2/6
ref $data eq "HASH" and keys %$data == 1 and $data->{"_"}
!ll&&!rl&&r
003
ref $data eq "HASH" and keys %$data == 1
!ll&&!rl&&r
003
MC/DC0%0/3
ref $data eq "HASH" and keys %$data == 1 and $data->{"_"}
ref $data eq "HASH" keys %$data == 1 $data->{"_"}
Truth table25%1/4
A and B and C
A= ref $data eq "HASH"B= keys %$data == 1C= $data->{"_"}
ABCresult
0XX0
10X0
1100
1111
116 3 $data;
117 }
118 2 );
119  
120 # For unknown reason, the FaultDetail header is described everywhere
121 # in the docs, but missing from the schema.
122 2 $wsdl->importDefinitions( <<_FAULTDETAIL );
123 <schema xmlns="http://www.w3.org/2001/XMLSchema"
124 xmlns:tns="$ns" targetNamespace="$ns"
125 elementFormDefault="qualified"
126 attributeFormDefault="unqualified">
127 <element name="FaultDetail">
128 <complexType>
129 <sequence>
130 <any minOccurs="0" maxOccurs="unbounded" />
131 </sequence>
132 </complexType>
133 </element>
134 </schema>
135 _FAULTDETAIL
136  
137 2 $self;
138 }
139  
140 sub soap11OperationInit($$)
141 2 ▶{ my ($self, $op, $args) = @_;
Subroutine soap11OperationInit: called CC=2 SCAR=6.9
Pod documented
142 2 my $ns = $self->wsaNS;
143  
144 2 $op->{wsa}{action_input} = $args->{input_def}{body}{wsa_action};
145 2 $op->{wsa}{action_output} = $args->{output_def}{body}{wsa_action};
146  
147 2 trace "adding wsa header logic";
148 2 my $def = $versions{$self->{version}};
149 2 foreach my $hdr ( @{$def->{hdr}} )
150 18 { $op->addHeader(INPUT => "wsa_$hdr" => "{$ns}$hdr");
151 18 $op->addHeader(OUTPUT => "wsa_$hdr" => "{$ns}$hdr");
152 }
153  
154 # soap11 specific
155 2 $op->addHeader(OUTPUT => wsa_FaultDetail => "{$ns}FaultDetail");
156 }
157 3 *soap12OperationInit = \&soap11OperationInit;
158  
159 sub soap11ClientWrapper($$$)
160 2 ▶{ my ($self, $op, $call, $args) = @_;
Subroutine soap11ClientWrapper: called CC=3 SCAR=11.9
Pod documented
161 2 my $to = ($op->endPoints)[0];
162 2 ▶ my $action = $op->wsaAction('INPUT') || $op->soapAction;
Condition66%2/3
$op->wsaAction('INPUT') || $op->soapAction
l!l&&r!l&&!r
110
MC/DC0%0/2
$op->wsaAction('INPUT') || $op->soapAction
$op->wsaAction('INPUT') $op->soapAction
Truth table66%2/3
A || B
A= $op->wsaAction('INPUT')B= $op->soapAction
ABresult
1X1
011
000
163 # my $outact = $op->wsaAction('OUTPUT');
164  
165 2 ▶ trace "added wsa in call $to".($action ? " for $action" : '');
Branch: 1 branch
BranchTrueFalseTotal
$action ? : 2 0 2
166 sub
167 2 ▶ { my $data = @_==1 ? shift : {@_};
Subroutine __ANON__: called CC=4 SCAR=16.4
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 2 2
168 2 ▶ $data->{wsa_To} ||= $to;
Condition33%1/3
$data->{"wsa_To"} ||= $to
l!l&&r!l&&!r
020
MC/DC0%0/2
$data->{"wsa_To"} ||= $to
$data->{"wsa_To"} $to
Truth table33%1/3
A ||= B
A= $data->{"wsa_To"}B= $to
ABresult
1X1
011
000
169 2 ▶ $data->{wsa_Action} ||= $action;
Condition33%1/3
$data->{"wsa_Action"} ||= $action
l!l&&r!l&&!r
020
MC/DC0%0/2
$data->{"wsa_Action"} ||= $action
$data->{"wsa_Action"} $action
Truth table33%1/3
A ||= B
A= $data->{"wsa_Action"}B= $action
ABresult
1X1
011
000
170 2 $call->($data);
171 # should we check that the wsa_Action in the reply is correct?
172 2 };
173 }
174 3 *soap12ClientWrapper = \&soap11ClientWrapper;
175  
176 sub soap11HandlerWrapper($$$)
177 0 ▶{ my ($self, $op, $cb, $args) = @_;
Subroutine soap11HandlerWrapper: not called CC=2 SCAR=17.9
Pod documented
178 0 my $outact = $op->wsaAction('OUTPUT');
179 0 ▶ defined $outact
Branch: 1 branch
BranchTrueFalseTotal
defined $outact or return $cb 0 0 0
180 or return $cb;
181  
182 sub
183 0 ▶ { my $data = $cb->(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
184 0 $data->{wsa_Action} = $outact;
185 0 $data;
186 0 };
187 }
188 3 *soap12HandlerWrapper = \&soap11HandlerWrapper;
189  
190  
191 3 1;
« blib/lib/XML/Compile/SOAP/WSA.pm ↑ Summary blib/lib/XML/Compile/WSA.pm »