blib/lib/XML/Compile/SOAP/Daemon/Dancer2/Handler.pm

filter: Statementstmt 59.6% 37 / 62 Branchbran 7.1% 1 / 14 Conditioncond 8.3% 1 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 45.7% 49 / 107 SCAR 37.4
CC
13
Cov
44%
handle
126.2
BEGIN
1.0
BEGIN
1.0
CRAP 42.2
↑ Summary blib/lib/XML/Compile/SOAP/Daemon/Dancer2.pm »
1 package XML::Compile::SOAP::Daemon::Dancer2::Handler;
2 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 $VERSION = '0.1';
6  
7 3 ▶use parent 'XML::Compile::SOAP::Daemon';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use Log::Report 'xml-compile-soap-daemon';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 use constant
14 3 { RC_OK => 200
15 , RC_METHOD_NOT_ALLOWED => 405
16 , RC_NOT_ACCEPTABLE => 406
17 , RC_SERVER_ERROR => 500
18 3 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 #--------------------
21  
22  
23 sub init($)
24 2 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
25 2 $self->SUPER::init($args);
26 2 $self->_init($args);
27 2 $self;
28 }
29  
30 #------------------------------
31  
32 sub _init($)
33 2 ▶{ my ($self, $args) = @_;
Subroutine _init: called CC=1 SCAR=0.0
34 2 $self->{preprocess} = $args->{preprocess};
35 2 $self->{postprocess} = $args->{postprocess};
36 2 $self;
37 }
38  
39  
40 # PSGI request handler
41 #will be called from the route
42 #sub call($)
43 #{ my ($self, $env) = @_;
44 #my $res = eval { $self->_call($env) };
45 #$res ||= Plack::Response->new
46 #( RC_SERVER_ERROR
47 #, [Content_Type => 'text/plain']
48 #, [$@]
49 #);
50 #$res->finalize;
51 #}
52  
53 sub handle($)
54 2 ▶{ my ($self, $dsl) = @_;
Subroutine handle: called CC=13 SCAR=48.4
Pod undocumented
55  
56 notice __x"WSA module loaded, but not used"
57 2 ▶ if XML::Compile::SOAP::WSA->can('new') && !keys %{$self->{wsa_input}};
Branch: 1 branch
BranchTrueFalseTotal
if "XML::Compile::SOAP::WSA"->can("new") and not keys %{$$self{"wsa_input"};} 0 2 2
Condition33%1/3
"XML::Compile::SOAP::WSA"->can("new") and not keys %{$$self{"wsa_input"};}
!ll&&!rl&&r
200
MC/DC0%0/2
"XML::Compile::SOAP::WSA"->can("new") and not keys %{$$self{"wsa_input"};}
"XML::Compile::SOAP::WSA"->can("new") not keys %{$$self{"wsa_input"};}
Truth table33%1/3
A and not(B)
A= "XML::Compile::SOAP::WSA"->can("new")B= not keys %{$$self{"wsa_input"};}
ABresult
0X0
100
111
58 2 $self->{wsa_input_rev} = +{ reverse %{$self->{wsa_input}} };
59  
60 #return $self->sendWsdl($req)
61 #if $req->method eq 'GET' && uc($req->uri->query || '') eq 'WSDL';
62  
63 2 my $method = $dsl->request->method;
64 0 ▶ my $ct = $dsl->request->content_type || 'text/plain';
Condition0%0/2
$dsl->request->content_type || 'text/plain'
l!l
00
MC/DC0%0/1
$dsl->request->content_type || 'text/plain'
$dsl->request->content_type
Truth table0%0/2
A
A= $dsl->request->content_type
Aresult
11
00
65 0 $ct =~ s/\;\s.*//;
66  
67 0 my ($rc, $msg, $err, $content, $mime);
68 0 ▶ if($method ne 'POST' && $method ne 'M-POST')
Branch: 2 branches
BranchTrueFalseTotal
if ($method ne 'POST' and $method ne 'M-POST') { } 0 0 0
elsif (not $ct =~ /\bxml\b/) { } 0 0 0
Condition0%0/3
$method ne "POST" and $method ne "M-POST"
!ll&&!rl&&r
000
MC/DC0%0/2
$method ne "POST" and $method ne "M-POST"
$method ne "POST" $method ne "M-POST"
Truth table0%0/3
A and B
A= $method ne "POST"B= $method ne "M-POST"
ABresult
0X0
100
111
69 0 { ($rc, $msg) = (RC_METHOD_NOT_ALLOWED, 'only POST or M-POST');
70 0 $err = 'attempt to connect via GET';
71 }
72 elsif($ct !~ m/\bxml\b/)
73 0 { ($rc, $msg) = (RC_NOT_ACCEPTABLE, 'required is XML');
74 0 $err = 'content-type seems to be '.$ct.', must be some XML';
75 }
76 else
77 0 ▶ { my $charset = $dsl->request->headers->content_type_charset || 'ascii';
Condition0%0/2
$dsl->request->headers->content_type_charset || 'ascii'
l!l
00
MC/DC0%0/1
$dsl->request->headers->content_type_charset || 'ascii'
$dsl->request->headers->content_type_charset
Truth table0%0/2
A
A= $dsl->request->headers->content_type_charset
Aresult
11
00
78 0 my $xmlin = decode $charset, $dsl->request->content;
79 0 ▶ my $action = $dsl->request->header('SOAPAction') || '';
Condition0%0/2
$dsl->request->header('SOAPAction') || ''
l!l
00
MC/DC0%0/1
$dsl->request->header('SOAPAction') || ''
$dsl->request->header('SOAPAction')
Truth table0%0/2
A
A= $dsl->request->header('SOAPAction')
Aresult
11
00
80 0 $action =~ s/["'\s]//g; # sometimes illegal quoting and blanks "
81 0 ($rc, $msg, my $xmlout) = $self->process(\$xmlin, $dsl, $action);
82 #($rc, $msg, my $xmlout) = (RC_OK, 'blab', XML::LibXML::Document->createDocument() );
83 #($rc, $msg, my $xmlout) = (RC_OK, 'blab', 'pppp' );
84  
85 0 ▶ if(UNIVERSAL::isa($xmlout, 'XML::LibXML::Document'))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($xmlout, 'XML::LibXML::Document')) { } 0 0 0
86 0 ▶ { $content = $xmlout->toString($rc == RC_OK ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$rc == 200 ? : 0 0 0
87 0 $mime = 'text/xml; charset="utf-8"';
88 }
89 else
90 {
91 0 $err = $xmlout;
92 }
93 }
94  
95 0 ▶ if( $err ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
96 0 $content = $err;# $bytes = "[$rc] $err\n";
97 0 $mime = 'text/plain';
98 }
99 0 $dsl->status( $rc );
100 0 $dsl->content_type( $mime );
101 0 ▶ $dsl->header( Warning => "199 $msg" ) if length( $msg );
Branch: 1 branch
BranchTrueFalseTotal
if length $msg 0 0 0
102 #$dsl->content_length(length $bytes);
103 0 return $content;
104 }
105  
106 #manage from the route itself
107 #sub setWsdlResponse($;$)
108 #{ my ($self, $fn, $ft) = @_;
109 #local *WSDL;
110 #open WSDL, '<:raw', $fn
111 #or fault __x"cannot read WSDL from {file}", file => $fn;
112 #local $/;
113 #$self->{wsdl_data} = <WSDL>;
114 #$self->{wsdl_type} = $ft || 'application/wsdl+xml';
115 #close WSDL;
116 #}
117  
118 #sub sendWsdl($)
119 #{ my ($self, $req) = @_;
120  
121 #my $res = $req->new_response(RC_OK,
122 #{ Warning => '199 WSDL specification'
123 #, Content_Type => $self->{wsdl_type}.'; charset=utf-8'
124 #, Content_Length => length($self->{wsdl_data})
125 #}, $self->{wsdl_data});
126  
127 #$res;
128 #}
129  
130 #-----------------------------
131  
132 3 1;
133  
134  
135 3 1;
↑ Summary blib/lib/XML/Compile/SOAP/Daemon/Dancer2.pm »