lib/SOAP/Transport/TCP.pm

filter: Statementstmt 56.1% 78 / 139 Branchbran 23.4% 15 / 64 Conditioncond 19.0% 8 / 42 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 62.5% 15 / 24 Podpod n/a totaltotal 39.3% 116 / 295 CC 46 SCAR 33.7
CC
46
Cov
41%
new
110.0
syswrite
30.0
sysread
30.0
CRAP 29.0
« lib/SOAP/Lite.pm ↑ Summary lib/SOAP/Packager.pm »
1 # ======================================================================
2 #
3 # Copyright (C) 2000-2001 Paul Kulchenko (paulclinger@yahoo.com)
4 # SOAP::Lite is free software; you can redistribute it
5 # and/or modify it under the same terms as Perl itself.
6 #
7 # $Id: TCP.pm 384 2011-08-16 17:08:08Z kutterma $
8 #
9 # ======================================================================
10  
11 package SOAP::Transport::TCP;
12  
13 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 our $VERSION = 1.12;
16  
17 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use IO::SessionData;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 # ======================================================================
23  
24 package URI::tcp; # ok, let's do 'tcp://' scheme
25  
26 2 our $VERSION = 0.715;
27  
28 2 require URI::_server;
29 2 @URI::tcp::ISA=qw(URI::_server);
30  
31 # ======================================================================
32  
33 package SOAP::Transport::TCP::Client;
34  
35 2 our $VERSION = 0.715;
36  
37 2 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 require SOAP::Lite;
39 2 @ISA = qw(SOAP::Client);
40  
41 1 ▶sub DESTROY { SOAP::Trace::objects('()') }
Subroutine DESTROY: called CC=1 SCAR=0.0
42  
43 sub new {
44 4 ▶ my $self = shift;
Subroutine new: called CC=9 SCAR=23.0
45  
46 4 ▶ unless (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 1 3 4
47 1 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
48 1 my(@params, @methods);
49 1 ▶ while (@_) { $class->can($_[0]) ? push(@methods, shift() => shift) : push(@params, shift) }
Branch: 2 branches
BranchTrueFalseTotal
if (@_) 1 1 2
$class->can($_[0]) ? : 1 0 1
50 1 $self = bless {@params} => $class;
51 1 ▶ while (@methods) { my($method, $params) = splice(@methods,0,2);
Branch: 1 branch
BranchTrueFalseTotal
if (@methods) 1 1 2
52 1 ▶ $self->$method(ref $params eq 'ARRAY' ? @$params : $params)
Branch: 1 branch
BranchTrueFalseTotal
ref $params eq 'ARRAY' ? : 0 1 1
53 }
54 # use SSL if there is any parameter with SSL_* in the name
55 1 ▶ $self->SSL(1) if !$self->SSL && grep /^SSL_/, keys %$self;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->SSL and grep /^SSL_/, keys %$self 0 1 1
Condition33%1/3
not $self->SSL and grep /^SSL_/, keys %$self
!ll&&!rl&&r
010
MC/DC0%0/2
not $self->SSL and grep /^SSL_/, keys %$self
not $self->SSL grep /^SSL_/, keys %$self
Truth table33%1/3
not(A) and B
A= not $self->SSLB= grep /^SSL_/, keys %$self
ABresult
0X0
100
111
56 1 SOAP::Trace::objects('()');
57 }
58 4 return $self;
59 }
60  
61 sub SSL {
62 2 ▶ my $self = shift->new;
Subroutine SSL: called CC=2 SCAR=7.2
63 2 ▶ @_ ? ($self->{_SSL} = shift, return $self) : return $self->{_SSL};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 2 2
64 }
65  
66 1 ▶sub io_socket_class { shift->SSL ? 'IO::Socket::SSL' : 'IO::Socket::INET' }
Subroutine io_socket_class: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
(shift())->SSL ? : 0 1 1
67  
68 sub syswrite {
69 0 ▶ my($self, $sock, $data) = @_;
Subroutine syswrite: not called CC=5 SCAR=34.0
70  
71 0 my $timeout = $sock->timeout;
72  
73 0 my $select = IO::Select->new($sock);
74  
75 0 my $len = length $data;
76 0 ▶ while (length $data > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $data > 0) 0 0 0
77 0 ▶ return unless $select->can_write($timeout);
Branch: 1 branch
BranchTrueFalseTotal
unless $select->can_write($timeout) 0 0 0
78 0 local $SIG{PIPE} = 'IGNORE';
79 # added length() to make it work on Mac. Thanks to Robin Fuller <rfuller@broadjump.com>
80 0 my $wc = syswrite($sock, $data, length($data));
81 0 ▶ if (defined $wc) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $wc) { } 0 0 0
elsif (not IO::SessionData::WOULDBLOCK($!)) { } 0 0 0
82 0 substr($data, 0, $wc) = '';
83 } elsif (!IO::SessionData::WOULDBLOCK($!)) {
84 0 return;
85 }
86 }
87 0 return $len;
88 }
89  
90 sub sysread {
91 0 ▶ my($self, $sock) = @_;
Subroutine sysread: not called CC=5 SCAR=34.0
92  
93 0 my $timeout = $sock->timeout;
94 0 my $select = IO::Select->new($sock);
95  
96 0 my $result = '';
97 0 my $data;
98 0 while (1) {
99 0 ▶ return unless $select->can_read($timeout);
Branch: 1 branch
BranchTrueFalseTotal
unless $select->can_read($timeout) 0 0 0
100 0 my $rc = sysread($sock, $data, 4096);
101 0 ▶ if ($rc) {
Branch: 3 branches
BranchTrueFalseTotal
if ($rc) { } 0 0 0
elsif (defined $rc) { } 0 0 0
elsif (not IO::SessionData::WOULDBLOCK($!)) { } 0 0 0
102 0 $result .= $data;
103 } elsif (defined $rc) {
104 0 return $result;
105 } elsif (!IO::SessionData::WOULDBLOCK($!)) {
106 0 return;
107 }
108 }
109 }
110  
111 sub send_receive {
112 1 ▶ my($self, %parameters) = @_;
Subroutine send_receive: called CC=13 SCAR=33.7
113 my($envelope, $endpoint, $action) =
114 1 @parameters{qw(envelope endpoint action)};
115  
116 1 ▶ $endpoint ||= $self->endpoint;
Condition33%1/3
$endpoint ||= $self->endpoint
l!l&&r!l&&!r
010
MC/DC0%0/2
$endpoint ||= $self->endpoint
$endpoint $self->endpoint
Truth table33%1/3
A ||= B
A= $endpointB= $self->endpoint
ABresult
1X1
011
000
117 1 ▶ warn "URLs with 'tcp:' scheme are deprecated. Use 'tcp://'. Still continue\n"
Branch: 1 branch
BranchTrueFalseTotal
if $endpoint =~ s[^tcp:(//)?][tcp://]i and not $1 0 1 1
Condition33%1/3
$endpoint =~ s[^tcp:(//)?][tcp://]i and not $1
!ll&&!rl&&r
010
MC/DC0%0/2
$endpoint =~ s[^tcp:(//)?][tcp://]i and not $1
$endpoint =~ s[^tcp:(//)?][tcp://]i not $1
Truth table33%1/3
A and not(B)
A= $endpoint =~ s[^tcp:(//)?][tcp://]iB= not $1
ABresult
0X0
100
111
118 if $endpoint =~ s!^tcp:(//)?!tcp://!i && !$1;
119 1 my $uri = URI->new($endpoint);
120  
121 1 local($^W, $@, $!);
122 1 my $socket = $self->io_socket_class;
123 1 ▶ eval "require $socket" or Carp::croak $@ unless UNIVERSAL::can($socket => 'new');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can($socket, "new") 0 1 1
Condition16%1/6
UNIVERSAL::can($socket, 'new') || (eval "require $socket" || Carp::croak($@))
l!l&&r!l&&!r
100
eval "require $socket" or Carp::croak($@)
l!l&&r!l&&!r
000
MC/DC0%0/3
UNIVERSAL::can($socket, 'new') || (eval "require $socket" || Carp::croak($@))
UNIVERSAL::can($socket, 'new') eval "require $socket" Carp::croak($@)
Truth table0%0/4
A || B or C
A= UNIVERSAL::can($socket, 'new')B= eval "require $socket"C= Carp::croak($@)
ABCresult
1XX1
01X1
0011
0000
124 1 my $sock = $socket->new (
125 PeerAddr => $uri->host, PeerPort => $uri->port, Proto => $uri->scheme, %$self
126 );
127  
128 1 SOAP::Trace::debug($envelope);
129  
130 # bytelength hack. See SOAP::Transport::HTTP.pm for details.
131 1 my $bytelength = SOAP::Utils::bytelength($envelope);
132 1 ▶ $envelope = pack('C0A*', $envelope)
Branch: 1 branch
BranchTrueFalseTotal
if not $SOAP::Constants::DO_NOT_USE_LWP_LENGTH_HACK and length $envelope != $bytelength 0 1 1
Condition33%1/3
not $SOAP::Constants::DO_NOT_USE_LWP_LENGTH_HACK and length $envelope != $bytelength
!ll&&!rl&&r
010
MC/DC0%0/2
not $SOAP::Constants::DO_NOT_USE_LWP_LENGTH_HACK and length $envelope != $bytelength
not $SOAP::Constants::DO_NOT_USE_LWP_LENGTH_HACK length $envelope != $bytelength
Truth table33%1/3
not(A) and B
A= not $SOAP::Constants::DO_NOT_USE_LWP_LENGTH_HACKB= length $envelope != $bytelength
ABresult
0X0
100
111
133 if !$SOAP::Constants::DO_NOT_USE_LWP_LENGTH_HACK && length($envelope) != $bytelength;
134  
135 1 my $result;
136 1 ▶ if ($sock) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sock) 0 1 1
137 0 $sock->blocking(0);
138 0 ▶ $self->syswrite($sock, $envelope) and
Branch: 1 branch
BranchTrueFalseTotal
$self->syswrite($sock, $envelope) and $sock->shutdown(1) and $result = $self->sysread($sock) 0 0 0
Condition0%0/3
$self->syswrite($sock, $envelope) and $sock->shutdown(1)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->syswrite($sock, $envelope) and $sock->shutdown(1)
$self->syswrite($sock, $envelope) $sock->shutdown(1)
Truth table0%0/3
A and B
A= $self->syswrite($sock, $envelope)B= $sock->shutdown(1)
ABresult
0X0
100
111
139 $sock->shutdown(1) and # stop writing
140 $result = $self->sysread($sock);
141 }
142  
143 1 SOAP::Trace::debug($result);
144  
145 1 ▶ my $code = $@ || $!;
Condition33%1/3
$@ || $!
l!l&&r!l&&!r
100
MC/DC0%0/2
$@ || $!
$@ $!
Truth table33%1/3
A || B
A= $@B= $!
ABresult
1X1
011
000
146  
147 1 $self->code($code);
148 1 $self->message($code);
149 1 ▶ $self->is_success(!defined $code || $code eq '');
Condition33%1/3
!defined($code) || $code eq ''
l!l&&r!l&&!r
001
MC/DC0%0/2
!defined($code) || $code eq ''
!defined($code) $code eq ''
Truth table33%1/3
not(A) || B
A= !defined($code)B= $code eq ''
ABresult
1X1
011
000
150 1 $self->status($code);
151  
152 1 return $result;
153 }
154  
155 # ======================================================================
156  
157 package SOAP::Transport::TCP::Server;
158  
159 2 ▶use IO::SessionSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
160  
161 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
162 2 ▶use vars qw($AUTOLOAD @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
163 2 @ISA = qw(SOAP::Server);
164  
165 2 our $VERSION = 0.715;
166  
167 0 ▶sub DESTROY { SOAP::Trace::objects('()') }
Subroutine DESTROY: not called CC=1 SCAR=6.9
168  
169 sub new {
170 0 ▶ my $self = shift;
Subroutine new: not called CC=10 SCAR=47.0
171  
172 0 ▶ unless (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 0 0 0
173 0 ▶ my $class = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
174  
175 0 my(@params, @methods);
176 0 ▶ while (@_) { $class->can($_[0]) ? push(@methods, shift() => shift) : push(@params, shift) }
Branch: 2 branches
BranchTrueFalseTotal
if (@_) 0 0 0
$class->can($_[0]) ? : 0 0 0
177 0 $self = $class->SUPER::new(@methods);
178  
179 # use SSL if there is any parameter with SSL_* in the name
180 0 ▶ $self->SSL(1) if !$self->SSL && grep /^SSL_/, @params;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->SSL and grep /^SSL_/, @params 0 0 0
Condition0%0/3
not $self->SSL and grep /^SSL_/, @params
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->SSL and grep /^SSL_/, @params
not $self->SSL grep /^SSL_/, @params
Truth table0%0/3
not(A) and B
A= not $self->SSLB= grep /^SSL_/, @params
ABresult
0X0
100
111
181  
182 0 my $socket = $self->io_socket_class;
183 0 ▶ eval "require $socket" or Carp::croak $@ unless UNIVERSAL::can($socket => 'new');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can($socket, "new") 0 0 0
Condition0%0/6
UNIVERSAL::can($socket, 'new') || (eval "require $socket" || Carp::croak($@))
l!l&&r!l&&!r
000
eval "require $socket" or Carp::croak($@)
l!l&&r!l&&!r
000
MC/DC0%0/3
UNIVERSAL::can($socket, 'new') || (eval "require $socket" || Carp::croak($@))
UNIVERSAL::can($socket, 'new') eval "require $socket" Carp::croak($@)
Truth table0%0/4
A || B or C
A= UNIVERSAL::can($socket, 'new')B= eval "require $socket"C= Carp::croak($@)
ABCresult
1XX1
01X1
0011
0000
184 0 ▶ $self->{_socket} = $socket->new(Proto => 'tcp', @params)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_socket"} = $socket->new("Proto", "tcp", @params) or Carp::croak("Can't open socket: $!") 0 0 0
185 or Carp::croak "Can't open socket: $!";
186  
187 0 SOAP::Trace::objects('()');
188 }
189 0 return $self;
190 }
191  
192 sub SSL {
193 0 ▶ my $self = shift->new;
Subroutine SSL: not called CC=2 SCAR=17.9
194 0 ▶ @_ ? ($self->{_SSL} = shift, return $self) : return $self->{_SSL};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
195 }
196  
197 0 ▶sub io_socket_class { shift->SSL ? 'IO::Socket::SSL' : 'IO::Socket::INET' }
Subroutine io_socket_class: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
(shift())->SSL ? : 0 0 0
198  
199 sub AUTOLOAD {
200 0 ▶ my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::') + 2);
Subroutine AUTOLOAD: not called CC=2 SCAR=12.2
201 0 ▶ return if $method eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "DESTROY" 0 0 0
202  
203 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
204 0 ▶ *$AUTOLOAD = sub { shift->{_socket}->$method(@_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
205 0 goto &$AUTOLOAD;
206 }
207  
208 sub handle {
209 0 ▶ my $self = shift->new;
Subroutine handle: not called CC=4 SCAR=30.0
210 0 my $sock = $self->{_socket};
211 0 my $session_set = IO::SessionSet->new($sock);
212 0 my %data;
213 0 while (1) {
214 0 my @ready = $session_set->wait($sock->timeout);
215 0 for my $session (grep { defined } @ready) {
216 0 my $data;
217 0 ▶ if (my $rc = $session->read($data, 4096)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rc = $session->read($data, 4096)) { } 0 0 0
218 0 ▶ $data{$session} .= $data if $rc > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rc > 0 0 0 0
219 } else {
220 0 $session->write($self->SUPER::handle(delete $data{$session}));
221 0 $session->close;
222 }
223 }
224 }
225 }
226  
227 # ======================================================================
228  
229 2 1;
230  
231 __END__
« lib/SOAP/Lite.pm ↑ Summary lib/SOAP/Packager.pm »