lib/XML/Compile/SOAP/Server.pm

filter: Statementstmt 29.1% 23 / 79 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 36.8% 7 / 19 Podpod 83.3% 5 / 6 totaltotal 22.2% 35 / 157 SCAR 54.5
CC
20
Cov
19%
__ANON__
90.0
compileFilter
30.0
compileHandler
20.0
CRAP 232.5
« blib/lib/XML/Compile/SOAP/Trace.pm ↑ Summary lib/XML/Compile/Transport/SOAPHTTP.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::SOAP::Server;
10 7 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 $VERSION = '3.27';
12  
13  
14 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 7 ▶use Log::Report 'xml-compile-soap';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 7 ▶use XML::Compile::Util qw/unpack_type/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶use XML::Compile::SOAP::Util qw/:soap11/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 7 use HTTP::Status qw/RC_OK RC_BAD_REQUEST RC_NOT_ACCEPTABLE
22 7 ▶ RC_INTERNAL_SERVER_ERROR/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24  
25 0 ▶sub new(@) { panic __PACKAGE__." only secundary in multiple inheritance" }
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
26  
27 sub init($)
28 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=3 SCAR=24.8
Pod undocumented
29 0 ▶ $self->{role} = $self->roleURI($args->{role} || 'NEXT') || $args->{role};
Condition0%0/5
$self->roleURI($args->{'role'} || 'NEXT') || $args->{'role'}
l!l&&r!l&&!r
000
$args->{'role'} || 'NEXT'
l!l
00
MC/DC0%0/2
$self->roleURI($args->{'role'} || 'NEXT') || $args->{'role'}
$self->roleURI($args->{'role'} || 'NEXT') $args->{'role'}
MC/DC0%0/1
$args->{'role'} || 'NEXT'
$args->{'role'}
Truth table0%0/3
A || B
A= $self->roleURI($args->{'role'} || 'NEXT')B= $args->{'role'}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $args->{'role'}
Aresult
11
00
30 0 $self;
31 }
32  
33 #---------------------------------
34  
35  
36 0 ▶sub role() {shift->{role}}
Subroutine role: not called CC=1 SCAR=6.9
Pod documented
37  
38 #---------------------------------
39  
40  
41 sub compileHandler(@)
42 0 ▶{ my ($self, %args) = @_;
Subroutine compileHandler: not called CC=4 SCAR=30.0
Pod documented
43  
44 0 my $decode = $args{decode};
45 0 ▶ my $encode = $args{encode} || $self->compileMessage('SENDER');
Condition0%0/3
$args{'encode'} || $self->compileMessage('SENDER')
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'encode'} || $self->compileMessage('SENDER')
$args{'encode'} $self->compileMessage('SENDER')
Truth table0%0/3
A || B
A= $args{'encode'}B= $self->compileMessage('SENDER')
ABresult
1X1
011
000
46 my $name = $args{name}
47 0 ▶ or error __x"each server handler requires a name";
Branch: 1 branch
BranchTrueFalseTotal
my $name = $args{"name"} or &error(&__x("each server handler requires a name")) 0 0 0
48 0 ▶ my $selector = $args{selector} || sub {0};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$args{'selector'} || sub { 0; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'selector'} || sub { 0; }
$args{'selector'} sub { 0; }
Truth table0%0/3
A || B
A= $args{'selector'}B= sub { 0; }
ABresult
1X1
011
000
49  
50 # even without callback, we will validate
51 0 my $callback = $args{callback};
52  
53 sub
54 0 ▶ { my ($name, $xmlin, $info, $session) = @_;
Subroutine __ANON__: not called CC=9 SCAR=45.0
55 # info is used to help determine if the xmlin is of the type for
56 # this call. $session is passed in by the server and is in turn
57 # passed to the handlers
58 0 ▶ $selector->($xmlin, $info) or return;
Branch: 1 branch
BranchTrueFalseTotal
&$selector($xmlin, $info) or return 0 0 0
59 0 trace __x"procedure {name} selected", name => $name;
60  
61 0 my $data;
62 0 ▶ if($decode)
Branch: 1 branch
BranchTrueFalseTotal
if ($decode) { } 0 0 0
63 0 ▶ { $data = try { $decode->($xmlin) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 ▶ if(my $err = $@->wasFatal)
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@->wasFatal) 0 0 0
65 0 { $err->throw(reason => 'INFO', is_fatal => 0);
66 0 return ( RC_NOT_ACCEPTABLE, 'input validation failed'
67 , $self->faultValidationFailed($name, $err))
68 }
69 }
70 else
71 0 { $data = $xmlin;
72 }
73  
74 0 my $answer = $callback->($self, $data, $session);
75 0 ▶ unless(defined $answer)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $answer) 0 0 0
76 0 { notice __x"procedure {name} did not produce an answer", name=>$name;
77 0 return ( RC_INTERNAL_SERVER_ERROR, 'no answer produced'
78 , $self->faultNoAnswerProduced($name));
79 }
80  
81 0 ▶ if(ref $answer ne 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $answer ne "HASH") 0 0 0
82 0 { notice __x"procedure {name} did not return a HASH", name => $name;
83 0 return ( RC_INTERNAL_SERVER_ERROR, 'invalid answer produced'
84 , $self->faultNoAnswerProduced($name));
85 }
86  
87 0 ▶ my $rc = (delete $answer->{_RETURN_CODE}) || RC_OK;
Condition0%0/2
delete $answer->{'_RETURN_CODE'} || 200
l!l
00
MC/DC0%0/1
delete $answer->{'_RETURN_CODE'} || 200
delete $answer->{'_RETURN_CODE'}
Truth table0%0/2
A
A= delete $answer->{'_RETURN_CODE'}
Aresult
11
00
88 0 ▶ my $rc_txt = delete $answer->{_RETURN_TEXT} || 'Answer included';
Condition0%0/2
delete $answer->{'_RETURN_TEXT'} || 'Answer included'
l!l
00
MC/DC0%0/1
delete $answer->{'_RETURN_TEXT'} || 'Answer included'
delete $answer->{'_RETURN_TEXT'}
Truth table0%0/2
A
A= delete $answer->{'_RETURN_TEXT'}
Aresult
11
00
89  
90 0 ▶ my $xmlout = try { $encode->($answer) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 0 ▶ $@ or return ($rc, $rc_txt, $xmlout);
Branch: 1 branch
BranchTrueFalseTotal
$@ or return $rc, $rc_txt, $xmlout 0 0 0
92  
93 0 my $fatal = $@->wasFatal;
94 0 $fatal->throw(reason => 'ALERT', is_fatal => 0);
95  
96 0 ( RC_INTERNAL_SERVER_ERROR, 'created response not valid'
97 , $self->faultResponseInvalid($name, $fatal)
98 );
99 0 };
100 }
101  
102  
103 sub compileFilter(@)
104 0 ▶{ my ($self, %args) = @_;
Subroutine compileFilter: not called CC=5 SCAR=34.0
Pod documented
105  
106 0 my $need_node;
107 0 ▶ if($args{style} eq 'rpc')
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'style'} eq 'rpc') { } 0 0 0
108 { # RPC-style wraps the body parameters in the procedure name. That's
109 # a logical construction.
110 0 ▶ $need_node = $args{body}{procedure} or panic;
Branch: 1 branch
BranchTrueFalseTotal
$need_node = $args{"body"}{"procedure"} or &panic() 0 0 0
111 }
112 else
113 { # Document-style does *not* contain the procedure name anywhere! We
114 # can only base the selection on the type of the elements. Therefore,
115 # procedure selection is often based on HTTP header (which was created
116 # for other purposes.
117 0 my $first = $args{body}{parts}[0];
118 0 ▶ $need_node = $first ? $first->{element} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$first ? : 0 0 0
119 }
120  
121 $need_node
122 0 ▶ or return sub { !defined $_[1]->{body}[0] }; # empty body
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$need_node or return sub { not defined $_[1]{"body"}[0]; } 0 0 0
123  
124 0 my ($need_ns, $need_local) = unpack_type($need_node);
125  
126 # The returned code-ref is called with (XML, INFO)
127 sub {
128 0 ▶ my ($xml, $info) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
129 0 (my $body) = $xml->getChildrenByLocalName('Body');
130 0 (my $has) = $body->getElementsByTagNameNS($need_ns, $need_local);
131 0 defined $has;
132 0 };
133 }
134  
135  
136 sub faultWriter()
137 0 ▶{ my $thing = shift;
Subroutine faultWriter: not called CC=3 SCAR=24.8
Pod documented
138 0 ▶ my $self = ref $thing ? $thing : $thing->new;
Branch: 1 branch
BranchTrueFalseTotal
ref $thing ? : 0 0 0
139 0 ▶ $self->{fault_writer} ||= $self->compileMessage('SENDER');
Condition0%0/3
$self->{"fault_writer"} ||= $self->compileMessage("SENDER")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"fault_writer"} ||= $self->compileMessage("SENDER")
$self->{"fault_writer"} $self->compileMessage("SENDER")
Truth table0%0/3
A ||= B
A= $self->{"fault_writer"}B= $self->compileMessage("SENDER")
ABresult
1X1
011
000
140 }
141  
142 7 1;
« blib/lib/XML/Compile/SOAP/Trace.pm ↑ Summary lib/XML/Compile/Transport/SOAPHTTP.pm »