blib/lib/SOAP/WSDL/Server/CGI.pm

filter: Statementstmt 92.0% 69 / 75 Branchbran 87.5% 14 / 16 Conditioncond 73.3% 11 / 15 MC/DCmcdc 55.5% 5 / 9 Subroutinesub 100% 14 / 14 Podpod 100% 1 / 1 totaltotal 87.6% 114 / 130 CC 15 SCAR 18.6
CC
15
Cov
89%
handle
12.7
_output
4.1
BEGIN
1.0
CRAP 6.5
« blib/lib/SOAP/WSDL/Types.pm ↑ Summary blib/lib/SOAP/WSDL/XSD/Typelib/Builtin/anyType.pm »
1 package SOAP::WSDL::Server::CGI;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use HTTP::Status;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Class::Std::Fast::Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use base qw(SOAP::WSDL::Server);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 our $VERSION = 3.004;
18  
19 # mostly copied from SOAP::Lite. Unfortunately we can't use SOAP::Lite's CGI
20 # server directly - we would have to swap out it's base class...
21 #
22 # This should be a warning for us: We should not handle methods via inheritance,
23 # but via some plugin mechanism, to allow alternative handlers to be plugged
24 # in.
25  
26 10 ▶sub handle {
Subroutine handle: called CC=12 SCAR=25.4
Pod documented
27 10 my $self = shift;
28 10 my $response;
29 10 ▶ my $length = $ENV{'CONTENT_LENGTH'} || 0;
Condition100%2/2
$ENV{'CONTENT_LENGTH'} || 0
l!l
91
MC/DC100%1/1
$ENV{'CONTENT_LENGTH'} || 0
$ENV{'CONTENT_LENGTH'}
Truth table100%2/2
A
A= $ENV{'CONTENT_LENGTH'}
Aresult
11
00
30  
31 10 ▶ if (!$length) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($length) 1 9 10
32 1 $response = HTTP::Response->new(411); # LENGTH REQUIRED
33 1 $self->_output($response);
34 1 return;
35 }
36  
37 9 ▶ if (exists $ENV{EXPECT} && $ENV{EXPECT} =~ /\b100-Continue\b/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"EXPECT"} and $ENV{"EXPECT"} =~ /\b100-Continue\b/i) 1 8 9
Condition100%3/3
exists $ENV{"EXPECT"} and $ENV{"EXPECT"} =~ /\b100-Continue\b/i
!ll&&!rl&&r
711
MC/DC100%2/2
exists $ENV{"EXPECT"} and $ENV{"EXPECT"} =~ /\b100-Continue\b/i
exists $ENV{"EXPECT"} $ENV{"EXPECT"} =~ /\b100-Continue\b/i
Truth table100%3/3
A and B
A= exists $ENV{"EXPECT"}B= $ENV{"EXPECT"} =~ /\b100-Continue\b/i
ABresult
0X0
100
111
38 1 print "HTTP/1.1 100 Continue\r\n\r\n";
39 }
40  
41 9 my $content = q{};
42 9 my $buffer;
43  
44 # do we need to use bytes; here ?
45 9 binmode(STDIN);
46 9 ▶ while (read(STDIN,$buffer,$length - length($content))) {
Branch: 1 branch
BranchTrueFalseTotal
if (read STDIN, $buffer, $length - length($content)) 4 9 13
47 4 $content .= $buffer;
48 }
49  
50 my $request = HTTP::Request->new(
51 $ENV{'REQUEST_METHOD'} || '' => $ENV{'SCRIPT_NAME'},
52 HTTP::Headers->new(
53 map {
54 9 ▶ (/^HTTP_(.+)/i
Condition100%2/2
$ENV{'REQUEST_METHOD'} || ''
l!l
72
MC/DC100%1/1
$ENV{'REQUEST_METHOD'} || ''
$ENV{'REQUEST_METHOD'}
Truth table100%2/2
A
A= $ENV{'REQUEST_METHOD'}
Aresult
11
00
55 ? ($1=~m/SOAPACTION/)
56 ?('SOAPAction')
57 :($1)
58 : $_
59 35 ▶ ) => $ENV{$_}
Branch: 2 branches
BranchTrueFalseTotal
/^HTTP_(.+)/i ? : 7 28 35
$1 =~ /SOAPACTION/ ? : 1 6 7
60 } keys %ENV),
61 $content,
62 );
63  
64 # we copy the response message around here.
65 # Passing by reference would be much better...
66 9 my $response_message = eval { $self->SUPER::handle($request) };
67 # caveat: SOAP::WSDL::SOAP::Typelib::Fault11 is false in bool context...
68 9 ▶ if ($@ || blessed $@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or builtin::blessed($@)) { } 9 0 9
Condition33%1/3
$@ or builtin::blessed($@)
l!l&&r!l&&!r
900
MC/DC0%0/2
$@ or builtin::blessed($@)
$@ builtin::blessed($@)
Truth table33%1/3
A or B
A= $@B= builtin::blessed($@)
ABresult
1X1
011
000
69 9 my $exception = $@;
70 9 $response = HTTP::Response->new(500);
71 9 $response->header('Content-type' => 'text/xml; charset="utf-8"');
72 9 ▶ if (blessed($exception)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($exception)) { } 0 9 9
73 0 $response->content( $self->get_serializer->serialize({
74 body => $exception
75 })
76 );
77 }
78 else {
79 9 $response->content($exception);
80 }
81 }
82 else {
83 0 $response = HTTP::Response->new(200);
84 0 $response->header('Content-type' => 'text/xml; charset="utf-8"');
85 0 $response->content( encode('utf8', $response_message ) );
86 {
87 0 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.2
88 0 $response->header('Content-length', length $response_message);
89 }
90 }
91  
92 9 $self->_output($response);
93 9 return;
94 }
95  
96 10 ▶sub _output :PRIVATE {
Subroutine _output: called CC=4 SCAR=14.0
97 10 my ($self, $response) = @_;
98 # imitate nph- cgi for IIS (pointed by Murray Nesbitt)
99 my $status = defined($ENV{'SERVER_SOFTWARE'}) && $ENV{'SERVER_SOFTWARE'}=~/IIS/
100 10 ▶ ? $ENV{SERVER_PROTOCOL} || 'HTTP/1.0'
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'SERVER_SOFTWARE'} && $ENV{'SERVER_SOFTWARE'} =~ /IIS/ ? : 1 9 10
Condition60%3/5
defined $ENV{"SERVER_SOFTWARE"} and $ENV{"SERVER_SOFTWARE"} =~ /IIS/
!ll&&!rl&&r
901
$ENV{"SERVER_PROTOCOL"} or "HTTP/1.0"
l!l
01
MC/DC50%1/2
defined $ENV{"SERVER_SOFTWARE"} and $ENV{"SERVER_SOFTWARE"} =~ /IIS/
defined $ENV{"SERVER_SOFTWARE"} $ENV{"SERVER_SOFTWARE"} =~ /IIS/
MC/DC0%0/1
$ENV{"SERVER_PROTOCOL"} or "HTTP/1.0"
$ENV{"SERVER_PROTOCOL"}
Truth table66%2/3
A and B
A= defined $ENV{"SERVER_SOFTWARE"}B= $ENV{"SERVER_SOFTWARE"} =~ /IIS/
ABresult
0X0
100
111
Truth table50%1/2
A
A= $ENV{"SERVER_PROTOCOL"}
Aresult
11
00
101 : 'Status:';
102  
103 10 my $code = $response->code;
104 10 binmode(STDOUT);
105 10 print STDOUT "$status $code ", HTTP::Status::status_message($code)
106 , "\015\012", $response->headers_as_string("\015\012")
107 , "\015\012", $response->content;
108 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 1 1;
111  
112 =pod
113  
114 =head1 NAME
115  
116 SOAP::WSDL::Server::CGI - CGI based SOAP server
117  
118 =head1 SYNOPSIS
119  
120 use MyServer::TestService::TestPort;
121 my $server = MyServer::TestService::TestPort->new({
122 dispatch_to => 'main',
123 transport_class => 'SOAP::WSDL::Server::CGI', # optional, default
124 });
125 $server->handle();
126  
127 =head1 USAGE
128  
129 To use SOAP::WSDL::Server::CGI efficiently, you should first create a server
130 interface using L<wsdl2perl.pl|wsdl2perl.pl>.
131  
132 SOAP::WSDL::Server dispatches all calls to appropriately named methods in the
133 class or object set via C<dispatch_to>.
134  
135 See the generated server class on details.
136  
137 =head1 DESCRIPTION
138  
139 Lightweight CGI based SOAP server. SOAP::WSDL::Server::CGI does not provide
140 the fancier things of CGI handling, like URL parsing, parameter extraction
141 or the like, but provides a basic SOAP server using SOAP::WSDL::Server.
142  
143 =head1 METHODS
144  
145 =head2 handle
146  
147 See synopsis above.
148  
149 =head1 LICENSE AND COPYRIGHT
150  
151 Copyright 2004-2008 Martin Kutter.
152  
153 This file is part of SOAP-WSDL. You may distribute/modify it under the same
154 terms as perl itself
155  
156 =head1 AUTHOR
157  
158 Martin Kutter E<lt>martin.kutter fen-net.deE<gt>
159  
160 =head1 REPOSITORY INFORMATION
161  
162 $Rev: 391 $
163 $LastChangedBy: kutterma $
164 $Id: Client.pm 391 2007-11-17 21:56:13Z kutterma $
165 $HeadURL: https://soap-wsdl.svn.sourceforge.net/svnroot/soap-wsdl/SOAP-WSDL/trunk/lib/SOAP/WSDL/Client.pm $
166  
167 =cut
« blib/lib/SOAP/WSDL/Types.pm ↑ Summary blib/lib/SOAP/WSDL/XSD/Typelib/Builtin/anyType.pm »