Dancer2/Handler.pm

filter: Statementstmt 86.6% 65 / 75 Branchbran 54.1% 13 / 24 Conditioncond 45.0% 9 / 20 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 2 totaltotal 69.0% 98 / 142 CC 21 SCAR 33.8
CC
21
Cov
73%
handle
42.9
BEGIN
1.0
BEGIN
1.0
CRAP 29.4
↑ Summary 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
Subroutine BEGIN: called CC=1 SCAR=0.0
15 , RC_METHOD_NOT_ALLOWED => 405
16 , RC_NOT_ACCEPTABLE => 406
17 , RC_SERVER_ERROR => 500
18 3 };
19  
20 #--------------------
21  
22  
23 sub init($)
24 4 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
25 4 $self->SUPER::init($args);
26 4 $self->_init($args);
27 4 $self;
28 }
29  
30 #------------------------------
31  
32 sub _init($)
33 4 ▶{ my ($self, $args) = @_;
Subroutine _init: called CC=1 SCAR=0.0
34 4 $self->{preprocess} = $args->{preprocess};
35 4 $self->{postprocess} = $args->{postprocess};
36 4 $self;
37 }
38  
39  
40 3 my $parser = XML::LibXML->new;
41 sub handle($)
42 4 ▶{ my ($self, $dsl) = @_;
Subroutine handle: called CC=21 SCAR=37.6
Pod undocumented
43  
44 notice __x"WSA module loaded, but not used"
45 0 ▶ 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 4 4
Condition33%1/3
"XML::Compile::SOAP::WSA"->can("new") and not keys %{$$self{"wsa_input"};}
!ll&&!rl&&r
400
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
46 4 $self->{wsa_input_rev} = +{ reverse %{$self->{wsa_input}} };
47  
48 #return $self->sendWsdl($req)
49 #if $req->method eq 'GET' && uc($req->uri->query || '') eq 'WSDL';
50  
51 4 my $method = $dsl->app->request->method;
52 4 ▶ my $ct = $dsl->app->request->content_type || 'text/plain';
Condition50%1/2
$dsl->app->request->content_type || 'text/plain'
l!l
40
MC/DC0%0/1
$dsl->app->request->content_type || 'text/plain'
$dsl->app->request->content_type
Truth table50%1/2
A
A= $dsl->app->request->content_type
Aresult
11
00
53 4 $ct =~ s/\;\s.*//;
54  
55 4 my ($rc, $msg, $err, $content, $mime);
56 4 ▶ if($method ne 'POST' && $method ne 'M-POST')
Branch: 2 branches
BranchTrueFalseTotal
if ($method ne 'POST' and $method ne 'M-POST') { } 0 4 4
elsif (not $ct =~ /\bxml\b/) { } 0 4 4
Condition33%1/3
$method ne "POST" and $method ne "M-POST"
!ll&&!rl&&r
400
MC/DC0%0/2
$method ne "POST" and $method ne "M-POST"
$method ne "POST" $method ne "M-POST"
Truth table33%1/3
A and B
A= $method ne "POST"B= $method ne "M-POST"
ABresult
0X0
100
111
57 0 { ($rc, $msg) = (RC_METHOD_NOT_ALLOWED, 'only POST or M-POST');
58 0 $err = 'attempt to connect via GET';
59 }
60 elsif($ct !~ m/\bxml\b/)
61 0 { ($rc, $msg) = (RC_NOT_ACCEPTABLE, 'required is XML');
62 0 $err = 'content-type seems to be '.$ct.', must be some XML';
63 }
64 else
65 4 ▶ { my $charset = $dsl->app->request->headers->content_type_charset || 'ascii';
Condition50%1/2
$dsl->app->request->headers->content_type_charset || 'ascii'
l!l
40
MC/DC0%0/1
$dsl->app->request->headers->content_type_charset || 'ascii'
$dsl->app->request->headers->content_type_charset
Truth table50%1/2
A
A= $dsl->app->request->headers->content_type_charset
Aresult
11
00
66 4 ▶ my $xmlin = try { $parser->parse_string( decode( $charset, $dsl->app->request->content ) ); };
Subroutine __ANON__: called CC=1 SCAR=0.0
67  
68 4 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 4 4
69 0 ($rc, $msg, $err) = $self->faultInvalidXML($@->died);
70 } else {
71 4 my $version = undef;
72 4 ▶ $xmlin= $xmlin->documentElement
Branch: 1 branch
BranchTrueFalseTotal
if $xmlin->isa("XML::LibXML::Document") 4 0 4
73 if $xmlin->isa('XML::LibXML::Document');
74  
75 4 my $local = $xmlin->localName;
76  
77 4 ▶ if( $local eq 'Envelope' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($local eq "Envelope") 4 0 4
78 4 ▶ my $envns = $xmlin->namespaceURI || '';
Condition50%1/2
$xmlin->namespaceURI || ''
l!l
40
MC/DC0%0/1
$xmlin->namespaceURI || ''
$xmlin->namespaceURI
Truth table50%1/2
A
A= $xmlin->namespaceURI
Aresult
11
00
79 4 my $proto = XML::Compile::SOAP->fromEnvelope($envns);
80 4 ▶ if( $proto ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proto) 4 0 4
81 4 $version = $proto->version;
82 }
83 }
84 4 ▶ my $action = $dsl->app->request->header('SOAPAction') || $dsl->app->request->header('Action') || $dsl->app->request->header('action') || '';
Condition50%4/8
$dsl->app->request->header('SOAPAction') || $dsl->app->request->header('Action') || $dsl->app->request->header('action') || ''
l!l
40
$dsl->app->request->header("SOAPAction") or $dsl->app->request->header("Action") or $dsl->app->request->header("action")
l!l&&r!l&&!r
400
$dsl->app->request->header("SOAPAction") or $dsl->app->request->header("Action")
l!l&&r!l&&!r
220
MC/DC0%0/3
$dsl->app->request->header('SOAPAction') || $dsl->app->request->header('Action') || $dsl->app->request->header('action') || ''
$dsl->app->request->header("SOAPAction") $dsl->app->request->header("Action") $dsl->app->request->header("action")
Truth table50%2/4
A or B or C
A= $dsl->app->request->header("SOAPAction")B= $dsl->app->request->header("Action")C= $dsl->app->request->header("action")
ABCresult
1XX1
01X1
0011
0000
85 4 $action =~ s/["'\s]//g; # sometimes illegal quoting and blanks "
86 4 ($rc, $msg, my $xmlout) = $self->process($xmlin, $dsl, $action);
87  
88 4 ▶ if(UNIVERSAL::isa($xmlout, 'XML::LibXML::Document'))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($xmlout, 'XML::LibXML::Document')) { } 4 0 4
89 {
90 4 ▶ $content = $xmlout->toString($rc == RC_OK ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$rc == 200 ? : 4 0 4
91 4 ▶ if( $version eq "SOAP11" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version eq 'SOAP11') { } 2 2 4
92 2 $mime = 'text/xml; charset="utf-8"';
93 } else {
94 2 $mime = "application/soap+xml; charset=utf-8";
95 }
96 }
97 else
98 {
99 0 $err = $xmlout;
100 }
101 }
102 }
103  
104 4 ▶ if( $err ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 4 4
105 0 $content = $err;# $bytes = "[$rc] $err\n";
106 0 $mime = 'text/plain';
107 }
108 4 $dsl->status( $rc );
109 4 $dsl->content_type( $mime );
110 4 ▶ $dsl->header( Warning => "199 $msg" ) if length( $msg );
Branch: 1 branch
BranchTrueFalseTotal
if length $msg 4 0 4
111 #$dsl->content_length(length $bytes);
112 0 return $content;
113 }
114  
115 3 1;
↑ Summary Dancer2.pm »