blib/lib/Net/QMTP.pm

filter: Statementstmt 33.3% 74 / 222 Branchbran 16.6% 34 / 204 Conditioncond 5.0% 1 / 20 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 54.1% 13 / 24 Podpod 100% 12 / 12 totaltotal 27.2% 134 / 492 CC 111 SCAR 47.2
CC
111
Cov
24%
send
420.0
reconnect
156.0
_send_file
156.0
CRAP 112.7
↑ Summary
1 package Net::QMTP;
2  
3 1 require 5.001;
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Text::Netstring qw(netstring_encode netstring_decode netstring_read
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 netstring_verify);
10  
11 #
12 # Copyright (c) 2003 James Raftery <james@now.ie>. All rights reserved.
13 # This program is free software; you can redistribute it and/or
14 # modify it under the same terms as Perl itself.
15 # Please submit bug reports, patches and comments to the author.
16 # Latest information at http://romana.now.ie/#net-qmtp
17 #
18 # $Id: QMTP.pm,v 1.22 2004/11/02 14:56:18 james Exp $
19 #
20 # This module is an object interface to the Quick Mail Transfer Protocol
21 # (QMTP). QMTP is a replacement for the Simple Mail Transfer Protocol
22 # (SMTP). It offers increased speed, especially over high latency
23 # links, pipelining, 8-bit data transmission and predeclaration of
24 # line-ending encoding.
25 #
26 # See the Net::QMTP man page that was installed with this module for
27 # information on how to use the module. You require version 0.04 or
28 # later of the Text::Netstring module.
29 #
30  
31 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 $VERSION = "0.06";
33  
34 1 ▶sub new {
Subroutine new: called CC=17 SCAR=40.8
Pod documented
35 1 ▶ my $proto = shift or croak;
Branch: 1 branch
BranchTrueFalseTotal
my $proto = shift() or croak() 1 0 1
36 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
37 1 ▶ my $server = shift or croak "No server specified in constructor";
Branch: 1 branch
BranchTrueFalseTotal
my $server = shift() or croak("No server specified in constructor") 1 0 1
38 1 my %args;
39  
40 1 ▶ %args = @_ if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 0 1
41 1 my $self = {
42 SENDER => undef,
43 RECIPIENTS => [],
44 MESSAGE => undef,
45 MSGFILE => undef,
46 ENCODING => undef,
47 SOCKET => undef,
48 SERVER => undef,
49 PORT => 209,
50 DEBUG => undef,
51 TIMEOUT => undef, # use IO::Socket default
52 CONNECTTIME => undef,
53 SESSIONLIMIT => 3600, # 1 hour
54 };
55 1 ▶ if ($args{'Debug'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"Debug"}) 0 1 1
56 0 $self->{DEBUG} = 1;
57 0 warn "debugging on; Version: $VERSION; RCS " .
58 qq$Revision: 1.22 $ . "\n";
59 }
60 1 ▶ $self->{SERVER} = $server or croak "Constructor server failed";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"SERVER"} = $server or croak("Constructor server failed") 1 0 1
61 1 ▶ warn "server set to '$server'\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 1 1
62 1 bless($self, $class);
63 1 ▶ unless ($self->encoding("__GUESS__")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->encoding("__GUESS__")) 0 1 1
64 0 carp "Constructor encoding() failed";
65 0 return undef;
66 }
67 1 ▶ if ($args{'ConnectTimeout'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"ConnectTimeout"}) 0 1 1
68 0 $self->{TIMEOUT} = $args{'ConnectTimeout'};
69 0 ▶ warn "timeout ".$self->{TIMEOUT}."\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
70 }
71 1 ▶ if ($args{'Port'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"Port"}) 0 1 1
72 0 $self->{PORT} = $args{'Port'};
73 0 ▶ warn "port set to ".$self->{PORT}."\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
74 }
75 1 ▶ unless ($args{'DeferConnect'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"DeferConnect"}) 0 1 1
76 0 ▶ warn "calling reconnect()\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
77 0 ▶ $self->reconnect() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->reconnect or return undef 0 0 0
78 }
79 1 ▶ warn "constructor finished\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 1 1
80 1 return $self;
81 }
82  
83 0 ▶sub reconnect {
Subroutine reconnect: not called CC=12 SCAR=50.5
Pod documented
84 0 my $self = shift;
85 0 ▶ ref($self) or croak;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or croak() 0 0 0
86  
87 0 my $sock = $self->{SOCKET};
88  
89 # if have a socket, disconnect first
90 0 ▶ if (defined($sock)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sock) 0 0 0
91 #carp "Socket is already defined";
92 #return undef;
93 0 ▶ $self->disconnect() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->disconnect or return undef 0 0 0
94 }
95  
96 # Applying timeout() to socket seems to fail. Hmm.
97 0 ▶ warn "opening socket to " . $self->{SERVER} . "\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
98 0 ▶ if ($self->{TIMEOUT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'TIMEOUT'}) { } 0 0 0
99 0 ▶ warn "socket timeout ".$self->{TIMEOUT}."\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
100 $sock = IO::Socket::INET->new(
101 PeerAddr => $self->{SERVER},
102 PeerPort => $self->{PORT},
103 Timeout => $self->{TIMEOUT},
104 0 ▶ Proto => 'tcp') or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$sock = "IO::Socket::INET"->new("PeerAddr", $self->{"SERVER"}, "PeerPort", $self->{"PORT"}, "Timeout", $self->{"TIMEOUT"}, "Proto", "tcp") or return undef 0 0 0
105 } else {
106 0 ▶ warn "socket default timeout\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
107 $sock = IO::Socket::INET->new(
108 PeerAddr => $self->{SERVER},
109 PeerPort => $self->{PORT},
110 0 ▶ Proto => 'tcp') or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$sock = "IO::Socket::INET"->new("PeerAddr", $self->{"SERVER"}, "PeerPort", $self->{"PORT"}, "Proto", "tcp") or return undef 0 0 0
111 }
112  
113 0 binmode($sock);
114 0 $self->{SOCKET} = $sock;
115 0 $sock->autoflush();
116 0 ▶ warn "socket opened to " . $sock->peerhost() . "\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
117 0 $self->{CONNECTTIME} = time;
118 0 ▶ warn "connected at " . $self->{CONNECTTIME} . "\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
119 0 return $self->{SOCKET};
120 }
121  
122 1 ▶sub disconnect {
Subroutine disconnect: called CC=6 SCAR=27.7
Pod documented
123 1 my $self = shift;
124 1 ▶ ref($self) or croak;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or croak() 1 0 1
125  
126 1 my $sock = $self->{SOCKET};
127  
128 # can't disconnect if no socket
129 1 ▶ if (!defined($sock)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sock) 1 0 1
130 1 carp "Socket is not defined";
131 1 return undef;
132 }
133  
134 ##
135 ## Only on newer perls
136 ##
137 ### can't disconnect if not connected
138 ##if (!$sock->connected()) {
139 ## carp "Socket is not connected";
140 ## $self->{SOCKET} = undef;
141 ## return undef;
142 ##}
143  
144 0 ▶ warn "closing socket to " . $sock->peerhost() . "\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
145 0 ▶ unless (close $sock) {
Branch: 1 branch
BranchTrueFalseTotal
unless (close $sock) 0 0 0
146 0 carp "Cannot close socket: $!";
147 0 return undef;
148 }
149 0 $self->{SOCKET} = undef;
150 warn "socket closed (was open for " . (time - $self->{CONNECTTIME}) .
151 0 ▶ "s)\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
152 0 return 1;
153 }
154  
155 1 ▶sub encoding {
Subroutine encoding: called CC=12 SCAR=38.2
Pod documented
156 1 my $self = shift;
157 1 ▶ ref($self) or croak;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or croak() 1 0 1
158 1 ▶ my $e = shift or return $self->{ENCODING};
Branch: 1 branch
BranchTrueFalseTotal
my $e = shift() or return $self->{"ENCODING"} 1 0 1
159  
160 # guess from input record seperator
161 1 ▶ if ($e eq "__GUESS__") {
Branch: 3 branches
BranchTrueFalseTotal
if ($e eq '__GUESS__') { } 1 0 1
elsif ($e eq 'dos') { } 0 0 0
elsif ($e eq 'unix') { } 0 0 0
162 1 ▶ warn "guessing encoding\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 1 1
163 1 ▶ if ($/ eq "\015\012") { # CRLF: Dos/Win
Branch: 1 branch
BranchTrueFalseTotal
if ($/ eq "\r\n") { } 0 1 1
164 0 $self->{ENCODING} = "\015";
165 0 ▶ warn "guessed carraige-return encoding\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
166 } else { # LF: Unix-like
167 1 $self->{ENCODING} = "\012";
168 1 ▶ warn "guessed line-feed encoding\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 1 1
169 }
170  
171 # specific encoding requested
172 } elsif ($e eq "dos") {
173 0 $self->{ENCODING} = "\015";
174 0 ▶ warn "set carraige-return encoding\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
175 } elsif ($e eq "unix") {
176 0 $self->{ENCODING} = "\012";
177 0 ▶ warn "set line-feed encoding\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
178 } else {
179 0 croak "Unknown encoding: '$e'";
180 0 $self->{ENCODING} = undef;
181 }
182  
183 1 return $self->{ENCODING};
184 }
185  
186 1 ▶sub server {
Subroutine server: called CC=4 SCAR=14.6
Pod documented
187 1 my $self = shift;
188 1 ▶ ref($self) or croak;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or croak() 1 0 1
189 1 ▶ $self->{SERVER} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
190 1 ▶ warn "server is " . $self->{SERVER} . "\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 1 1
191 1 return $self->{SERVER};
192 }
193  
194 3 ▶sub sender {
Subroutine sender: called CC=4 SCAR=14.1
Pod documented
195 3 my $self = shift;
196 3 ▶ ref($self) or croak;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or croak() 3 0 3
197 3 ▶ $self->{SENDER} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 2 3
198 3 ▶ warn "sender is " . $self->{SENDER} . "\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 3 3
199 3 return $self->{SENDER};
200 }
201  
202 4 ▶sub recipient {
Subroutine recipient: called CC=4 SCAR=14.3
Pod documented
203 4 my $self = shift;
204 4 ▶ ref($self) or croak;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or croak() 4 0 4
205 4 ▶ push(@{$self->{RECIPIENTS}}, shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 2 4
206 0 warn "recipients are ". join(",", @{$self->{RECIPIENTS}}) .
207 4 ▶ "\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 4 4
208 4 return $self->{RECIPIENTS};
209 }
210  
211 0 ▶sub message {
Subroutine message: not called CC=6 SCAR=37.4
Pod documented
212 0 my $self = shift;
213 0 ▶ ref($self) or croak;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or croak() 0 0 0
214 0 ▶ warn "message() started\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
215 0 ▶ if ($self->{MSGFILE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"MSGFILE"}) 0 0 0
216 0 carp "Message already created by message_from_file()";
217 0 return undef;
218 }
219 0 ▶ $self->{MESSAGE} .= shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
220 warn "message text appended (is now " . length($self->{MESSAGE}) .
221 0 ▶ " bytes)\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
222 0 return $self->{MESSAGE};
223 }
224  
225 0 ▶sub message_from_file {
Subroutine message_from_file: not called CC=6 SCAR=37.4
Pod documented
226 0 my $self = shift;
227 0 ▶ ref($self) or croak;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or croak() 0 0 0
228 0 ▶ warn "message_from_file() started\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
229 0 ▶ if (defined($self->{MESSAGE})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"MESSAGE"}) 0 0 0
230 0 carp "Message already created by message()";
231 0 return undef;
232 }
233 0 ▶ my $f = shift or return $self->{MSGFILE};
Branch: 1 branch
BranchTrueFalseTotal
my $f = shift() or return $self->{"MSGFILE"} 0 0 0
234 #
235 # This is permitted in case the file needs to be created/modified
236 # by some subsequent process
237 ## -f $f or return undef;
238 #
239 0 ▶ warn "message_from_file file is '$f'\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
240 0 $self->{MSGFILE} = $f;
241 0 return $self->{MSGFILE};
242 }
243  
244 0 ▶sub new_message {
Subroutine new_message: not called CC=3 SCAR=24.8
Pod documented
245 0 my $self = shift;
246 0 ▶ ref($self) or croak;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or croak() 0 0 0
247  
248 0 $self->{MESSAGE} = undef;
249 0 $self->{MSGFILE} = undef;
250 0 ▶ warn "message reset\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
251 0 return 1;
252 }
253  
254 1 ▶sub new_envelope {
Subroutine new_envelope: called CC=3 SCAR=11.2
Pod documented
255 1 my $self = shift;
256 1 ▶ ref($self) or croak;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or croak() 1 0 1
257  
258 1 $self->{SENDER} = undef;
259 1 $self->{RECIPIENTS} = [];
260 1 ▶ warn "envelope reset\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 1 1
261 1 return 1;
262 }
263  
264 0 ▶sub _send_file {
Subroutine _send_file: not called CC=12 SCAR=50.5
265 0 my $self = shift;
266 0 ▶ ref($self) or die;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or die 0 0 0
267 0 my $f = $self->{MSGFILE};
268 0 my $sock = $self->{SOCKET};
269  
270 0 ▶ warn "_send_file starting\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
271 0 ▶ unless (open(FILE, $f)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open FILE, $f) 0 0 0
272 0 carp "Cannot open file '$f': $!";
273 0 return undef;
274 }
275 0 my $size = (stat(FILE))[7];
276 0 binmode(FILE);
277 #carp "File '$f' is empty" if $size == 0;
278 0 ▶ if ($size < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size < 0) 0 0 0
279 0 carp "File '$f' has negative size";
280 0 return undef;
281 }
282  
283 0 my $len;
284 0 ▶ print $sock ($size+1) . ":" . $self->{ENCODING} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
print $sock ($size + 1) . ':' . $self->{"ENCODING"} or return undef 0 0 0
285 0 ▶ while (<FILE>) { print $sock $_ or return undef; $len += length($_) };
Branch: 2 branches
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 0 0 0
print $sock $_ or return undef 0 0 0
286  
287 0 ▶ if ($size != $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size != $len) 0 0 0
288 0 warn "File '$f' should be $size but we read $len\n";
289 0 return undef;
290 }
291 0 ▶ print $sock "," or return undef;
Branch: 1 branch
BranchTrueFalseTotal
print $sock "," or return undef 0 0 0
292 0 ▶ unless (close FILE) {
Branch: 1 branch
BranchTrueFalseTotal
unless (close FILE) 0 0 0
293 0 carp "Cannot close file '$f': $!";
294 0 return undef;
295 }
296 0 ▶ warn "_send_file finished\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
297 0 return 1;
298 }
299  
300 0 ▶sub send {
Subroutine send: not called CC=20 SCAR=60.4
Pod documented
301 0 my $self = shift;
302 0 ▶ ref($self) or croak;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or croak() 0 0 0
303  
304 0 ▶ warn "send() running sanity checks\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
305 0 ▶ $self->_ready_to_send() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_ready_to_send or return undef 0 0 0
306 ##$self->_session_notexpired() or return undef;
307 0 my $sock = $self->{SOCKET};
308  
309 0 ▶ if ($self->{MSGFILE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'MSGFILE'}) { } 0 0 0
310 warn "calling _send_file for " . $self->{MSGFILE} .
311 0 ▶ "\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
312 0 ▶ $self->_send_file() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_send_file or return undef 0 0 0
313 } else {
314 0 ▶ warn "sending message data\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
315 print $sock netstring_encode($self->{ENCODING} .
316 0 ▶ $self->{MESSAGE}) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
print $sock netstring_encode($self->{"ENCODING"} . $self->{"MESSAGE"}) or return undef 0 0 0
317 }
318  
319 0 my($s, %r);
320  
321 0 $s = netstring_encode($self->{SENDER});
322 0 ▶ warn "sending envelope sender $s\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
323 0 ▶ print $sock $s or return undef;
Branch: 1 branch
BranchTrueFalseTotal
print $sock $s or return undef 0 0 0
324  
325 0 $s = netstring_encode(scalar netstring_encode($self->{RECIPIENTS}));
326 0 ▶ warn "sending envelope recipient(s) $s\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
327 0 ▶ print $sock $s or return undef;
Branch: 1 branch
BranchTrueFalseTotal
print $sock $s or return undef 0 0 0
328
329 0 $s = undef;
330 0 foreach (@{$self->{RECIPIENTS}}) {
331 0 ▶ warn "read response\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
332 0 $s = $self->_read_netstring();
333 0 ▶ warn "parse response: $s\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
334 CASE: {
335 0 ▶ $s =~ s/^K/success: / and last CASE;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ s/^K/success: / and last CASE 0 0 0
336 0 ▶ $s =~ s/^Z/deferral: / and last CASE;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ s/^Z/deferral: / and last CASE 0 0 0
337 0 ▶ $s =~ s/^D/failure: / and last CASE;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ s/^D/failure: / and last CASE 0 0 0
338 0 _badproto();
339 }
340 0 $r{$_} = $s;
341 }
342  
343 0 ▶ warn "finished send()\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
344 0 return \%r;
345 }
346  
347 0 ▶sub _ready_to_send {
Subroutine _ready_to_send: not called CC=8 SCAR=42.8
348 0 my $self = shift;
349 0 ▶ ref($self) or die;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or die 0 0 0
350  
351 0 ▶ warn "_ready_to_send() starting\n" if $self->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
352 # need defined sender (don't need true; empty string valid),
353 # recipient(s), defined message, socket and an encoding
354 0 ▶ return (defined($self->{SENDER}) and scalar(@{$self->{RECIPIENTS}}) and
Condition0%0/3
defined $self->{"MESSAGE"} or $self->{"MSGFILE"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $self->{"MESSAGE"} or $self->{"MSGFILE"}
defined $self->{"MESSAGE"} $self->{"MSGFILE"}
Truth table0%0/3
A or B
A= defined $self->{"MESSAGE"}B= $self->{"MSGFILE"}
ABresult
1X1
011
000
355 (defined($self->{MESSAGE}) or $self->{MSGFILE}) and
356 0 ▶ $self->{SOCKET} and $self->{ENCODING});
Condition0%0/11
defined $self->{'SENDER'} && scalar @{$self->{'RECIPIENTS'};} && (defined $self->{'MESSAGE'} || $self->{'MSGFILE'}) && $self->{'SOCKET'} && $self->{'ENCODING'}
!ll&&!rl&&r
000
defined $self->{"SENDER"} and scalar @{$self->{"RECIPIENTS"};} and defined $self->{"MESSAGE"} || $self->{"MSGFILE"} and $self->{"SOCKET"}
!ll&&!rl&&r
000
defined $self->{"SENDER"} and scalar @{$self->{"RECIPIENTS"};} and defined $self->{"MESSAGE"} || $self->{"MSGFILE"}
!ll&&!rl&&r
000
defined $self->{"SENDER"} and scalar @{$self->{"RECIPIENTS"};}
!ll
00
MC/DC0%0/4
defined $self->{'SENDER'} && scalar @{$self->{'RECIPIENTS'};} && (defined $self->{'MESSAGE'} || $self->{'MSGFILE'}) && $self->{'SOCKET'} && $self->{'ENCODING'}
defined $self->{"SENDER"} defined $self->{"MESSAGE"} || $self->{"MSGFILE"} $self->{"SOCKET"} $self->{'ENCODING'}
Truth table0%0/5
A and B and C && D
A= defined $self->{"SENDER"}B= defined $self->{"MESSAGE"} || $self->{"MSGFILE"}C= $self->{"SOCKET"}D= $self->{'ENCODING'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
357 }
358  
359 0 ▶sub _session_notexpired {
Subroutine _session_notexpired: not called CC=3 SCAR=24.8
360 0 my $self = shift;
361 0 ▶ ref($self) or die;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or die 0 0 0
362  
363 0 ▶ if (time - $self->{CONNECTTIME} > $self->{SESSIONLIMIT}) {
Branch: 1 branch
BranchTrueFalseTotal
if (time - $self->{"CONNECTTIME"} > $self->{"SESSIONLIMIT"}) 0 0 0
364 0 carp "Session has expired";
365 0 $self->disconnect(); # what about failure?
366 0 return undef;
367 }
368 0 return 1;
369 }
370  
371 0 ▶sub _read_netstring {
Subroutine _read_netstring: not called CC=4 SCAR=30.0
372 0 my $self = shift;
373 0 ▶ ref($self) or die;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or die 0 0 0
374 0 my $sock = $self->{SOCKET};
375  
376 0 my $s = netstring_read($sock);
377  
378 0 ▶ if (defined $s and netstring_verify($s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and netstring_verify($s)) 0 0 0
Condition0%0/3
defined $s and netstring_verify($s)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $s and netstring_verify($s)
defined $s netstring_verify($s)
Truth table0%0/3
A and B
A= defined $sB= netstring_verify($s)
ABresult
0X0
100
111
379 0 return netstring_decode($s);
380 }
381 0 return "";
382 }
383  
384 0 ▶sub _badproto {
Subroutine _badproto: not called CC=1 SCAR=6.9
385 0 confess "Protocol violation\n";
386 }
387  
388 0 ▶sub _badresources {
Subroutine _badresources: not called CC=1 SCAR=6.9
389 0 confess "Excessive resources requested\n";
390 }
391  
392 1 ▶sub DESTROY {
Subroutine DESTROY: called CC=3 SCAR=11.7
393 1 my $self = shift;
394 1 ▶ ref($self) or die;
Branch: 1 branch
BranchTrueFalseTotal
ref $self or die 1 0 1
395 1 ▶ $self->disconnect() if $self->{SOCKET}; # don't care about failure
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"SOCKET"} 0 1 1
396 }
397  
398 1 1;
399  
400 __END__
↑ Summary