lib/XML/Compile/SOAP11/Operation.pm

filter: Statementstmt 17.6% 41 / 232 Branchbran 0.0% 0 / 100 Conditioncond 1.1% 1 / 85 MC/DCmcdc 0.0% 0 / 51 Subroutinesub 44.4% 12 / 27 Podpod 88.8% 8 / 9 totaltotal 12.3% 62 / 504 SCAR 88.0
CC
95
Cov
10%
explain
1892.0
_msg_parts
210.0
_fault_parts
110.0
CRAP 6658.5
« blib/lib/XML/Compile/SOAP11/Encoding.pm ↑ Summary lib/XML/Compile/SOAP11/Encoding.pm »
1 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
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.02.
5 # This code is part of distribution XML-Compile-SOAP. Meta-POD processed
6 # with OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package XML::Compile::SOAP11::Operation;
10 7 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 $VERSION = '3.27';
12  
13 7 ▶use base 'XML::Compile::SOAP::Operation';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 7 ▶use Log::Report 'xml-compile-soap';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 7 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 7 ▶use XML::Compile::Util qw/pack_type unpack_type/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 7 ▶use XML::Compile::SOAP::Util qw/:soap11/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 7 ▶use XML::Compile::SOAP11::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 7 ▶use XML::Compile::SOAP11::Server;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 7 ▶use XML::Compile::SOAP::Extension;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 7 ▶use vars '$VERSION'; # OODoc adds $VERSION to the script
Subroutine BEGIN: called CC=1 SCAR=0.0
29 7 ▶$VERSION ||= '(devel)';
Condition50%1/2
$XML::Compile::SOAP11::Operation::VERSION ||= "(devel)"
l!l
70
MC/DC0%0/1
$XML::Compile::SOAP11::Operation::VERSION ||= "(devel)"
$XML::Compile::SOAP11::Operation::VERSION
Truth table50%1/2
A
A= $XML::Compile::SOAP11::Operation::VERSION
Aresult
11
00
30  
31 # client/server object per schema class, because initiation options
32 # can be different. Class reference is key.
33 7 my (%soap11_client, %soap11_server);
34  
35  
36 sub init($)
37 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=4 SCAR=30.0
Pod undocumented
38  
39 0 $self->SUPER::init($args);
40  
41 $self->{$_} = $args->{$_} || {}
42 0 ▶ for qw/input_def output_def fault_def/;
Condition0%0/2
$args->{$_} || {}
l!l
00
MC/DC0%0/1
$args->{$_} || {}
$args->{$_}
Truth table0%0/2
A
A= $args->{$_}
Aresult
11
00
43  
44 0 ▶ $self->{style} = $args->{style} || 'document';
Condition0%0/2
$args->{'style'} || 'document'
l!l
00
MC/DC0%0/1
$args->{'style'} || 'document'
$args->{'style'}
Truth table0%0/2
A
A= $args->{'style'}
Aresult
11
00
45  
46 0 XML::Compile::SOAP::Extension->soap11OperationInit($self, $args);
47 0 $self;
48 }
49  
50 sub _fromWSDL11(@)
51 0 ▶{ my ($class, %args) = @_;
Subroutine _fromWSDL11: not called CC=6 SCAR=37.4
52  
53 # Extract the SOAP11 specific information from a WSDL11 file. There are
54 # half a zillion parameters.
55 my ($p_op, $b_op, $wsdl)
56 0 = @args{ qw/port_op bind_op wsdl/ };
57  
58 0 $args{schemas} = $wsdl;
59 0 $args{endpoints} = $args{serv_port}{soap_address}{location};
60  
61 0 ▶ my $sop = $b_op->{soap_operation} || {};
Condition0%0/2
$b_op->{'soap_operation'} || {}
l!l
00
MC/DC0%0/1
$b_op->{'soap_operation'} || {}
$b_op->{'soap_operation'}
Truth table0%0/2
A
A= $b_op->{'soap_operation'}
Aresult
11
00
62 0 ▶ $args{action} ||= $sop->{soapAction};
Condition0%0/3
$args{"action"} ||= $sop->{"soapAction"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"action"} ||= $sop->{"soapAction"}
$args{"action"} $sop->{"soapAction"}
Truth table0%0/3
A ||= B
A= $args{"action"}B= $sop->{"soapAction"}
ABresult
1X1
011
000
63  
64 0 ▶ my $sb = $args{binding}{soap_binding} || {};
Condition0%0/2
$args{'binding'}{'soap_binding'} || {}
l!l
00
MC/DC0%0/1
$args{'binding'}{'soap_binding'} || {}
$args{'binding'}{'soap_binding'}
Truth table0%0/2
A
A= $args{'binding'}{'soap_binding'}
Aresult
11
00
65 0 ▶ $args{transport} = $sb->{transport} || 'HTTP';
Condition0%0/2
$sb->{'transport'} || 'HTTP'
l!l
00
MC/DC0%0/1
$sb->{'transport'} || 'HTTP'
$sb->{'transport'}
Truth table0%0/2
A
A= $sb->{'transport'}
Aresult
11
00
66 0 ▶ $args{style} = $sb->{style} || 'document';
Condition0%0/2
$sb->{'style'} || 'document'
l!l
00
MC/DC0%0/1
$sb->{'style'} || 'document'
$sb->{'style'}
Truth table0%0/2
A
A= $sb->{'style'}
Aresult
11
00
67  
68 $args{input_def} = $class->_msg_parts($wsdl, $args{name}, $args{style}
69 0 , $p_op->{wsdl_input}, $b_op->{wsdl_input});
70  
71 $args{output_def} = $class->_msg_parts($wsdl, $args{name}.'Response'
72 0 , $args{style}, $p_op->{wsdl_output}, $b_op->{wsdl_output});
73  
74 $args{fault_def}
75 0 = $class->_fault_parts($wsdl, $p_op->{wsdl_fault}, $b_op->{wsdl_fault});
76  
77 0 $class->SUPER::new(%args);
78 }
79  
80 sub _msg_parts($$$$$)
81 0 ▶{ my ($class, $wsdl, $opname, $style, $port_op, $bind_op) = @_;
Subroutine _msg_parts: not called CC=14 SCAR=53.5
82 0 my %parts;
83  
84 0 ▶ defined $port_op # communication not in two directions
Branch: 1 branch
BranchTrueFalseTotal
defined $port_op or return {}, {} 0 0 0
85 or return ({}, {});
86  
87 0 ▶ if(my $body = $bind_op->{soap_body})
Branch: 2 branches
BranchTrueFalseTotal
if (my $body = $bind_op->{'soap_body'}) { } 0 0 0
elsif ($port_op->{'message'}) { } 0 0 0
88 0 { my $msgname = $port_op->{message};
89 0 my @parts = $class->_select_parts($wsdl, $msgname, $body->{parts});
90  
91 0 my ($ns, $local) = unpack_type $msgname;
92 0 ▶ my $rpc_ns = $body->{namespace} // '';
Condition0%0/2
$body->{"namespace"} // ""
l!l
00
MC/DC0%0/1
$body->{"namespace"} // ""
$body->{"namespace"}
Truth table0%0/2
A
A= $body->{"namespace"}
Aresult
11
00
93 0 ▶ $wsdl->addNicePrefix(call => $rpc_ns) if $rpc_ns;
Branch: 1 branch
BranchTrueFalseTotal
if $rpc_ns 0 0 0
94  
95 my $procedure
96 = $style eq 'rpc' ? pack_type($rpc_ns, $opname)
97 0 ▶ : @parts==1 && $parts[0]{type} ? $msgname
Branch: 2 branches
BranchTrueFalseTotal
$style eq 'rpc' ? : 0 0 0
@parts == 1 && $parts[0]{'type'} ? : 0 0 0
Condition0%0/3
@parts == 1 and $parts[0]{"type"}
!ll&&!rl&&r
000
MC/DC0%0/2
@parts == 1 and $parts[0]{"type"}
@parts == 1 $parts[0]{"type"}
Truth table0%0/3
A and B
A= @parts == 1B= $parts[0]{"type"}
ABresult
0X0
100
111
98 : $local;
99  
100 0 $parts{body} = { procedure => $procedure, %$port_op, use => 'literal'
101 , %$body, parts => \@parts };
102 }
103 elsif($port_op->{message})
104 { # missing <soap:body use="literal"> in <wsdl:input> or :output
105 0 error __x"operation {opname} has a message in its portType but no encoding in the binding", opname => $opname;
106 }
107  
108 0 ▶ my $bsh = $bind_op->{soap_header} || [];
Condition0%0/2
$bind_op->{'soap_header'} || []
l!l
00
MC/DC0%0/1
$bind_op->{'soap_header'} || []
$bind_op->{'soap_header'}
Truth table0%0/2
A
A= $bind_op->{'soap_header'}
Aresult
11
00
109 0 ▶ foreach my $header (ref $bsh eq 'ARRAY' ? @$bsh : $bsh)
Branch: 1 branch
BranchTrueFalseTotal
ref $bsh eq 'ARRAY' ? : 0 0 0
110 0 { my $msgname = $header->{message};
111 0 my @parts = $class->_select_parts($wsdl, $msgname, $header->{part});
112 0 push @{$parts{header}}, { %$header, parts => \@parts };
113  
114 0 ▶ foreach my $fault ( @{$header->{headerfault} || []} )
Branch: 1 branch
BranchTrueFalseTotal
$header->{"headerfault"} or [] 0 0 0
115 0 { $msgname = $fault->{message};
116 0 my @hf = $class->_select_parts($wsdl, $msgname, $fault->{part});
117 0 push @{$parts{headerfault}}, { %$fault, parts => \@hf };
118 }
119 }
120 0 \%parts;
121 }
122  
123 sub _select_parts($$$)
124 0 ▶{ my ($class, $wsdl, $msgname, $need_parts) = @_;
Subroutine _select_parts: not called CC=8 SCAR=42.8
125 0 ▶ my $msg = $wsdl->findDef(message => $msgname)
Branch: 1 branch
BranchTrueFalseTotal
my $msg = $wsdl->findDef("message", $msgname) or &error(&__x("cannot find message {name}", "name", $msgname)) 0 0 0
126 or error __x"cannot find message {name}", name => $msgname;
127  
128 my @need
129 0 ▶ = ref $need_parts ? @$need_parts
Branch: 2 branches
BranchTrueFalseTotal
ref $need_parts ? : 0 0 0
defined $need_parts ? : 0 0 0
130 : defined $need_parts ? $need_parts
131 : ();
132  
133 0 ▶ my $parts = $msg->{wsdl_part} || [];
Condition0%0/2
$msg->{'wsdl_part'} || []
l!l
00
MC/DC0%0/1
$msg->{'wsdl_part'} || []
$msg->{'wsdl_part'}
Truth table0%0/2
A
A= $msg->{'wsdl_part'}
Aresult
11
00
134 0 ▶ @need or return @$parts;
Branch: 1 branch
BranchTrueFalseTotal
@need or return @$parts 0 0 0
135  
136 0 my @sel;
137 0 my %parts = map +($_->{name} => $_), @$parts;
138 0 foreach my $name (@need)
139 { my $part = $parts{$name}
140 or error __x"message {msg} does not have a part named {part}"
141 0 ▶ , msg => $msg->{name}, part => $name;
Branch: 1 branch
BranchTrueFalseTotal
my $part = $parts{$name} or &error(&__x("message {msg} does not have a part named {part}", "msg", $msg->{"name"}, "part", $name)) 0 0 0
142  
143 0 push @sel, $part;
144 }
145  
146 0 @sel;
147 }
148  
149 sub _fault_parts($$$)
150 0 ▶{ my ($class, $wsdl, $portop, $bind) = @_;
Subroutine _fault_parts: not called CC=10 SCAR=47.0
151  
152 0 ▶ my $port_faults = $portop || [];
Condition0%0/2
$portop || []
l!l
00
MC/DC0%0/1
$portop || []
$portop
Truth table0%0/2
A
A= $portop
Aresult
11
00
153 0 my %faults;
154  
155 0 foreach my $fault (@$bind)
156 0 ▶ { $fault or next;
Branch: 1 branch
BranchTrueFalseTotal
$fault or next 0 0 0
157 0 my $name = $fault->{name};
158  
159 0 ▶ my $port = first {$_->{name} eq $name} @$port_faults;
Subroutine __ANON__: not called CC=1 SCAR=6.9
160 0 ▶ defined $port
Branch: 1 branch
BranchTrueFalseTotal
defined $port or &error(&__x("cannot find port for fault {name}", "name", $name)) 0 0 0
161 or error __x"cannot find port for fault {name}", name => $name;
162  
163 my $msgname = $port->{message}
164 0 ▶ or error __x"no fault message name in portOperation";
Branch: 1 branch
BranchTrueFalseTotal
my $msgname = $port->{"message"} or &error(&__x("no fault message name in portOperation")) 0 0 0
165  
166 0 ▶ my $message = $wsdl->findDef(message => $msgname)
Branch: 1 branch
BranchTrueFalseTotal
my $message = $wsdl->findDef("message", $msgname) or &error(&__x("cannot find fault message {name}", "name", $msgname)) 0 0 0
167 or error __x"cannot find fault message {name}", name => $msgname;
168  
169 0 ▶ @{$message->{wsdl_part} || []}==1
Branch: 2 branches
BranchTrueFalseTotal
@{$message->{"wsdl_part"} or [];} == 1 or &error(&__x("fault message {name} must have one part exactly", "name", $msgname)) 0 0 0
$message->{"wsdl_part"} or [] 0 0 0
170 or error __x"fault message {name} must have one part exactly"
171 , name => $msgname;
172  
173 $faults{$name} =
174 { part => $message->{wsdl_part}[0]
175 0 ▶ , use => ($fault->{use} || 'literal')
Condition0%0/2
$fault->{'use'} || 'literal'
l!l
00
MC/DC0%0/1
$fault->{'use'} || 'literal'
$fault->{'use'}
Truth table0%0/2
A
A= $fault->{'use'}
Aresult
11
00
176 };
177 }
178  
179 0 +{ faults => \%faults };
180 }
181  
182 #-------------------------------------------
183  
184  
185 0 ▶sub style() {shift->{style}}
Subroutine style: not called CC=1 SCAR=6.9
Pod documented
186 sub version() { 'SOAP11' }
187 0 ▶sub serverClass { 'XML::Compile::SOAP11::Server' }
Subroutine serverClass: not called CC=1 SCAR=6.9
Pod documented
188 0 ▶sub clientClass { 'XML::Compile::SOAP11::Client' }
Subroutine clientClass: not called CC=1 SCAR=6.9
Pod documented
189  
190 #-------------------------------------------
191  
192  
193 sub addHeader($$$%)
194 0 ▶{ my ($self, $dir, $label, $el, %opts) = @_;
Subroutine addHeader: not called CC=7 SCAR=40.3
Pod documented
195 0 my $elem = $self->schemas->findName($el);
196 0 ▶ my $defs
Branch: 3 branches
BranchTrueFalseTotal
$dir eq 'INPUT' ? : 0 0 0
$dir eq 'OUTPUT' ? : 0 0 0
$dir eq 'FAULT' ? : 0 0 0
197 = $dir eq 'INPUT' ? 'input_def'
198 : $dir eq 'OUTPUT' ? 'output_def'
199 : $dir eq 'FAULT' ? 'fault_def'
200 : panic "addHeader $dir";
201 0 ▶ my $headers = $self->{$defs}{header} ||= [];
Condition0%0/2
$self->{$defs}{"header"} ||= []
l!l
00
MC/DC0%0/1
$self->{$defs}{"header"} ||= []
$self->{$defs}{"header"}
Truth table0%0/2
A
A= $self->{$defs}{"header"}
Aresult
11
00
202  
203 0 ▶ if(my $already = first {$_->{part} eq $label} @$headers)
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (my $already = &first(sub { $_->{"part"} eq $label; } , @$headers)) 0 0 0
204 { # the header is already defined, ignore second declaration
205 0 my $other_type = $already->{parts}[0]{element};
206 0 ▶ $other_type eq $elem
Branch: 1 branch
BranchTrueFalseTotal
$other_type eq $elem or &error(&__x("header {label} already defined with type {type}", "label", $label, "type", $other_type)) 0 0 0
207 or error __x"header {label} already defined with type {type}"
208 , label => $label, type => $other_type;
209 0 return $already;
210 }
211  
212 my %part =
213 ( part => $label, use => 'literal'
214 , parts => [
215 { name => $label, element => $elem
216 , mustUnderstand => $opts{mustUnderstand}
217 , destination => $opts{destination}
218 0 } ]);
219  
220 0 push @$headers, \%part;
221 0 \%part;
222 }
223  
224 #-------------------------------------------
225  
226  
227 sub compileHandler(@)
228 0 ▶{ my ($self, %args) = @_;
Subroutine compileHandler: not called CC=7 SCAR=40.3
Pod documented
229  
230 my $soap = $soap11_server{$self->{schemas}}
231 0 ▶ ||= XML::Compile::SOAP11::Server->new(schemas => $self->{schemas});
Condition0%0/3
$soap11_server{$self->{"schemas"}} ||= "XML::Compile::SOAP11::Server"->new("schemas", $self->{"schemas"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$soap11_server{$self->{"schemas"}} ||= "XML::Compile::SOAP11::Server"->new("schemas", $self->{"schemas"})
$soap11_server{$self->{"schemas"}} "XML::Compile::SOAP11::Server"->new("schemas", $self->{"schemas"})
Truth table0%0/3
A ||= B
A= $soap11_server{$self->{"schemas"}}B= "XML::Compile::SOAP11::Server"->new("schemas", $self->{"schemas"})
ABresult
1X1
011
000
232 0 ▶ my $style = $args{style} ||= $self->style;
Condition0%0/3
$args{"style"} ||= $self->style
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"style"} ||= $self->style
$args{"style"} $self->style
Truth table0%0/3
A ||= B
A= $args{"style"}B= $self->style
ABresult
1X1
011
000
233  
234 0 my @ro = (%{$self->{input_def}}, %{$self->{fault_def}});
235 0 my @so = (%{$self->{output_def}}, %{$self->{fault_def}});
236  
237 0 ▶ $args{encode} ||= $soap->_sender(@so, %args);
Condition0%0/3
$args{"encode"} ||= $soap->_sender(@so, %args)
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"encode"} ||= $soap->_sender(@so, %args)
$args{"encode"} $soap->_sender(@so, %args)
Truth table0%0/3
A ||= B
A= $args{"encode"}B= $soap->_sender(@so, %args)
ABresult
1X1
011
000
238 0 ▶ $args{decode} ||= $soap->_receiver(@ro, %args);
Condition0%0/3
$args{"decode"} ||= $soap->_receiver(@ro, %args)
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"decode"} ||= $soap->_receiver(@ro, %args)
$args{"decode"} $soap->_receiver(@ro, %args)
Truth table0%0/3
A ||= B
A= $args{"decode"}B= $soap->_receiver(@ro, %args)
ABresult
1X1
011
000
239 0 ▶ $args{kind} ||= $self->kind;
Condition0%0/3
$args{"kind"} ||= $self->kind
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"kind"} ||= $self->kind
$args{"kind"} $self->kind
Truth table0%0/3
A ||= B
A= $args{"kind"}B= $self->kind
ABresult
1X1
011
000
240 0 $args{name} = $self->name;
241 0 ▶ $args{selector} ||= $soap->compileFilter(%{$self->{input_def}},
Condition0%0/3
$args{"selector"} ||= $soap->compileFilter(%{$$self{"input_def"};}, "style", $style)
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"selector"} ||= $soap->compileFilter(%{$$self{"input_def"};}, "style", $style)
$args{"selector"} $soap->compileFilter(%{$$self{"input_def"};}, "style", $style)
Truth table0%0/3
A ||= B
A= $args{"selector"}B= $soap->compileFilter(%{$$self{"input_def"};}, "style", $style)
ABresult
1X1
011
000
242 style => $style);
243  
244 $args{callback} = XML::Compile::SOAP::Extension
245 0 ->soap11HandlerWrapper($self, $args{callback}, \%args);
246  
247 0 $soap->compileHandler(%args);
248 }
249  
250  
251 sub compileClient(@)
252 0 ▶{ my ($self, %args) = @_;
Subroutine compileClient: not called CC=4 SCAR=30.0
Pod documented
253  
254 my $client = $soap11_client{$self->{schemas}}
255 0 ▶ ||= XML::Compile::SOAP11::Client->new(schemas => $self->{schemas});
Condition0%0/3
$soap11_client{$self->{"schemas"}} ||= "XML::Compile::SOAP11::Client"->new("schemas", $self->{"schemas"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$soap11_client{$self->{"schemas"}} ||= "XML::Compile::SOAP11::Client"->new("schemas", $self->{"schemas"})
$soap11_client{$self->{"schemas"}} "XML::Compile::SOAP11::Client"->new("schemas", $self->{"schemas"})
Truth table0%0/3
A ||= B
A= $soap11_client{$self->{"schemas"}}B= "XML::Compile::SOAP11::Client"->new("schemas", $self->{"schemas"})
ABresult
1X1
011
000
256 0 ▶ my $style = $args{style} ||= $self->style;
Condition0%0/3
$args{"style"} ||= $self->style
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"style"} ||= $self->style
$args{"style"} $self->style
Truth table0%0/3
A ||= B
A= $args{"style"}B= $self->style
ABresult
1X1
011
000
257 0 ▶ my $kind = $args{kind} ||= $self->kind;
Condition0%0/3
$args{"kind"} ||= $self->kind
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"kind"} ||= $self->kind
$args{"kind"} $self->kind
Truth table0%0/3
A ||= B
A= $args{"kind"}B= $self->kind
ABresult
1X1
011
000
258  
259 0 my @so = (%{$self->{input_def}}, %{$self->{fault_def}});
260 0 my @ro = (%{$self->{output_def}}, %{$self->{fault_def}});
261  
262 my $call = $client->compileClient
263 ( name => $self->name
264 , kind => $kind
265 , encode => $client->_sender(@so, %args)
266 , decode => $client->_receiver(@ro, %args)
267 , transport => $self->compileTransporter(%args)
268 , async => $args{async}
269 , soap => $args{soap}
270 0 );
271  
272 0 XML::Compile::SOAP::Extension->soap11ClientWrapper($self, $call, \%args);
273 }
274  
275 #--------------------------
276  
277  
278 7 my $sep = '#--------------------------------------------------------------';
279  
280 sub explain($$$@)
281 0 ▶{ my ($self, $schema, $format, $dir, %args) = @_;
Subroutine explain: not called CC=43 SCAR=75.5
Pod documented
282  
283 # $schema has to be passed as argument, because we do not want operation
284 # objects to be glued to a schema object after compile time.
285  
286 0 ▶ UNIVERSAL::isa($schema, 'XML::Compile::Schema')
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($schema, "XML::Compile::Schema") or &error(&__x("explain() requires first element to be a schema")) 0 0 0
287 or error __x"explain() requires first element to be a schema";
288  
289 0 ▶ $format eq 'PERL'
Branch: 1 branch
BranchTrueFalseTotal
$format eq "PERL" or &error(&__x("only PERL template supported for the moment, not {got}", "got", $format)) 0 0 0
290 or error __x"only PERL template supported for the moment, not {got}"
291 , got => $format;
292  
293 0 my $style = $self->style;
294 0 my $opname = $self->name;
295 0 ▶ my $skip_header = delete $args{skip_header} || 0;
Condition0%0/2
delete $args{'skip_header'} || 0
l!l
00
MC/DC0%0/1
delete $args{'skip_header'} || 0
delete $args{'skip_header'}
Truth table0%0/2
A
A= delete $args{'skip_header'}
Aresult
11
00
296 0 ▶ my $recurse = delete $args{recurse} || 0;
Condition0%0/2
delete $args{'recurse'} || 0
l!l
00
MC/DC0%0/1
delete $args{'recurse'} || 0
delete $args{'recurse'}
Truth table0%0/2
A
A= delete $args{'recurse'}
Aresult
11
00
297  
298 0 ▶ my $def = $dir eq 'INPUT' ? $self->{input_def} : $self->{output_def};
Branch: 1 branch
BranchTrueFalseTotal
$dir eq 'INPUT' ? : 0 0 0
299 0 my $faults = $self->{fault_def}{faults};
300  
301 0 my (@struct, @postproc, @attach);
302 0 ▶ my @main = $recurse
Branch: 1 branch
BranchTrueFalseTotal
$recurse ? : 0 0 0
303 ? "# The details of the types and elements are attached below."
304 : "# To explore the HASHes for each part, use recurse option.";
305  
306 HEAD_PART:
307 0 ▶ foreach my $header (@{$def->{header} || []})
Branch: 1 branch
BranchTrueFalseTotal
$def->{"header"} or [] 0 0 0
308 0 ▶ { foreach my $part ( @{$header->{parts} || []} )
Branch: 1 branch
BranchTrueFalseTotal
$header->{"parts"} or [] 0 0 0
309 0 { my $name = $part->{name};
310 my ($kind, $value) = $part->{type} ? (type => $part->{type})
311 0 ▶ : (element => $part->{element});
Branch: 1 branch
BranchTrueFalseTotal
$part->{'type'} ? : 0 0 0
312
313 0 ▶ my $type = $schema->prefixed($value) || $value;
Condition0%0/3
$schema->prefixed($value) || $value
l!l&&r!l&&!r
000
MC/DC0%0/2
$schema->prefixed($value) || $value
$schema->prefixed($value) $value
Truth table0%0/3
A || B
A= $schema->prefixed($value)B= $value
ABresult
1X1
011
000
314 0 ▶ push @main, ''
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'type' && $recurse ? : 0 0 0
Condition0%0/3
$kind eq "type" and $recurse
!ll&&!rl&&r
000
MC/DC0%0/2
$kind eq "type" and $recurse
$kind eq "type" $recurse
Truth table0%0/3
A and B
A= $kind eq "type"B= $recurse
ABresult
0X0
100
111
315 , "# Header part '$name' is $kind $type"
316 , ($kind eq 'type' && $recurse ? "# See fake element '$name'" : ())
317 , "my \$$name = {};";
318 0 push @struct, " $name => \$$name,";
319
320 0 ▶ $recurse or next HEAD_PART;
Branch: 1 branch
BranchTrueFalseTotal
$recurse or next HEAD_PART 0 0 0
321
322 0 my $elem = $value;
323 0 ▶ if($kind eq 'type')
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "type") 0 0 0
324 { # generate element with part name, because template requires elem
325 0 $schema->compileType(READER => $value, element => $name);
326 0 $elem = $name;
327 }
328
329 0 push @attach, '', $sep, "\$$name ="
330 , $schema->template(PERL => $elem, skip_header => 1, %args), ';';
331 }
332 }
333  
334 BODY_PART:
335 0 ▶ foreach my $part ( @{$def->{body}{parts} || []} )
Branch: 1 branch
BranchTrueFalseTotal
$def->{"body"}{"parts"} or [] 0 0 0
336 0 { my $name = $part->{name};
337 my ($kind, $value) = $part->{type} ? (type => $part->{type})
338 0 ▶ : (element => $part->{element});
Branch: 1 branch
BranchTrueFalseTotal
$part->{'type'} ? : 0 0 0
339  
340 0 ▶ my $type = $schema->prefixed($value) || $value;
Condition0%0/3
$schema->prefixed($value) || $value
l!l&&r!l&&!r
000
MC/DC0%0/2
$schema->prefixed($value) || $value
$schema->prefixed($value) $value
Truth table0%0/3
A || B
A= $schema->prefixed($value)B= $value
ABresult
1X1
011
000
341 0 ▶ push @main, ''
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'type' && $recurse ? : 0 0 0
Condition0%0/3
$kind eq "type" and $recurse
!ll&&!rl&&r
000
MC/DC0%0/2
$kind eq "type" and $recurse
$kind eq "type" $recurse
Truth table0%0/3
A and B
A= $kind eq "type"B= $recurse
ABresult
0X0
100
111
342 , "# Body part '$name' is content for $kind $type"
343 , ($kind eq 'type' && $recurse ? "# See fake element '$name'" : ())
344 , "my \$$name = {};";
345 0 push @struct, " $name => \$$name,";
346  
347 0 ▶ $recurse or next BODY_PART;
Branch: 1 branch
BranchTrueFalseTotal
$recurse or next BODY_PART 0 0 0
348  
349 0 my $elem = $value;
350 0 ▶ if($kind eq 'type')
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "type") 0 0 0
351 { # generate element with part name, because template requires elem
352 0 $schema->compileType(READER => $value, element => $name);
353 0 $elem = $name;
354 }
355  
356 0 push @attach, '', $sep, "\$$name ="
357 , $schema->template(PERL => $elem, skip_header => 1, %args), ';';
358 }
359  
360 0 foreach my $fault (sort keys %$faults)
361 0 { my $part = $faults->{$fault}{part}; # fault msgs have only one part
362 my ($kind, $value) = $part->{type} ? (type => $part->{type})
363 0 ▶ : (element => $part->{element});
Branch: 1 branch
BranchTrueFalseTotal
$part->{'type'} ? : 0 0 0
364  
365 0 ▶ my $type = $schema->prefixFor($value)
Branch: 1 branch
BranchTrueFalseTotal
$schema->prefixFor($value) ? : 0 0 0
366 ? $schema->prefixed($value) : $value;
367  
368 0 ▶ if($dir eq 'OUTPUT')
Branch: 1 branch
BranchTrueFalseTotal
if ($dir eq 'OUTPUT') { } 0 0 0
369 0 ▶ { push @main, ''
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'type' && $recurse ? : 0 0 0
Condition0%0/3
$kind eq "type" and $recurse
!ll&&!rl&&r
000
MC/DC0%0/2
$kind eq "type" and $recurse
$kind eq "type" $recurse
Truth table0%0/3
A and B
A= $kind eq "type"B= $recurse
ABresult
0X0
100
111
370 , "# ... or fault $fault is $kind"
371 , "my \$$fault = {}; # $type"
372 , ($kind eq 'type' && $recurse ? "# See fake element '$fault'" : ())
373 , "my \$fault ="
374 , " { code => pack_type(\$myns, 'Open.NoSuchFile')"
375 , " , reason => 'because I can'"
376 , " , detail => \$$fault"
377 , ' };';
378 0 push @struct, " $fault => \$fault,";
379 }
380 else
381 0 ▶ { my $nice = $schema->prefixed($type) || $type;
Condition0%0/3
$schema->prefixed($type) || $type
l!l&&r!l&&!r
000
MC/DC0%0/2
$schema->prefixed($type) || $type
$schema->prefixed($type) $type
Truth table0%0/3
A || B
A= $schema->prefixed($type)B= $type
ABresult
1X1
011
000
382 0 push @postproc
383 , " elsif(\$errname eq '$fault')"
384 , " { # \$details is a $nice"
385 , " }";
386 }
387  
388 0 ▶ $recurse or next;
Branch: 1 branch
BranchTrueFalseTotal
$recurse or next 0 0 0
389  
390 0 my $elem = $value;
391 0 ▶ if($kind eq 'type')
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "type") 0 0 0
392 { # generate element with part name, because template requires elem
393 0 $schema->compileType(READER => $value, element => $fault);
394 0 $elem = $fault;
395 }
396  
397 0 push @attach, '', $sep, "# FAULT", "\$$fault ="
398 , $schema->template(PERL => $elem, skip_header => 1, %args), ';';
399 }
400  
401 0 ▶ if($dir eq 'INPUT')
Branch: 2 branches
BranchTrueFalseTotal
if ($dir eq 'INPUT') { } 0 0 0
elsif ($dir eq 'OUTPUT') { } 0 0 0
402 0 { push @main, ''
403 , '# Call with the combination of parts.'
404 , 'my @params = (', @struct, ');'
405 , 'my ($answer, $trace) = $call->(@params);', ''
406 , '# @params will become %$data_in in the server handler.'
407 , '# $answer is a HASH, an operation OUTPUT or Fault.'
408 , '# $trace is an XML::Compile::SOAP::Trace object.';
409  
410 0 unshift @postproc, ''
411 , '# You may get an error back from the server'
412 , 'if(my $f = $answer->{Fault})'
413 , '{ my $errname = $f->{_NAME};'
414 , ' my $error = $answer->{$errname};'
415 , ' print "$error->{code}\n";', ''
416 , ' my $details = $error->{detail};'
417 , ' if(not $details)'
418 , ' { # system error, no $details'
419 , ' }';
420
421 0 push @postproc
422 , ' exit 1;'
423 , '}';
424 }
425 elsif($dir eq 'OUTPUT')
426 0 { s/^/ / for @main, @struct;
427 0 unshift @main, ''
428 , "sub handle_$opname(\$)"
429 , '{ my ($server, $data_in) = @_;'
430 , ' # process $data_in, structured as INPUT message.'
431 , ' # Hint: use "print Dumper $data_in"';
432  
433 0 push @main, ''
434 , ' # This will end-up as $answer at client-side'
435 , ' return # optional keyword'
436 , " +{", @struct, " };", "}";
437 }
438 else
439 0 { error __x"template for direction INPUT or OUTPUT, not {got}"
440 , got => $dir;
441 }
442  
443 0 my @header;
444 0 ▶ if(my $how = $def->{body})
Branch: 1 branch
BranchTrueFalseTotal
if (my $how = $def->{'body'}) { } 0 0 0
445 0 ▶ { my $use = $how->{use} || 'literal';
Condition0%0/2
$how->{'use'} || 'literal'
l!l
00
MC/DC0%0/1
$how->{'use'} || 'literal'
$how->{'use'}
Truth table0%0/2
A
A= $how->{'use'}
Aresult
11
00
446 push @header
447 0 ▶ , "# Operation ". ($how->{procedure} || '(unnamed)')
Condition0%0/2
$how->{'procedure'} || '(unnamed)'
l!l
00
MC/DC0%0/1
$how->{'procedure'} || '(unnamed)'
$how->{'procedure'}
Truth table0%0/2
A
A= $how->{'procedure'}
Aresult
11
00
448 , "# $dir, $style $use";
449 }
450 else
451 0 { push @header,
452 , "# Operation $opname has no $dir";
453 }
454  
455 0 foreach my $fault (sort keys %$faults)
456 0 { my $usage = $faults->{$fault};
457 0 push @header
458 , "# FAULT $fault, $style $usage->{use}" # $style?
459 }
460  
461 push @header
462 , "# Produced by ".__PACKAGE__." version $VERSION"
463 , "# on ".localtime()
464 , "#"
465 , "# The output below is only an example: it cannot be used"
466 , "# without interpretation, although very close to real code."
467 , ""
468 0 ▶ unless $args{skip_header};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"skip_header"} 0 0 0
469  
470 0 ▶ if($dir eq 'INPUT')
Branch: 1 branch
BranchTrueFalseTotal
if ($dir eq 'INPUT') { } 0 0 0
471 0 { push @header
472 , '# Compile only once in your code, usually during initiation:'
473 , "# my \$call = \$wsdl->compileClient('$opname');"
474 , '# then call it as often as you need. Alternatively'
475 , '# $wsdl->compileCalls(); # once'
476 , "# \$response = \$wsdl->call('$opname', \$request);";
477 }
478 else #OUTPUT
479 0 { push @header
480 , '# As part of the initiation phase of your server:'
481 , 'my $daemon = XML::Compile::SOAP::HTTPDaemon->new;'
482 , '$daemon->operationsFromWSDL'
483 , ' ( $wsdl'
484 , ' , callbacks =>'
485 , " { $opname => \\&handle_$opname}"
486 , ' );'
487 }
488  
489 0 join "\n", @header, @main, @postproc, @attach, '';
490 }
491  
492 sub parsedWSDL()
493 0 ▶{ my $self = shift;
Subroutine parsedWSDL: not called CC=1 SCAR=6.9
Pod documented
494 +{ input => $self->{input_def}{body}
495 , output => $self->{output_def}{body}
496 , faults => $self->{fault_def}{faults}
497 0 , style => $self->style
498 };
499 }
500  
501 7 1;
« blib/lib/XML/Compile/SOAP11/Encoding.pm ↑ Summary lib/XML/Compile/SOAP11/Encoding.pm »