blib/lib/Net/Gen.pm

filter: Statementstmt 79.2% 680 / 858 Branchbran 44.2% 194 / 438 Conditioncond 38.2% 107 / 280 MC/DCmcdc 10.8% 17 / 157 Subroutinesub 91.7% 89 / 97 Podpod 92.1% 35 / 38 totaltotal 60.0% 1122 / 1868 CC 319 SCAR 36.4
CC
319
Cov
62%
_valconnect
240.0
_tryconnect
121.4
recv
94.4
CRAP 37.9
« blib/lib/Net/TCP.pm ↑ Summary blib/lib/Net/UNIX.pm »
1 # Copyright 1995,2002 Spider Boardman.
2 # All rights reserved.
3 #
4 # Automatic licensing for this software is available. This software
5 # can be copied and used under the terms of the GNU Public License,
6 # version 1 or (at your option) any later version, or under the
7 # terms of the Artistic license. Both of these can be found with
8 # the Perl distribution, which this software is intended to augment.
9 #
10 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13  
14 # rcsid: "@(#) $Id: Gen.dat,v 1.44 2002/04/10 11:27:18 spider Exp $"
15  
16  
17 package Net::Gen;
18 2 ▶use 5.004_04; # new minimum Perl version for this package
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 #use Carp; # no! just require Carp when we want to croak.
22 2 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 %_missing $AUTOLOAD $adebug);
24  
25 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 $VERSION = '1.011';
27 2 eval "sub Version () { __PACKAGE__ . ' v$VERSION' }";
28 }
29  
30 #use Socket qw(!/pack_sockaddr/ !/^MSG_OOB$/ !SOMAXCONN);
31 2 ▶use Socket ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use AutoLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use DynaLoader ();
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use Symbol qw(gensym);
Subroutine BEGIN: called CC=1 SCAR=0.0
36 2 ▶use SelectSaver ();
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 ▶use IO::Handle ();
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 # Special wart for new_from_f{d,h}, since only the _fh flavour's already
40 # known to AutoLoader.
41 3 sub new_from_fd; *new_from_fd = \&new_from_fh;
42  
43 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
44 2 @ISA = qw(IO::Handle Exporter DynaLoader);
45  
46 2 @EXPORT = ();
47  
48 2 @EXPORT_OK = qw(pack_sockaddr
49 unpack_sockaddr
50 VAL_O_NONBLOCK
51 VAL_EAGAIN
52 RD_NODATA
53 EOF_NONBLOCK
54 EINPROGRESS EALREADY ENOTSOCK EDESTADDRREQ
55 EMSGSIZE EPROTOTYPE ENOPROTOOPT EPROTONOSUPPORT
56 ESOCKTNOSUPPORT EOPNOTSUPP EPFNOSUPPORT EAFNOSUPPORT
57 EADDRINUSE EADDRNOTAVAIL ENETDOWN ENETUNREACH ENETRESET
58 ECONNABORTED ECONNRESET ENOBUFS EISCONN ENOTCONN
59 ESHUTDOWN ETOOMANYREFS ETIMEDOUT
60 ECONNREFUSED EHOSTDOWN EHOSTUNREACH
61 ENOSR ETIME EBADMSG EPROTO ENODATA ENOSTR
62 EAGAIN EWOULDBLOCK
63 ENOENT EINVAL EBADF
64 SHUT_RD SHUT_WR SHUT_RDWR
65 SOL_SOCKET
66 SOMAXCONN
67 SO_ACCEPTCONN SO_BROADCAST SO_DEBUG SO_DONTROUTE
68 SO_ERROR SO_EXPANDED_RIGHTS SO_FAMILY SO_KEEPALIVE
69 SO_LINGER SO_OOBINLINE SO_PAIRABLE SO_RCVBUF
70 SO_RCVLOWAT SO_RCVTIMEO SO_REUSEADDR SO_REUSEPORT
71 SO_SNDBUF SO_SNDLOWAT SO_SNDTIMEO SO_STATE SO_TYPE
72 SO_USELOOPBACK SO_XSE
73 SOCK_STREAM SOCK_DGRAM SOCK_RAW SOCK_RDM SOCK_SEQPACKET
74 AF_UNSPEC AF_UNIX AF_INET AF_IMPLINK AF_PUP AF_CHAOS
75 AF_NS AF_ISO AF_OSI AF_ECMA AF_DATAKIT AF_CCITT AF_SNA
76 AF_DECnet AF_DLI AF_LAT AF_HYLINK AF_APPLETALK AF_ROUTE
77 AF_LINK AF_NETMAN AF_X25 AF_CTF AF_WAN AF_USER AF_LAST
78 PF_UNSPEC PF_UNIX PF_INET PF_IMPLINK PF_PUP PF_CHAOS
79 PF_NS PF_ISO PF_OSI PF_ECMA PF_DATAKIT PF_CCITT PF_SNA
80 PF_DECnet PF_DLI PF_LAT PF_HYLINK PF_APPLETALK PF_ROUTE
81 PF_LINK PF_NETMAN PF_X25 PF_CTF PF_WAN PF_USER PF_LAST
82 AF_LOCAL PF_LOCAL
83 );
84  
85 2 %EXPORT_TAGS = (
86 NonBlockVals => [qw(EOF_NONBLOCK RD_NODATA VAL_EAGAIN VAL_O_NONBLOCK)],
87 routines => [qw(pack_sockaddr unpack_sockaddr)],
88 errnos => [qw(EINPROGRESS EALREADY ENOTSOCK EDESTADDRREQ
89 EMSGSIZE EPROTOTYPE ENOPROTOOPT EPROTONOSUPPORT
90 ESOCKTNOSUPPORT EOPNOTSUPP EPFNOSUPPORT EAFNOSUPPORT
91 EADDRINUSE EADDRNOTAVAIL ENETDOWN ENETUNREACH ENETRESET
92 ECONNABORTED ECONNRESET ENOBUFS EISCONN ENOTCONN
93 ESHUTDOWN ETOOMANYREFS ETIMEDOUT
94 ECONNREFUSED EHOSTDOWN EHOSTUNREACH
95 ENOSR ETIME EBADMSG EPROTO ENODATA ENOSTR
96 EAGAIN EWOULDBLOCK
97 ENOENT EINVAL EBADF
98 )],
99 shutflags => [qw(SHUT_RD SHUT_WR SHUT_RDWR)],
100 sockopts => [qw(SO_ACCEPTCONN SO_BROADCAST SO_DEBUG SO_DONTROUTE
101 SO_ERROR SO_EXPANDED_RIGHTS SO_FAMILY SO_KEEPALIVE
102 SO_LINGER SO_OOBINLINE SO_PAIRABLE SO_RCVBUF
103 SO_RCVLOWAT SO_RCVTIMEO SO_REUSEADDR SO_REUSEPORT
104 SO_SNDBUF SO_SNDLOWAT SO_SNDTIMEO SO_STATE SO_TYPE
105 SO_USELOOPBACK SO_XSE
106 )],
107 sockvals => [qw(SOL_SOCKET
108 SOCK_STREAM SOCK_DGRAM SOCK_RAW SOCK_RDM SOCK_SEQPACKET
109 )],
110 af => [qw(AF_UNSPEC AF_UNIX AF_INET AF_IMPLINK AF_PUP AF_CHAOS
111 AF_NS AF_ISO AF_OSI AF_ECMA AF_DATAKIT AF_CCITT AF_SNA
112 AF_DECnet AF_DLI AF_LAT AF_HYLINK AF_APPLETALK AF_ROUTE
113 AF_LINK AF_NETMAN AF_X25 AF_CTF AF_WAN AF_USER AF_LAST
114 AF_LOCAL
115 )],
116 pf => [qw(PF_UNSPEC PF_UNIX PF_INET PF_IMPLINK PF_PUP PF_CHAOS
117 PF_NS PF_ISO PF_OSI PF_ECMA PF_DATAKIT PF_CCITT PF_SNA
118 PF_DECnet PF_DLI PF_LAT PF_HYLINK PF_APPLETALK PF_ROUTE
119 PF_LINK PF_NETMAN PF_X25 PF_CTF PF_WAN PF_USER PF_LAST
120 PF_LOCAL
121 )],
122 ALL => [@EXPORT, @EXPORT_OK],
123 );
124 2 $EXPORT_TAGS{'non_block_vals'} = $EXPORT_TAGS{'NonBlockVals'};
125 2 $EXPORT_TAGS{'families'} = [@{$EXPORT_TAGS{'af'}}, @{$EXPORT_TAGS{'pf'}}];
126 }
127  
128 3 my %loaded;
129  
130  
131 # dummies for the Carp:: routines, which we'll re-invoke if we get called.
132  
133 sub croak
134 0 ▶{
Subroutine croak: not called CC=1 SCAR=6.9
Pod undocumented
135 0 require Carp;
136 0 goto &Carp::croak;
137 }
138  
139 sub carp
140 2 ▶{
Subroutine carp: called CC=1 SCAR=0.0
Pod undocumented
141 2 require Carp;
142 2 goto &Carp::carp;
143 }
144  
145  
146 3 ▶my $nullsub = sub {}; # handy null warning handler
Subroutine __ANON__: not called CC=1 SCAR=0.0
147 # If the warning handler is this exact code ref, don't bother calling
148 # croak in the AUTOLOAD constant section, since we're being called from
149 # inside the eval in initsockopts().
150  
151 sub AUTOLOAD
152 8 ▶{
Subroutine AUTOLOAD: called CC=11 SCAR=33.3
153 2 ▶ use attrs qw(locked);
Subroutine BEGIN: called CC=1 SCAR=0.0
154 # This AUTOLOAD is used to validate possible missing constants from
155 # the XS code, or to auto-create get/setattr subs.
156 # The defined constants are already available as XSUBs, and the same
157 # XS code which handles that also sets up the %_missing hash to note
158 # which names were known but are undefined.
159 # If the name is in %_missing, we'll croak as a normal AUTOLOAD with
160 # a constant() XS function (except for when $nullsub is the die handler).
161 # If the name isn't known to %_missing, but it is known
162 # as a key for setparams/getparams, it will be simulated via _accessor().
163 # Otherwise, control will be passed to the AUTOLOAD in AutoLoader.
164  
165 # use attrs 'locked'; # modifies the symbol table and abuses a global
166  
167 8 my ($constname,$callpkg);
168 { # block to preserve $1,$2,et al.
169 8 ($callpkg,$constname) = $AUTOLOAD =~ /^(.*)::(.*)$/;
170 }
171 8 ▶ if (exists $_missing{$AUTOLOAD}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Net::Gen::_missing{$Net::Gen::AUTOLOAD}) 0 8 8
172 0 my $wh = $SIG{__WARN__};
173 0 ▶ die "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $wh and ref $wh eq "CODE" and $wh == $nullsub 0 0 0
Condition0%0/6
$wh and ref $wh eq "CODE" and $wh == $nullsub
!ll&&!rl&&r
000
$wh and ref $wh eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/3
$wh and ref $wh eq "CODE" and $wh == $nullsub
$wh ref $wh eq "CODE" $wh == $nullsub
Truth table0%0/4
A and B and C
A= $whB= ref $wh eq "CODE"C= $wh == $nullsub
ABCresult
0XX0
10X0
1100
1111
174 if ($wh and (ref($wh) eq 'CODE') and $wh == $nullsub);
175 0 croak "Your vendor has not defined $callpkg macro $constname, used";
176 }
177 8 ▶ if (@_ && ref $_[0] && @_ < 3 && exists $ {*{$_[0]}}{Keys}{$constname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and ref $_[0] and @_ < 3 and exists do { *{$_[0];} }->{"Keys"}{$constname}) 0 8 8
Condition55%5/9
@_ and ref $_[0] and @_ < 3 and exists do { *{$_[0];} }->{"Keys"}{$constname}
!ll&&!rl&&r
350
@_ and ref $_[0] and @_ < 3
!ll&&!rl&&r
035
@_ and ref $_[0]
!ll&&!rl&&r
008
MC/DC0%0/4
@_ and ref $_[0] and @_ < 3 and exists do { *{$_[0];} }->{"Keys"}{$constname}
@_ ref $_[0] @_ < 3 exists do { *{$_[0];} }->{"Keys"}{$constname}
Truth table40%2/5
A and B and C and D
A= @_B= ref $_[0]C= @_ < 3D= exists do { *{$_[0];} }->{"Keys"}{$constname}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
178 2 ▶ no strict 'refs'; # allow us to define the sub
Subroutine BEGIN: called CC=1 SCAR=0.0
179 0 my $what = $constname; # don't tie up $constname for closures
180 0 ▶ warn "Auto-generating accessor $AUTOLOAD\n" if $adebug;
Branch: 1 branch
BranchTrueFalseTotal
if $Net::Gen::adebug 0 0 0
181 0 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
182 0 splice @_, 1, 0, $what;
183 0 goto &_accessor;
184 0 };
185 0 goto &$AUTOLOAD;
186 }
187 8 ▶ warn "Autoloading $AUTOLOAD\n" if $adebug;
Branch: 1 branch
BranchTrueFalseTotal
if $Net::Gen::adebug 0 8 8
188 8 $AutoLoader::AUTOLOAD = $AUTOLOAD;
189 8 goto &AutoLoader::AUTOLOAD;
190 }
191  
192 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
193 # do this now so the constant XSUBs really are
194 2 __PACKAGE__->DynaLoader::bootstrap($VERSION);
195 }
196  
197  
198 # Preloaded methods go here. Autoload methods go after __END__, and are
199 # processed by the autosplit program.
200  
201  
202 # This package has the core 'generic' routines for fiddling with
203 # sockets.
204  
205  
206 # initsockopts - Set up the socket options of a class using this module.
207 # The structure of a sockopt hash is like this:
208 # %sockopts = ( OPTION => ['pack_string', $option_number, $option_level,
209 # $number_of_elements], ... );
210 # The option level and number are for calling [gs]etsockopt, and
211 # the number of elements is for some (weak) consistency checking.
212 # The pack/unpack template is used by $obj->getsopt and setsopt.
213 # Only the pack template is set on input to this routine. On exit,
214 # it will have deleted any entries which cannot be resolved, and will
215 # have filled in the ones which can. It will also have duplicated
216 # the entries to be indexed by option value as well as by option name.
217  
218 3 my %evalopts; # avoid compiling an eval per sockopt
219  
220 #& initsockopts($class, $level+0, \%sockopts) : void
221 sub initsockopts
222 4 ▶{
Subroutine initsockopts: called CC=10 SCAR=23.9
Pod documented
223 2 ▶ use attrs qw(locked);
Subroutine BEGIN: called CC=1 SCAR=0.0
224 4 my ($class,$level,$opts) = @_;
225 4 ▶ croak "Invalid arguments to " . __PACKAGE__ . "::initsockopts, called"
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 3 or ref $opts ne "HASH" 0 4 4
Condition33%1/3
@_ != 3 or ref $opts ne "HASH"
l!l&&r!l&&!r
004
MC/DC0%0/2
@_ != 3 or ref $opts ne "HASH"
@_ != 3 ref $opts ne "HASH"
Truth table33%1/3
A or B
A= @_ != 3B= ref $opts ne "HASH"
ABresult
1X1
011
000
226 if @_ != 3 or ref $opts ne 'HASH';
227 4 $level += 0; # force numeric
228 4 my($opt,$oval,@oval,$esub);
229 4 my $nullwarn = $nullsub; # a handy __WARN__ handler
230 # The above has to be there, since the file-scope 'my' won't be seen
231 # in the generated closure.
232 4 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 4 4
233 2 ▶ $evalopts{$class} ||= eval "package $class; no strict 'refs';" .
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Condition33%1/3
$evalopts{$class} ||= eval "package $class; no strict 'refs';" . 'sub ($) {local($SIG{__WARN__})=$nullwarn;local($SIG{__DIE__});' . "&{\$_[0]}()}"
l!l&&r!l&&!r
040
MC/DC0%0/2
$evalopts{$class} ||= eval "package $class; no strict 'refs';" . 'sub ($) {local($SIG{__WARN__})=$nullwarn;local($SIG{__DIE__});' . "&{\$_[0]}()}"
$evalopts{$class} eval "package $class; no strict 'refs';" . 'sub ($) {local($SIG{__WARN__})=$nullwarn;local($SIG{__DIE__});' . "&{\$_[0]}()}"
Truth table33%1/3
A ||= B
A= $evalopts{$class}B= eval "package $class; no strict 'refs';" . 'sub ($) {local($SIG{__WARN__})=$nullwarn;local($SIG{__DIE__});' . "&{\$_[0]}()}"
ABresult
1X1
011
000
234 'sub ($) {local($SIG{__WARN__})=$nullwarn;local($SIG{__DIE__});' .
235 '&{$_[0]}()}';
236 4 $esub = $evalopts{$class};
237 4 foreach $opt (keys %$opts) {
238 62 ▶ delete $$opts{$opt}, next if exists $_missing{"${class}::$opt"};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Net::Gen::_missing{"${class}::$opt"} 14 48 62
239 48 $oval = eval {&$esub($opt)};
240 48 ▶ delete $$opts{$opt}, next if $@ or !defined($oval) or $oval eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $@ or not defined $oval or $oval eq "" 0 48 48
Condition33%2/6
$@ or not defined $oval or $oval eq ""
l!l&&r!l&&!r
0048
$@ or not defined $oval
l!l&&r!l&&!r
0048
MC/DC0%0/3
$@ or not defined $oval or $oval eq ""
$@ not defined $oval $oval eq ""
Truth table25%1/4
A or not(B) or C
A= $@B= not defined $ovalC= $oval eq ""
ABCresult
1XX1
01X1
0011
0000
241 48 $oval += 0; # force numeric
242 48 push(@{$$opts{$opt}}, $oval, $level);
243 48 $$opts{$oval} = $$opts{$opt};
244 48 $oval = $$opts{$opt}[0];
245 48 @oval = unpack($oval, pack($oval, 0));
246 48 $$opts{$opt}[3] = scalar @oval;
247 }
248 }
249  
250  
251 my %sockopts;
252  
253 # The known socket options (from Socket.pm)
254  
255 1 %sockopts = (
256 # First, the simple flag options
257  
258 'SO_ACCEPTCONN' => [ 'I' ],
259 'SO_BROADCAST' => [ 'I' ],
260 'SO_DEBUG' => [ 'I' ],
261 'SO_DONTROUTE' => [ 'I' ],
262 'SO_ERROR' => [ 'I' ],
263 'SO_EXPANDED_RIGHTS' => [ 'I' ],
264 'SO_KEEPALIVE' => [ 'I' ],
265 'SO_OOBINLINE' => [ 'I' ],
266 'SO_PAIRABLE' => [ 'I' ],
267 'SO_REUSEADDR' => [ 'I' ],
268 'SO_REUSEPORT' => [ 'I' ],
269 'SO_USELOOPBACK' => [ 'I' ],
270 'SO_XSE' => [ 'I' ],
271  
272 # Simple integer options
273  
274 'SO_RCVBUF' => [ 'I' ],
275 'SO_SNDBUF' => [ 'I' ],
276 'SO_RCVTIMEO' => [ 'I' ],
277 'SO_SNDTIMEO' => [ 'I' ],
278 'SO_RCVLOWAT' => [ 'I' ],
279 'SO_SNDLOWAT' => [ 'I' ],
280 'SO_TYPE' => [ 'I' ],
281 'SO_STATE' => [ 'I' ],
282 'SO_FAMILY' => [ 'I' ],
283  
284 # Finally, one which is a struct
285  
286 'SO_LINGER' => [ 'II' ],
287  
288 # Out of known socket options
289 );
290  
291 3 __PACKAGE__->initsockopts( SOL_SOCKET(), \%sockopts );
292  
293  
294 #& _genfh() : returns orphan globref with HV slot.
295 sub _genfh ()
296 6 ▶{
Subroutine _genfh: called CC=1 SCAR=0.0
297 6 my $rval = gensym;
298 6 *{$rval} = {}; # initialise a hash slot
299 6 $rval;
300 }
301  
302 3 my $debug = 0; # module-wide debug hack -- don't use
303  
304 # On the other hand, per-object debugging isn't so bad....
305  
306 # can update $debug file variable
307 #& _debug($this [, $newval]) : oldval
308 sub _debug
309 0 ▶{
Subroutine _debug: not called CC=3 SCAR=19.2
310 2 ▶ use attrs qw(locked);
Subroutine BEGIN: called CC=1 SCAR=0.0
311 0 my ($this,$newval) = @_;
312 0 ▶ return $this->debug($newval) if ref $this;
Branch: 1 branch
BranchTrueFalseTotal
if ref $this 0 0 0
313 # class method here
314 0 my $oldval = $debug;
315 0 ▶ $debug = 0+$newval if defined $newval;
Branch: 1 branch
BranchTrueFalseTotal
if defined $newval 0 0 0
316 0 $oldval;
317 }
318  
319 #& debug($self [, $newval]) : oldval
320 sub debug
321 273 ▶{
Subroutine debug: called CC=3 SCAR=11.1
Pod undocumented
322 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
323 273 my ($self,$newval) = @_;
324 273 ▶ my $oldval = $ {*$self}{Parms}{'debug'} if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 273 0 273
325 273 ▶ $self->setparams({'debug'=>$newval}) if defined $newval;
Branch: 1 branch
BranchTrueFalseTotal
if defined $newval 0 273 273
326 273 $oldval;
327 }
328  
329 #& _trace($this, \@args, minlevel, [$moretext]) : void
330 sub _trace
331 149 ▶{
Subroutine _trace: called CC=5 SCAR=18.9
332 149 my ($this,$aref,$level,$msg) = @_;
333 149 my $rtn = (caller(1))[3];
334 # local $^W=0; # keep the arglist interpolation from carping
335 149 ▶ $msg = '' unless defined $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $msg 130 19 149
336 0 ▶ print STDERR "${rtn}(@{$aref||[]})${msg}\n"
Branch: 1 branch
BranchTrueFalseTotal
if $level and $this->_debug >= $level 0 149 149
Condition20%1/5
$level and $this->_debug >= $level
!ll&&!rl&&r
01490
$aref || []
l!l
00
MC/DC0%0/2
$level and $this->_debug >= $level
$level $this->_debug >= $level
MC/DC0%0/1
$aref || []
$aref
Truth table33%1/3
A and B
A= $levelB= $this->_debug >= $level
ABresult
0X0
100
111
Truth table0%0/2
A
A= $aref
Aresult
11
00
337 if $level and $this->_debug >= $level;
338 149 ${rtn};
339 }
340  
341 #& _setdebug($self, $name, $newval) : {'' | "carp string"}
342 sub _setdebug
343 7 ▶{
Subroutine _setdebug: called CC=4 SCAR=15.2
344 7 my ($self,$what,$val) = @_;
345 7 ▶ return '' unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 7 7
346 7 ▶ return "$self->{$what} parameter ($val) must be non-negative integer"
Branch: 1 branch
BranchTrueFalseTotal
if $val eq "" or $val =~ /\D/ 0 7 7
Condition33%1/3
$val eq "" or $val =~ /\D/
l!l&&r!l&&!r
007
MC/DC0%0/2
$val eq "" or $val =~ /\D/
$val eq "" $val =~ /\D/
Truth table33%1/3
A or B
A= $val eq ""B= $val =~ /\D/
ABresult
1X1
011
000
347 if $val eq '' or $val =~ /\D/;
348 7 $_[2] += 0; # force numeric
349 7 ''; # return goodness
350 }
351  
352 # try to work even in places where Fcntl.xs doesn't.
353  
354 2 ▶my ($F_GETFL,$F_SETFL) =
Subroutine BEGIN: called CC=1 SCAR=0.0
355 eval 'use Fcntl qw(F_GETFL F_SETFL);(F_GETFL,F_SETFL)';
356 3 my $nonblock_flag = eval 'pack("I",VAL_O_NONBLOCK)';
357 3 my $eagain = eval 'VAL_EAGAIN';
358  
359 #& _accessor($self, $what [, $newval]) : oldvalue
360 sub _accessor
361 0 ▶{
Subroutine _accessor: not called CC=4 SCAR=24.6
362 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
363 0 my ($self, $what, $newval) = @_;
364 0 ▶ croak "Usage: \$sock->$what or \$sock->$what(\$newvalue),"
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 3 0 0 0
365 if @_ > 3;
366 0 ▶ my $oldval = $self->getparam($what) if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 0 0 0
367 0 ▶ $self->setparams({$what=>$newval}) if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 0 0
368 0 $oldval;
369 }
370  
371 #& _setblocking($self, $name, $newval) : {'' | "carp string"}
372 sub _setblocking
373 16 ▶{
Subroutine _setblocking: called CC=16 SCAR=31.6
374 16 my ($self,$what,$newval) = @_;
375 16 ▶ $newval = 1 unless defined $newval;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newval 0 16 16
376 # default previous value, just in case
377 0 $ {*$self}{Parms}{$what} = 1 unless
378 16 ▶ defined $ {*$self}{Parms}{$what};
Branch: 1 branch
BranchTrueFalseTotal
unless defined do { *$self }->{"Parms"}{$what} 0 16 16
379 16 ▶ if ($newval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newval) { } 14 2 16
380 14 $_[2] = 1; # canonicalise the new value
381 14 ▶ if (defined $F_GETFL and defined $F_SETFL and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $F_GETFL and defined $F_SETFL and defined $nonblock_flag and $self->isopen) 7 7 14
Condition44%4/9
defined $F_GETFL and defined $F_SETFL and defined $nonblock_flag and $self->isopen
!ll&&!rl&&r
077
defined $F_GETFL and defined $F_SETFL and defined $nonblock_flag
!ll&&!rl&&r
0014
defined $F_GETFL and defined $F_SETFL
!ll&&!rl&&r
0014
MC/DC25%1/4
defined $F_GETFL and defined $F_SETFL and defined $nonblock_flag and $self->isopen
defined $F_GETFL defined $F_SETFL defined $nonblock_flag $self->isopen
Truth table40%2/5
A and B and C and D
A= defined $F_GETFLB= defined $F_SETFLC= defined $nonblock_flagD= $self->isopen
ABCDresult
0XXX0
10XX0
110X0
11100
11111
382 defined $nonblock_flag and $self->isopen)
383 {
384 7 ▶ if ((CORE::fcntl($self, $F_GETFL, 0) & VAL_O_NONBLOCK) ==
Branch: 1 branch
BranchTrueFalseTotal
if ((CORE::fcntl($self, $F_GETFL, 0) & 2048) == 2048) 2 5 7
385 VAL_O_NONBLOCK)
386 {
387 2 $ {*$self}{Parms}{$what} = 0; # note previous status
388 return 'Failed to clear non-blocking status'
389 2 ▶ unless eval {CORE::fcntl($self, $F_SETFL,
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { CORE::fcntl $self, $F_SETFL, CORE::fcntl($self, $F_GETFL, 0) & '18446744073709549567' } } 0 2 2
390 CORE::fcntl($self, $F_GETFL, 0) &
391 ~VAL_O_NONBLOCK)};
392 }
393 }
394 }
395 else {
396 2 $_[2] = 0; # canonicalise the new value
397 2 ▶ unless (defined $F_GETFL and defined $F_SETFL and
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $F_GETFL and defined $F_SETFL and defined $nonblock_flag) 0 2 2
Condition33%2/6
defined $F_GETFL and defined $F_SETFL and defined $nonblock_flag
!ll&&!rl&&r
002
defined $F_GETFL and defined $F_SETFL
!ll&&!rl&&r
002
MC/DC0%0/3
defined $F_GETFL and defined $F_SETFL and defined $nonblock_flag
defined $F_GETFL defined $F_SETFL defined $nonblock_flag
Truth table25%1/4
A and B and C
A= defined $F_GETFLB= defined $F_SETFLC= defined $nonblock_flag
ABCresult
0XX0
10X0
1100
1111
398 defined $nonblock_flag)
399 {
400 0 return 'Non-blocking sockets unavailable in this configuration';
401 }
402 2 ▶ if ($self->isopen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isopen) 2 0 2
403 2 ▶ if ((CORE::fcntl($self, $F_GETFL, 0) & VAL_O_NONBLOCK) !=
Branch: 1 branch
BranchTrueFalseTotal
if ((CORE::fcntl($self, $F_GETFL, 0) & 2048) != 2048) 2 0 2
404 VAL_O_NONBLOCK)
405 {
406 2 $ {*$self}{Parms}{$what} = 1; # note previous state
407 return 'Failed to set non-blocking status'
408 2 ▶ unless eval {CORE::fcntl($self, $F_SETFL,
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { CORE::fcntl $self, $F_SETFL, CORE::fcntl($self, $F_GETFL, 0) | 2048 } } 0 2 2
409 CORE::fcntl($self, $F_GETFL, 0) |
410 VAL_O_NONBLOCK)};
411 }
412 }
413 }
414 16 ''; # return goodness if got this far
415 }
416  
417 #& blocking($self [, $newval]) : canonical_oldval
418 sub blocking
419 1 ▶{
Subroutine blocking: called CC=4 SCAR=14.2
Pod documented
420 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
421 1 my ($self, $newval) = @_;
422 1 ▶ croak 'Usage: $sock->blocking or $sock->blocking(0|1),'
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 1 1
423 if @_ > 2;
424 1 ▶ my $oldval = $self->getparam('blocking', 1, 1) if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 1 0 1
425 1 ▶ $self->setparams({'blocking'=>$newval}) if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 1 1
426 1 $oldval;
427 }
428  
429 #& _settimeout($self, $what, $newval) : {'' | "carp string"}
430 sub _settimeout
431 3 ▶{
Subroutine _settimeout: called CC=4 SCAR=17.2
432 3 my ($self,$what,$newval) = @_;
433 3 ▶ unless (defined $newval) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $newval) 0 3 3
434 0 return ''; # It's always OK to delete a timeout.
435 }
436 3 ▶ if (!length($newval) or $newval =~ /\D/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not length $newval or $newval =~ /\D/) { } 0 3 3
Condition33%1/3
not length $newval or $newval =~ /\D/
l!l&&r!l&&!r
003
MC/DC0%0/2
not length $newval or $newval =~ /\D/
not length $newval $newval =~ /\D/
Truth table33%1/3
not(A) or B
A= not length $newvalB= $newval =~ /\D/
ABresult
1X1
011
000
437 0 "Parameter $what must be a non-negative integer or undefined";
438 }
439 else {
440 3 '';
441 }
442 }
443  
444 3 my @Keys = qw(PF AF type proto dstaddr dstaddrlist srcaddr srcaddrlist
445 maxqueue reuseaddr netgen_fakeconnect reuseport);
446 3 my %Codekeys = (
447 'debug' => \&_setdebug,
448 'blocking' => \&_setblocking,
449 'timeout' => \&_settimeout,
450 );
451 # This hash remembers the original {Keys} settings after the first time.
452 3 my %Keys;
453  
454 # This hash remembers the original socket option settings after the first time.
455 my %Opts;
456  
457 #& register_param_keys($self, \@keys)
458 sub register_param_keys
459 5 ▶{
Subroutine register_param_keys: called CC=3 SCAR=11.2
Pod documented
460 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
461 5 my ($self, $names) = @_;
462 5 my $whoami = $self->_trace(\@_,3);
463 5 ▶ croak "Invalid arguments to ${whoami}(@_), called"
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 or ref $names ne "ARRAY" 0 5 5
Condition33%1/3
@_ != 2 or ref $names ne "ARRAY"
l!l&&r!l&&!r
005
MC/DC0%0/2
@_ != 2 or ref $names ne "ARRAY"
@_ != 2 ref $names ne "ARRAY"
Truth table33%1/3
A or B
A= @_ != 2B= ref $names ne "ARRAY"
ABresult
1X1
011
000
464 if @_ != 2 or ref $names ne 'ARRAY';
465 5 @{$ {*$self}{Keys}}{@$names} =
466 5 @{$ {*$self}{Keys}}{@$names}; # remember the names
467 # this form doesn't clobber pre-existing register_param_handlers values
468 }
469  
470 sub registerParamKeys; # helps with -w
471 3 *registerParamKeys = \&register_param_keys; # alias form preferred by many
472  
473 #& register_param_handlers($self, \@keys, [\]@handlers)
474 #& -or- ($self, \%key-handlers)
475 sub register_param_handlers
476 5 ▶{
Subroutine register_param_handlers: called CC=9 SCAR=30.0
Pod documented
477 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
478 5 my ($self, $names, @handlers, $handlers) = @_;
479 5 my $whoami = $self->_trace(\@_,3);
480 5 ▶ if (ref $names eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $names eq 'HASH') { } 5 0 5
481 5 ▶ croak "Invalid parameters to ${whoami}(@_), called"
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 5 5
482 if @_ != 2;
483 5 $handlers = [values %$names];
484 5 $names = [keys %$names];
485 }
486 else {
487 0 ▶ croak "Invalid parameters to ${whoami}(@_), called"
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 or ref $names ne "ARRAY" 0 0 0
Condition0%0/3
@_ < 3 or ref $names ne "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 3 or ref $names ne "ARRAY"
@_ < 3 ref $names ne "ARRAY"
Truth table0%0/3
A or B
A= @_ < 3B= ref $names ne "ARRAY"
ABresult
1X1
011
000
488 if @_ < 3 or ref $names ne 'ARRAY';
489 0 $handlers = \@handlers; # in case passed as a list
490 0 ▶ $handlers = $_[2] if @_ == 3 and ref($_[2]) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 3 and ref $_[2] eq "ARRAY" 0 0 0
Condition0%0/3
@_ == 3 and ref $_[2] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 3 and ref $_[2] eq "ARRAY"
@_ == 3 ref $_[2] eq "ARRAY"
Truth table0%0/3
A and B
A= @_ == 3B= ref $_[2] eq "ARRAY"
ABresult
0X0
100
111
491 }
492 5 ▶ croak "Invalid handlers in ${whoami}(@_), called"
Branch: 1 branch
BranchTrueFalseTotal
if @$handlers != @$names or grep((ref $_ ne "CODE"), @$handlers) 0 5 5
Condition33%1/3
@$handlers != @$names or grep((ref $_ ne "CODE"), @$handlers)
l!l&&r!l&&!r
005
MC/DC0%0/2
@$handlers != @$names or grep((ref $_ ne "CODE"), @$handlers)
@$handlers != @$names grep((ref $_ ne "CODE"), @$handlers)
Truth table33%1/3
A or B
A= @$handlers != @$namesB= grep((ref $_ ne "CODE"), @$handlers)
ABresult
1X1
011
000
493 if @$handlers != @$names or grep(ref $_ ne 'CODE', @$handlers);
494 # finally, all is validated, so set the bloody things
495 5 @{$ {*$self}{Keys}}{@$names} = @$handlers;
496 }
497  
498 sub registerParamHandlers; # helps with -w
499 3 *registerParamHandlers = \&register_param_handlers; # alias other form
500  
501 #& register_options($self, $levelname, $level, \%options)
502 sub register_options
503 3 ▶{
Subroutine register_options: called CC=2 SCAR=6.9
Pod documented
504 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
505 3 my ($self, $levname, $level, $opts) = @_;
506 3 my $whoami = $self->_trace(\@_,3);
507 3 ▶ croak "Invalid arguments to ${whoami}(@_), called"
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts ne "HASH" 0 3 3
508 if ref $opts ne 'HASH';
509 3 $ {*$self}{Sockopts}{$levname} = $opts;
510 3 $ {*$self}{Sockopts}{$level+0} = $opts;
511 }
512  
513 sub registerOptions; # helps with -w
514 3 *registerOptions = \&register_options; # alias form preferred by many
515  
516 # pseudo-subclass for saving parameters (ParamSaver, inspired by SelectSaver)
517 #& param_saver($self, @params) : restoration_object
518 sub param_saver
519 2 ▶{
Subroutine param_saver: called CC=1 SCAR=0.0
Pod documented
520 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
521 2 my ($self, @params) = @_;
522 my @delparams =
523 # map { exists $ {*$self}{Parms}{$_} ? () : ($_) } @params;
524 2 grep {!exists $ {*$self}{Parms}{$_}} @params;
525 2 my %setparams = $self->getparams(\@params);
526 2 bless [$self, \%setparams, \@delparams], 'Net::Gen::ParamSaver';
527 }
528  
529 sub paramSaver; # aliases
530 3 *paramSaver = \&param_saver;
531 sub ParamSaver;
532 3 *ParamSaver = \&param_saver;
533  
534 sub Net::Gen::ParamSaver::DESTROY
535 2 ▶{
Subroutine DESTROY: called CC=1 SCAR=0.0
536 2 local $!; # just to be sure we don't clobber it
537 2 $_[0]->[0]->setparams($_[0]->[1]);
538 2 $_[0]->[0]->delparams($_[0]->[2]);
539 }
540  
541 #& new(classname [, \%params]) : {$self | undef}
542 #& -or- $classname [, @ignored]
543 sub new
544 6 ▶{
Subroutine new: called CC=15 SCAR=30.8
Pod documented
545 6 my $whoami = $_[0]->_trace(\@_,1);
546 6 my($pack,$parms) = @_;
547 6 my %parms;
548 6 ▶ %parms = ( %$parms ) if $parms and ref $parms eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if $parms and ref $parms eq "HASH" 1 5 6
Condition100%3/3
$parms and ref $parms eq "HASH"
!ll&&!rl&&r
231
MC/DC100%2/2
$parms and ref $parms eq "HASH"
$parms ref $parms eq "HASH"
Truth table100%3/3
A and B
A= $parmsB= ref $parms eq "HASH"
ABresult
0X0
100
111
549 6 ▶ $parms{'debug'} = $pack->_debug unless defined $parms{'debug'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"debug"} 6 0 6
550 6 ▶ $parms{'blocking'} = 1 unless defined $parms{'blocking'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"blocking"} 6 0 6
551 6 ▶ if (@_ > 2 and $parms and ref $parms eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2 and $parms and ref $parms eq "HASH") 0 6 6
Condition66%4/6
@_ > 2 and $parms and ref $parms eq "HASH"
!ll&&!rl&&r
510
@_ > 2 and $parms
!ll&&!rl&&r
501
MC/DC0%0/3
@_ > 2 and $parms and ref $parms eq "HASH"
@_ > 2 $parms ref $parms eq "HASH"
Truth table50%2/4
A and B and C
A= @_ > 2B= $parmsC= ref $parms eq "HASH"
ABCresult
0XX0
10X0
1100
1111
552 0 croak "Invalid argument format to ${whoami}(@_), called";
553 }
554 6 ▶ my $class = ref $pack || $pack;
Condition66%2/3
ref $pack || $pack
l!l&&r!l&&!r
150
MC/DC0%0/2
ref $pack || $pack
ref $pack $pack
Truth table66%2/3
A || B
A= ref $packB= $pack
ABresult
1X1
011
000
555 6 my $self = _genfh;
556 6 bless $self,$class;
557 6 $pack->_trace(\@_,2,", self=$self after bless");
558 6 $ {*$self}{Parms} = \%parms;
559 6 ▶ if (%Keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (%Keys) { } 4 2 6
560 4 $ {*$self}{Keys} = { %Keys };
561 4 $ {*$self}{Sockopts} = { %Opts };
562 }
563 else {
564 2 $self->register_param_keys(\@Keys); # register our keys
565 2 $self->register_param_handlers(\%Codekeys);
566 2 $self->register_options('SOL_SOCKET', SOL_SOCKET(), \%sockopts);
567 2 %Keys = %{$ {*$self}{Keys}};
568 2 %Opts = %{$ {*$self}{Sockopts}};
569 }
570 6 ▶ if ($class eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 0 6 6
571 0 ▶ unless ($self->init) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->init) 0 0 0
572 0 local $!; # preserve errno
573 0 undef $self; # against the side-effects of this
574 0 undef $self; # another statement needed for unwinding
575 }
576 }
577 6 ▶ if (($self || $pack)->_debug) {
Branch: 1 branch
BranchTrueFalseTotal
if (($self || $pack)->_debug) 0 6 6
Condition33%1/3
$self || $pack
l!l&&r!l&&!r
600
MC/DC0%0/2
$self || $pack
$self $pack
Truth table33%1/3
A || B
A= $selfB= $pack
ABresult
1X1
011
000
578 0 ▶ if (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self) { } 0 0 0
579 0 print STDERR "${whoami} returning self=$self\n";
580 }
581 else {
582 0 print STDERR "${whoami} returning undef\n";
583 }
584 }
585 6 $self;
586 }
587  
588 #& setparams($this, \%newparams [, $newonly [, $check]]) : boolean
589 sub setparams
590 47 ▶{
Subroutine setparams: called CC=26 SCAR=34.5
Pod documented
591 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
592 47 my ($self,$newparams,$newonly,$check) = @_;
593 47 my $errs = 0;
594  
595 47 ▶ croak "Bad arguments to " . __PACKAGE__ . "::setparams, called"
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 and ref $newparams eq "HASH" 0 47 47
Condition33%1/3
@_ > 1 and ref $newparams eq "HASH"
!ll&&!rl&&r
0047
MC/DC0%0/2
@_ > 1 and ref $newparams eq "HASH"
@_ > 1 ref $newparams eq "HASH"
Truth table33%1/3
A and B
A= @_ > 1B= ref $newparams eq "HASH"
ABresult
0X0
100
111
596 unless @_ > 1 and ref $newparams eq 'HASH';
597 47 ▶ carp "Excess arguments to " . __PACKAGE__ . "::setparams ignored"
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 4 0 47 47
598 if @_ > 4;
599  
600 47 ▶ $newonly ||= 0; # undefined or zero is equiv now (-w problem)
Condition100%2/2
$newonly ||= 0
l!l
1433
MC/DC100%1/1
$newonly ||= 0
$newonly
Truth table100%2/2
A
A= $newonly
Aresult
11
00
601 47 my ($parm,$newval,$pslot);
602 47 ▶ while (($parm,$newval) = each %$newparams) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$newparams) 133 47 180
603 133 ▶ print STDERR __PACKAGE__ . "::setparams $self $parm" .
Branch: 2 branches
BranchTrueFalseTotal
if $self->debug 0 133 133
defined $newval ? : 0 0 0
604 (defined $newval ? " $newval" : "") . "\n"
605 if $self->debug;
606 (carp "Unknown parameter type $parm for a " . (ref $self) . " object")
607 , $errs++, next
608 133 ▶ unless exists $ {*$self}{Keys}{$parm};
Branch: 1 branch
BranchTrueFalseTotal
unless exists do { *$self }->{"Keys"}{$parm} 0 133 133
609 133 $pslot = \$ {*$self}{Parms}{$parm};
610 133 ▶ next if $newonly < 0 && defined $$pslot;
Branch: 1 branch
BranchTrueFalseTotal
if $newonly < 0 and defined $$pslot 2 131 133
Condition100%3/3
$newonly < 0 and defined $$pslot
!ll&&!rl&&r
93382
MC/DC100%2/2
$newonly < 0 and defined $$pslot
$newonly < 0 defined $$pslot
Truth table100%3/3
A and B
A= $newonly < 0B= defined $$pslot
ABresult
0X0
100
111
611 131 ▶ if (!$check)
Branch: 1 branch
BranchTrueFalseTotal
unless ($check) 65 66 131
612 {
613 # this ungodly construct brought to you by -w
614 next if
615 65 ▶ defined($$pslot) eq defined($newval)
Branch: 1 branch
BranchTrueFalseTotal
if defined $$pslot eq defined $newval and !defined($newval) || $$pslot eq $newval || !($$pslot =~ /\D/ || $newval =~ /\D/) && length $newval && length $$pslot && $$pslot == $newval 2 63 65
Condition71%15/21
defined $$pslot eq defined $newval and !defined($newval) || $$pslot eq $newval || !($$pslot =~ /\D/ || $newval =~ /\D/) && length $newval && length $$pslot && $$pslot == $newval
!ll&&!rl&&r
5582
not defined $newval or $$pslot eq $newval or not $$pslot =~ /\D/ || $newval =~ /\D/ and length $newval and length $$pslot and $$pslot == $newval
l!l&&r!l&&!r
208
not defined $newval or $$pslot eq $newval
l!l&&r!l&&!r
028
not $$pslot =~ /\D/ || $newval =~ /\D/ and length $newval and length $$pslot and $$pslot == $newval
!ll&&!rl&&r
350
not $$pslot =~ /\D/ || $newval =~ /\D/ and length $newval and length $$pslot
!ll&&!rl&&r
305
not $$pslot =~ /\D/ || $newval =~ /\D/ and length $newval
!ll&&!rl&&r
305
$$pslot =~ /\D/ || $newval =~ /\D/
l!l&&r!l&&!r
305
MC/DC25%2/8
defined $$pslot eq defined $newval and !defined($newval) || $$pslot eq $newval || !($$pslot =~ /\D/ || $newval =~ /\D/) && length $newval && length $$pslot && $$pslot == $newval
defined $$pslot eq defined $newval not defined $newval $$pslot eq $newval $$pslot =~ /\D/ $newval =~ /\D/ length $newval length $$pslot $$pslot == $newval
Truth table44%4/9
A and not(B) or C or not(D || E) and F and G and H
A= defined $$pslot eq defined $newvalB= not defined $newvalC= $$pslot eq $newvalD= $$pslot =~ /\D/E= $newval =~ /\D/F= length $newvalG= length $$pslotH= $$pslot == $newval
ABCDEFGHresult
0XXXXXXX0
1001XXXX0
10001XXX0
100000XX0
1000010X0
100001100
11XXXXXX1
101XXXXX1
100001111
616 and
617 !defined($newval) ||
618 $$pslot eq $newval ||
619 $$pslot !~ /\D/ &&
620 $newval !~ /\D/ &&
621 length($newval) &&
622 length($$pslot) &&
623 $$pslot == $newval
624 ;
625 }
626 129 ▶ carp("Overwrite of $parm parameter for ".(ref $self)." object ignored")
Branch: 1 branch
BranchTrueFalseTotal
if $newonly > 0 and defined $$pslot 0 129 129
Condition33%1/3
$newonly > 0 and defined $$pslot
!ll&&!rl&&r
12900
MC/DC0%0/2
$newonly > 0 and defined $$pslot
$newonly > 0 defined $$pslot
Truth table33%1/3
A and B
A= $newonly > 0B= defined $$pslot
ABresult
0X0
100
111
627 , $errs++, next
628 if $newonly > 0 && defined $$pslot;
629 129 ▶ if (defined($ {*$self}{Keys}{$parm}) and
Branch: 1 branch
BranchTrueFalseTotal
if (defined do { *$self }->{"Keys"}{$parm} and ref do { *$self }->{"Keys"}{$parm} eq "CODE") 35 94 129
Condition66%2/3
defined do { *$self }->{"Keys"}{$parm} and ref do { *$self }->{"Keys"}{$parm} eq "CODE"
!ll&&!rl&&r
94035
MC/DC50%1/2
defined do { *$self }->{"Keys"}{$parm} and ref do { *$self }->{"Keys"}{$parm} eq "CODE"
defined do { *$self }->{"Keys"}{$parm} ref do { *$self }->{"Keys"}{$parm} eq "CODE"
Truth table66%2/3
A and B
A= defined do { *$self }->{"Keys"}{$parm}B= ref do { *$self }->{"Keys"}{$parm} eq "CODE"
ABresult
0X0
100
111
630 35 (ref($ {*$self}{Keys}{$parm}) eq 'CODE'))
631 {
632 35 my $rval = &{$ {*$self}{Keys}{$parm}}($self,$parm,$newval);
633 35 ▶ (carp $rval), $errs++, next if $rval;
Branch: 1 branch
BranchTrueFalseTotal
if $rval 2 33 35
634 }
635 # not using $$pslot here in case {Parms} hash re-generated
636 127 $ {*$self}{Parms}{$parm} = $newval;
637 }
638  
639 47 ▶ $errs ? undef : 1;
Branch: 1 branch
BranchTrueFalseTotal
$errs ? : 2 45 47
640 }
641
642  
643 #& delparams($self, \@paramnames) : boolean
644 sub delparams
645 8 ▶{
Subroutine delparams: called CC=3 SCAR=11.0
Pod documented
646 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
647 8 $_[0]->_trace(\@_,1);
648 8 my($self,$keysref) = @_;
649 8 my(@k,%k);
650 8 @k = grep(exists $ {*$self}{Parms}{$_}, @$keysref);
651 8 ▶ return 1 unless @k; # if no keys need deleting, succeed vacuously
Branch: 1 branch
BranchTrueFalseTotal
unless @k 3 5 8
652 5 @k{@k} = (); # a hash of undefs for the following
653 5 ▶ return undef unless $self->setparams(\%k); # see whether undef is allowed
Branch: 1 branch
BranchTrueFalseTotal
unless $self->setparams(\%k) 0 5 5
654 5 delete @{$ {*$self}{Parms}}{@k};
655 5 1; # return goodness
656 }
657  
658 #& checkparams($self) : boolean
659 sub checkparams
660 7 ▶{
Subroutine checkparams: called CC=3 SCAR=11.0
Pod documented
661 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
662 7 my $whoami = $_[0]->_trace(\@_,1);
663 7 my $self = shift;
664 7 ▶ carp "Excess arguments to ${whoami} ignored"
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 7 7
665 if @_;
666 7 my $curparms = $ {*$self}{Parms};
667 7 ▶ $curparms = {} unless ref $curparms eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $curparms eq "HASH" 0 7 7
668 # make sure only the valid ones are set when we're done
669 7 $ {*$self}{Parms} = {};
670 7 my(@valkeys) = grep(exists $ {*$self}{Keys}{$_}, keys %$curparms);
671 # this assignment allows for inter-key dependencies to be evaluated
672 7 @{$ {*$self}{Parms}}{@valkeys} =
673 7 @{$curparms}{@valkeys};
674 # validate all current against the defined keys
675 7 $self->setparams($curparms, 0, 1);
676 }
677  
678 #& init($self) : {$self | undef}
679 sub init
680 6 ▶{
Subroutine init: called CC=2 SCAR=6.9
Pod documented
681 6 $_[0]->_trace(\@_,1);
682 6 my($self) = @_;
683 6 ▶ $self->checkparams ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->checkparams ? : 5 1 6
684 }
685  
686 #& getparam($self, $key [, $default [, $defaultifundef]]) : param_value
687 sub getparam
688 19 ▶{
Subroutine getparam: called CC=5 SCAR=16.1
Pod documented
689 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
690 19 my $whoami = $_[0]->_trace(\@_,2);
691 19 my($self,$key,$defval,$noundef) = @_;
692 19 ▶ carp "Excess arguments to ${whoami}($self) ignored"
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 4 0 19 19
693 if @_ > 4;
694 19 ▶ if ($noundef) {
Branch: 1 branch
BranchTrueFalseTotal
if ($noundef) { } 12 7 19
695 12 ▶ return $defval unless defined($ {*$self}{Parms}{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless defined do { *$self }->{"Parms"}{$key} 1 11 12
696 }
697 else {
698 7 ▶ return $defval unless exists($ {*$self}{Parms}{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless exists do { *$self }->{"Parms"}{$key} 0 7 7
699 }
700 18 $ {*$self}{Parms}{$key};
701 }
702  
703 #& getparams($self, \@keys [, $noundef]) : (%hash)
704 sub getparams
705 14 ▶{
Subroutine getparams: called CC=11 SCAR=29.4
Pod documented
706 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
707 14 my $whoami = $_[0]->_trace(\@_,2);
708 14 my ($self,$aref,$noundef) = @_;
709 14 ▶ croak "Insufficient arguments to ${whoami}($self), called"
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or not ref $self or ref $aref ne "ARRAY" 0 14 14
Condition33%2/6
@_ < 2 or not ref $self or ref $aref ne "ARRAY"
l!l&&r!l&&!r
0014
@_ < 2 or not ref $self
l!l&&r!l&&!r
0014
MC/DC0%0/3
@_ < 2 or not ref $self or ref $aref ne "ARRAY"
@_ < 2 not ref $self ref $aref ne "ARRAY"
Truth table25%1/4
A or not(B) or C
A= @_ < 2B= not ref $selfC= ref $aref ne "ARRAY"
ABCresult
1XX1
01X1
0011
0000
710 if @_ < 2 || !ref $self || ref $aref ne 'ARRAY';
711 14 ▶ carp "Excess arguments to ${whoami}($self) ignored"
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 3 0 14 14
712 if @_ > 3;
713 14 ▶ return unless defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 14 14
714 14 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 2 12 14
715 # the actual list is wanted -- see which way to do it
716 2 ▶ if ($noundef) {
Branch: 1 branch
BranchTrueFalseTotal
if ($noundef) { } 0 2 2
717 0 map {defined $ {*$self}{Parms}{$_} ?
718 0 ▶ ($_, $ {*$self}{Parms}{$_}) :
Branch: 1 branch
BranchTrueFalseTotal
defined do { *$self }->{'Parms'}{$_} ? : 0 0 0
719 ()
720 } @$aref;
721 }
722 else {
723 2 map {exists $ {*$self}{Parms}{$_} ?
724 2 ▶ ($_, $ {*$self}{Parms}{$_}) :
Branch: 1 branch
BranchTrueFalseTotal
exists do { *$self }->{'Parms'}{$_} ? : 2 0 2
725 ()
726 } @$aref;
727 }
728 }
729 else {
730 # the list count is wanted -- see which way to do it
731 12 ▶ if ($noundef) {
Branch: 1 branch
BranchTrueFalseTotal
if ($noundef) { } 12 0 12
732 12 2 * grep {defined $ {*$self}{Parms}{$_}} @$aref;
733 }
734 else {
735 0 2 * grep {exists $ {*$self}{Parms}{$_}} @$aref;
736 }
737 }
738 # my @ret;
739 # foreach (@$aref) {
740 # push(@ret, $_, $ {*$self}{Parms}{$_})
741 # if exists($ {*$self}{Parms}{$_}) and
742 # !$noundef || defined($ {*$self}{Parms}{$_});
743 # }
744 # wantarray ? @ret : 0+@ret;
745 }
746
747  
748 #& condition($self)
749 sub condition
750 5 ▶{
Subroutine condition: called CC=1 SCAR=0.0
Pod documented
751 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
752 5 my $self = $_[0];
753 5 my $sel = SelectSaver->new;
754 5 CORE::select($self);
755 5 $| = 1;
756 # $\ = "\015\012";
757 5 binmode($self);
758 5 vec($ {*$self}{FHVec} = '', CORE::fileno($self), 1) = 1;
759 5 $self->setparams({'blocking'=>$self->getparam('blocking',1,1)},0,1);
760 }
761  
762 #& open($self [, @ignore]) : boolean
763 sub open
764 4 ▶{
Subroutine open: called CC=11 SCAR=27.4
Pod documented
765 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
766 4 $_[0]->_trace(\@_,2);
767 4 my $self = shift;
768 4 ▶ $self->stopio if $self->isopen;
Branch: 1 branch
BranchTrueFalseTotal
if $self->isopen 0 4 4
769 4 my($pf,$af,$type,$proto) = \@{$ {*$self}{Parms}}{qw(PF AF type proto)};
770 4 ▶ $$pf = PF_UNSPEC unless defined $$pf;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$pf 0 4 4
771 4 ▶ $$af = AF_UNSPEC unless defined $$af;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$af 0 4 4
772 4 ▶ $$type = 0 unless defined $$type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$type 0 4 4
773 4 ▶ $$proto = 0 unless defined $$proto;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$proto 4 0 4
774 4 ▶ if (($$pf == PF_UNSPEC) && ($$af != AF_UNSPEC)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$pf == 0 and $$af != 0) { } 0 4 4
elsif ($$af == 0 and $$pf != 0) { } 0 8 8
Condition33%1/3
$$pf == 0 and $$af != 0
!ll&&!rl&&r
400
MC/DC0%0/2
$$pf == 0 and $$af != 0
$$pf == 0 $$af != 0
Truth table33%1/3
A and B
A= $$pf == 0B= $$af != 0
ABresult
0X0
100
111
775 0 $$pf = $$af;
776 }
777 ▶ elsif (($$af == AF_UNSPEC) && ($$pf != PF_UNSPEC)) {
Condition33%1/3
$$af == 0 and $$pf != 0
!ll&&!rl&&r
400
MC/DC0%0/2
$$af == 0 and $$pf != 0
$$af == 0 $$pf != 0
Truth table33%1/3
A and B
A= $$af == 0B= $$pf != 0
ABresult
0X0
100
111
778 0 $$af = $$pf;
779 }
780 4 ▶ if ($ {*$self}{'isopen'} = socket($self,$$pf,$$type,$$proto)) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{"isopen"} = socket($self, $$pf, $$type, $$proto)) 4 0 4
781 # keep stdio output buffers out of my way
782 4 $self->condition;
783 }
784 4 $self->isopen;
785 }
786  
787 # sub listen - autoloaded
788  
789 # hashes for async. connect error values
790 3 my %connok = ( EISCONN,1 );
791 3 my %connip = ( EWOULDBLOCK,1 , EINPROGRESS,1 , EAGAIN,1 , EALREADY,1 );
792  
793 #& _valconnect($self, $addr, $timeout) : boolean
794 sub _valconnect
795 0 ▶{
Subroutine _valconnect: not called CC=15 SCAR=54.8
796 0 my ($self,$addr,$timeout) = @_;
797 0 my ($fhvec,$rdvec,$wrvec,$nfound) = $ {*$self}{FHVec};
798 # don't block if socket is non-blocking
799 $timeout = 0 if
800 0 ▶ !defined $timeout && !$ {*$self}{Parms}{'blocking'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timeout or do { *$self }->{"Parms"}{"blocking"} 0 0 0
Condition0%0/3
defined $timeout or do { *$self }->{"Parms"}{"blocking"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $timeout or do { *$self }->{"Parms"}{"blocking"}
defined $timeout do { *$self }->{"Parms"}{"blocking"}
Truth table0%0/3
A or B
A= defined $timeoutB= do { *$self }->{"Parms"}{"blocking"}
ABresult
1X1
011
000
801 # assume caller checked for ->isconnecting
802 0 $rdvec = $wrvec = $fhvec;
803 0 $nfound = CORE::select($rdvec, $wrvec, undef, $timeout);
804 # If socket is 'ready', then the connect is complete (possibly failed).
805 0 ▶ $ {*$self}{'isconnecting'} = 0 if $nfound;
Branch: 1 branch
BranchTrueFalseTotal
if $nfound 0 0 0
806 # If we don't think the connect has finished, just try to invent a
807 # reasonable error and bug out.
808 0 ▶ if (!$nfound) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nfound) 0 0 0
809 0 $! = EINPROGRESS || EWOULDBLOCK || EALREADY || EAGAIN;
810 0 return;
811 }
812 0 my $rval;
813 # If we can try to find out with SO_ERROR, give it a shot.
814 # This won't give valid results with SOCKS. Tough.
815 0 ▶ if ($ {*$self}{Sockopts}{'SOL_SOCKET'}{'SO_ERROR'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{"Sockopts"}{"SOL_SOCKET"}{"SO_ERROR"}) 0 0 0
816 # Don't try the getsockopt if the connect is still pending!
817 # Solaris 2.5.1 (at least) hangs the getsockopt in that case.
818 # The connect is complete -- figure out whether we believe
819 # the status.
820 0 $rval = getsockopt($self,SOL_SOCKET,SO_ERROR);
821 0 ▶ return unless defined $rval;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rval 0 0 0
822 0 $rval = unpack("I", $rval);
823 0 ▶ if ($rval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rval) 0 0 0
824 0 $! = $rval;
825 0 return;
826 }
827 0 ▶ return unless defined getpeername($self);
Branch: 1 branch
BranchTrueFalseTotal
unless defined getpeername $self 0 0 0
828 0 return 1;
829 }
830 # Here, we can't use SO_ERROR (it's not available).
831 # The canonical test for success here involves a read() attempt, but
832 # we can't use that unless we have a stream socket. SOCK_SEQPACKET and
833 # real datagram services would lose their initial transmission to a
834 # read check. So, we try it here only if we think we are SOCK_STREAM.
835 0 my $type = $ {*$self}{Parms}{'type'};
836 0 ▶ if ($type && $type==SOCK_STREAM) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type and $type == 1) 0 0 0
Condition0%0/3
$type and $type == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$type and $type == 1
$type $type == 1
Truth table0%0/3
A and B
A= $typeB= $type == 1
ABresult
0X0
100
111
837 0 my $buf = "";
838 0 $rval = sysread($self,$buf,0);
839 0 ▶ return unless defined $rval;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rval 0 0 0
840 # It succeeded. Should it have? If getpeername says so,
841 # we still can't be sure, and we'll have to use a second connect().
842 }
843 0 ▶ return unless defined getpeername($self);
Branch: 1 branch
BranchTrueFalseTotal
unless defined getpeername $self 0 0 0
844 0 $rval = CORE::connect($self,$addr);
845 0 ▶ return $rval if $rval;
Branch: 1 branch
BranchTrueFalseTotal
if $rval 0 0 0
846 0 ▶ return 1 if $connok{0+$!};
Branch: 1 branch
BranchTrueFalseTotal
if $connok{0 + $!} 0 0 0
847 0 $rval;
848 }
849  
850 #& _tryconnect($self, $addr, $timeout) : boolean
851 sub _tryconnect
852 2 ▶{
Subroutine _tryconnect: called CC=17 SCAR=48.0
853 2 my ($self,$addr,$timeout) = @_;
854 2 ▶ if ($ {*$self}{'isconnecting'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{"isconnecting"}) 0 2 2
855 0 ▶ if ($ {*$self}{Parms}{'dstaddr'} and
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{"Parms"}{"dstaddr"} and do { *$self }->{"Parms"}{"dstaddr"} ne $addr) 0 0 0
Condition0%0/3
do { *$self }->{"Parms"}{"dstaddr"} and do { *$self }->{"Parms"}{"dstaddr"} ne $addr
!ll&&!rl&&r
000
MC/DC0%0/2
do { *$self }->{"Parms"}{"dstaddr"} and do { *$self }->{"Parms"}{"dstaddr"} ne $addr
do { *$self }->{"Parms"}{"dstaddr"} do { *$self }->{"Parms"}{"dstaddr"} ne $addr
Truth table0%0/3
A and B
A= do { *$self }->{"Parms"}{"dstaddr"}B= do { *$self }->{"Parms"}{"dstaddr"} ne $addr
ABresult
0X0
100
111
856 0 ($ {*$self}{Parms}{'dstaddr'} ne $addr))
857 {
858 carp "$self->_tryconnect: different destination address while ->isconnecting!"
859 0 ▶ if $ {*$self}{Parms}{'debug'} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"Parms"}{"debug"} > 2 0 0 0
860 0 $self->stopio;
861 0 ▶ return undef unless $self->open;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->open 0 0 0
862 0 ▶ if ($self->getparam('srcaddr') || $self->getparam('srcaddrlist')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getparam("srcaddr") || $self->getparam("srcaddrlist") and not $self->isbound) 0 0 0
Condition0%0/6
$self->getparam("srcaddr") || $self->getparam("srcaddrlist") and not $self->isbound
!ll&&!rl&&r
000
$self->getparam("srcaddr") or $self->getparam("srcaddrlist")
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->getparam("srcaddr") || $self->getparam("srcaddrlist") and not $self->isbound
$self->getparam("srcaddr") $self->getparam("srcaddrlist") not $self->isbound
Truth table0%0/5
A or B and not(C)
A= $self->getparam("srcaddr")B= $self->getparam("srcaddrlist")C= not $self->isbound
ABCresult
00X0
1X00
0100
1X11
0111
863 and !$self->isbound)
864 {
865 0 ▶ return undef unless $self->bind;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->bind 0 0 0
866 }
867 }
868 }
869 # Apparently, some versions of Solaris don't like a second connect.
870 # So, if we're retrying a non-blocking connect, check by other means
871 # before trying to use a second connect to get the status.
872 # Warning: This will not work with SOCKS.
873 2 ▶ unless ($ {*$self}{'isconnecting'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (do { *$self }->{"isconnecting"}) 2 0 2
874 # For Solaris, if datagram socket, don't connect if not bound.
875 2 ▶ if ($ {*$self}{Parms}{netgen_fakeconnect}) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{"Parms"}{"netgen_fakeconnect"}) 1 1 2
876 1 ▶ if (!$self->isbound) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->isbound) { } 1 0 1
877 1 $ {*$self}{Parms}{'dstaddr'} = $addr;
878 1 return 1;
879 }
880 else {
881 0 $self->delparams(['netgen_fakeconnect']);
882 }
883 }
884 1 my $rval = CORE::connect($self,$addr);
885 1 ▶ return $rval if $rval;
Branch: 1 branch
BranchTrueFalseTotal
if $rval 1 0 1
886 0 ▶ return 1 if $connok{0+$!};
Branch: 1 branch
BranchTrueFalseTotal
if $connok{0 + $!} 0 0 0
887 0 ▶ return $rval unless $connip{0+$!};
Branch: 1 branch
BranchTrueFalseTotal
unless $connip{0 + $!} 0 0 0
888 0 $ {*$self}{'isconnecting'} = 1;
889 0 $ {*$self}{Parms}{'dstaddr'} = $addr;
890 0 ▶ return $rval unless defined $timeout;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timeout 0 0 0
891 }
892 0 &_valconnect;
893 }
894  
895 #& connect($self, [@ignored]) : boolean
896 sub connect
897 2 ▶{
Subroutine connect: called CC=25 SCAR=42.6
Pod documented
898 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
899 2 $_[0]->_trace(\@_,2);
900 2 my $self = shift;
901 2 my $hval = *$self{HASH};
902 2 my $parms = $hval->{Parms};
903 $self->close if
904 $hval->{'isconnected'} ||
905 2 ▶ (!$hval->{'isconnecting'} && $hval->{'wasconnected'});
Branch: 1 branch
BranchTrueFalseTotal
if $hval->{"isconnected"} or not $hval->{"isconnecting"} and $hval->{"wasconnected"} 0 2 2
Condition33%2/6
$hval->{"isconnected"} or not $hval->{"isconnecting"} and $hval->{"wasconnected"}
l!l&&r!l&&!r
002
not $hval->{"isconnecting"} and $hval->{"wasconnected"}
!ll&&!rl&&r
020
MC/DC0%0/3
$hval->{"isconnected"} or not $hval->{"isconnecting"} and $hval->{"wasconnected"}
$hval->{"isconnected"} not $hval->{"isconnecting"} $hval->{"wasconnected"}
Truth table25%1/4
A or not(B) and C
A= $hval->{"isconnected"}B= not $hval->{"isconnecting"}C= $hval->{"wasconnected"}
ABCresult
1XX1
0111
00X0
0100
906 2 ▶ return undef unless $self->isopen or $self->open;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isopen or $self->open 0 2 2
Condition66%2/3
$self->isopen or $self->open
l!l&&r!l&&!r
110
MC/DC0%0/2
$self->isopen or $self->open
$self->isopen $self->open
Truth table66%2/3
A or B
A= $self->isopenB= $self->open
ABresult
1X1
011
000
907 2 ▶ if ($parms->{'srcaddr'} || $parms->{'srcaddrlist'}
Branch: 1 branch
BranchTrueFalseTotal
if ($parms->{"srcaddr"} || $parms->{"srcaddrlist"} and not $hval->{"isconnecting"} and not $self->isbound) 0 2 2
Condition33%3/9
$parms->{"srcaddr"} || $parms->{"srcaddrlist"} and not $hval->{"isconnecting"} and not $self->isbound
!ll&&!rl&&r
200
$parms->{"srcaddr"} || $parms->{"srcaddrlist"} and not $hval->{"isconnecting"}
!ll&&!rl&&r
200
$parms->{"srcaddr"} or $parms->{"srcaddrlist"}
l!l&&r!l&&!r
002
MC/DC0%0/4
$parms->{"srcaddr"} || $parms->{"srcaddrlist"} and not $hval->{"isconnecting"} and not $self->isbound
$parms->{"srcaddr"} $parms->{"srcaddrlist"} not $hval->{"isconnecting"} not $self->isbound
Truth table14%1/7
A or B and not(C) and not(D)
A= $parms->{"srcaddr"}B= $parms->{"srcaddrlist"}C= not $hval->{"isconnecting"}D= not $self->isbound
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
908 and !$hval->{'isconnecting'} and !$self->isbound)
909 {
910 0 ▶ return undef unless $self->bind;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->bind 0 0 0
911 }
912 2 my $rval;
913 2 my $error = 0; # errno to propagate if failing
914 {
915 2 my ($saveblocking,$timeout);
916 2 ▶ if (defined ($timeout = $parms->{'timeout'}) && $self->blocking) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($timeout = $parms->{"timeout"}) and $self->blocking) 1 1 2
Condition66%2/3
defined($timeout = $parms->{"timeout"}) and $self->blocking
!ll&&!rl&&r
101
MC/DC50%1/2
defined($timeout = $parms->{"timeout"}) and $self->blocking
defined($timeout = $parms->{"timeout"}) $self->blocking
Truth table66%2/3
A and B
A= defined($timeout = $parms->{"timeout"})B= $self->blocking
ABresult
0X0
100
111
917 1 $saveblocking = $self->param_saver('blocking');
918 1 ▶ $self->setparams({'blocking'=>0}) or undef $timeout;
Branch: 1 branch
BranchTrueFalseTotal
$self->setparams({"blocking", 0}) or undef $timeout 1 0 1
919 }
920 2 my $dlist = $parms->{dstaddrlist};
921 2 ▶ if (defined($dlist) and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dlist and ref $dlist eq 'ARRAY' and not $hval->{'isconnecting'}) { } 2 0 2
Condition33%2/6
defined $dlist and ref $dlist eq "ARRAY" and not $hval->{"isconnecting"}
!ll&&!rl&&r
002
defined $dlist and ref $dlist eq "ARRAY"
!ll&&!rl&&r
002
MC/DC0%0/3
defined $dlist and ref $dlist eq "ARRAY" and not $hval->{"isconnecting"}
defined $dlist ref $dlist eq "ARRAY" not $hval->{"isconnecting"}
Truth table25%1/4
A and B and not(C)
A= defined $dlistB= ref $dlist eq "ARRAY"C= not $hval->{"isconnecting"}
ABCresult
0XX0
10X0
1100
1111
922 ref($dlist) eq 'ARRAY' and
923 !$hval->{'isconnecting'})
924 {
925 2 my $tryaddr;
926 2 foreach $tryaddr (@{$dlist}) {
927 2 $rval = _tryconnect($self, $tryaddr, $timeout);
928 2 ▶ $parms->{dstaddr} = $tryaddr if $rval;
Branch: 1 branch
BranchTrueFalseTotal
if $rval 2 0 2
929 last if $rval or
930 defined $timeout && !$timeout
931 2 ▶ and $connip{0+$!};
Branch: 1 branch
BranchTrueFalseTotal
if $rval or defined $timeout and not $timeout and $connip{0 + $!} 2 0 2
Condition11%1/9
$rval or defined $timeout and not $timeout and $connip{0 + $!}
l!l&&r!l&&!r
200
defined $timeout and not $timeout and $connip{0 + $!}
!ll&&!rl&&r
000
defined $timeout and not $timeout
!ll&&!rl&&r
000
MC/DC0%0/4
$rval or defined $timeout and not $timeout and $connip{0 + $!}
$rval defined $timeout not $timeout $connip{0 + $!}
Truth table20%1/5
A or B and not(C) and D
A= $rvalB= defined $timeoutC= not $timeoutD= $connip{0 + $!}
ABCDresult
1XXX1
01111
00XX0
010X0
01100
932 }
933 }
934 else {
935 0 $rval = _tryconnect($self, $parms->{dstaddr}, $timeout);
936 }
937 2 ▶ $error = $!+0 unless $rval;
Branch: 1 branch
BranchTrueFalseTotal
unless $rval 0 2 2
938 }
939 2 $hval->{'isconnected'} = $rval;
940 2 $hval->{'wasconnected'} = '0 but true';
941 2 ▶ if (!$rval) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rval) 0 2 2
942 0 $! = $error;
943 0 return $rval;
944 }
945 2 $self->getsockinfo;
946 2 $self->isconnected;
947 }
948  
949 #& getsockinfo($self, [@ignored]) : ?dest sockaddr?
950 sub getsockinfo
951 5 ▶{
Subroutine getsockinfo: called CC=7 SCAR=23.0
Pod documented
952 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
953 5 $_[0]->_trace(\@_,4);
954 5 my $self = shift;
955 5 my ($sad,$dad);
956  
957 5 ▶ $self->setparams({dstaddr => $dad}) if defined($dad = getpeername($self));
Branch: 1 branch
BranchTrueFalseTotal
if defined($dad = getpeername $self) 2 3 5
958 5 ▶ $self->setparams({srcaddr => $sad}) if defined($sad = getsockname($self));
Branch: 1 branch
BranchTrueFalseTotal
if defined($sad = getsockname $self) 5 0 5
959 wantarray ?
960 5 ▶ ((defined($sad) || defined($dad)) ? ($sad, $dad) : ()) :
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 5 5
defined $sad || defined $dad ? : 0 0 0
Condition16%1/6
defined $sad or defined $dad
l!l&&r!l&&!r
000
$sad and $dad
!ll&&!rl&&r
050
MC/DC0%0/2
defined $sad or defined $dad
defined $sad defined $dad
MC/DC0%0/2
$sad and $dad
$sad $dad
Truth table0%0/3
A or B
A= defined $sadB= defined $dad
ABresult
1X1
011
000
Truth table33%1/3
A and B
A= $sadB= $dad
ABresult
0X0
100
111
961 $sad && $dad;
962 }
963  
964 # 'static' hashes for translating between SHUT_* values and the traditional
965 # (but off-by-one) 1-3. Used for marking shutdown progress. The connect
966 # code helps in the conspiracy by setting '0 but true' rather than '0'.
967  
968 1 my %to_shut_flags = (SHUT_RD,1, SHUT_WR,2, SHUT_RDWR,3);
969  
970 #& shutdown($self [, $how=SHUT_RDWR]) : boolean
971 sub shutdown
972 5 ▶{
Subroutine shutdown: called CC=10 SCAR=25.6
Pod documented
973 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
974 5 $_[0]->_trace(\@_,3);
975 5 my $self = shift;
976 5 ▶ return 1 unless $self->isconnected or $self->isconnecting;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isconnected or $self->isconnecting 2 3 5
Condition66%2/3
$self->isconnected or $self->isconnecting
l!l&&r!l&&!r
302
MC/DC50%1/2
$self->isconnected or $self->isconnecting
$self->isconnected $self->isconnecting
Truth table66%2/3
A or B
A= $self->isconnectedB= $self->isconnecting
ABresult
1X1
011
000
977 3 my $how = shift;
978 3 ▶ $how = SHUT_RDWR unless defined $how and $how !~ m/\D/ and length $how;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $how and not $how =~ /\D/ and length $how 3 0 3
Condition33%2/6
defined $how and not $how =~ /\D/ and length $how
!ll&&!rl&&r
300
defined $how and not $how =~ /\D/
!ll&&!rl&&r
300
MC/DC0%0/3
defined $how and not $how =~ /\D/ and length $how
defined $how not $how =~ /\D/ length $how
Truth table25%1/4
A and not(B) and C
A= defined $howB= not $how =~ /\D/C= length $how
ABCresult
0XX0
10X0
1100
1111
979 3 $how += 0;
980 3 my $xhow = $to_shut_flags{$how};
981 3 ▶ ($how = SHUT_RDWR), ($xhow = 3)
Branch: 1 branch
BranchTrueFalseTotal
unless $xhow 0 3 3
982 unless $xhow;
983 3 my $was = ($ {*$self}{'wasconnected'} |= $xhow);
984 3 my $rval = CORE::shutdown($self, $how);
985 3 local $!; # preserve shutdown()'s errno
986 3 $ {*$self}{'isconnecting'} = $ {*$self}{'isconnected'} = 0 if
987 $was == 3 or
988 0 ▶ (!defined(getpeername($self)) && ($ {*$self}{'wasconnected'} = 3));
Branch: 1 branch
BranchTrueFalseTotal
if $was == 3 or not defined getpeername $self and do { *$self }->{"wasconnected"} = 3 3 0 3
Condition20%1/5
$was == 3 or not defined getpeername $self and do { *$self }->{"wasconnected"} = 3
l!l&&r!l&&!r
300
not defined getpeername $self and do { *$self }->{"wasconnected"} = 3
!ll
00
MC/DC0%0/2
$was == 3 or not defined getpeername $self and do { *$self }->{"wasconnected"} = 3
$was == 3 not defined getpeername $self
Truth table33%1/3
A or not(B)
A= $was == 3B= not defined getpeername $self
ABresult
1X1
011
000
989 3 $rval;
990 }
991  
992  
993 1 my @CloseVars = qw(FHVec isopen isbound didlisten wasconnected isconnected
994 isconnecting);
995 1 my @CloseKeys = qw(srcaddr dstaddr);
996  
997 #& close($self [, @ignored]) : boolean
998 sub close
999 5 ▶{
Subroutine close: called CC=2 SCAR=7.0
Pod documented
1000 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
1001 5 $_[0]->_trace(\@_,3);
1002 5 my $self = shift;
1003 5 ▶ $self->shutdown if $self->isopen;
Branch: 1 branch
BranchTrueFalseTotal
if $self->isopen 5 0 5
1004 5 $self->stopio;
1005 }
1006  
1007 sub CLOSE;
1008 1 *CLOSE = \&close;
1009  
1010 #& stopio($self [, @ignored]) : boolean
1011 sub stopio
1012 6 ▶{
Subroutine stopio: called CC=2 SCAR=6.9
Pod documented
1013 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
1014 6 $_[0]->_trace(\@_,4);
1015 6 my $self = shift;
1016 6 my $wasopen = $self->isopen;
1017 6 @{*$self}{@CloseVars} = (); # these flags no longer true
1018 6 $self->delparams(\@CloseKeys); # connection values now invalid
1019 6 ▶ return 1 unless $wasopen;
Branch: 1 branch
BranchTrueFalseTotal
unless $wasopen 1 5 6
1020 5 CORE::close($self);
1021 }
1022  
1023 # I/O enries
1024  
1025 # Warning! No intercepting of SIGPIPE is done, so the output routines
1026 # can abort the program.
1027  
1028 # Note that (at least) Solaris 2.5.1 doesn't like connect() on datagram
1029 # sockets, at least not if they're not bound. So, we fake it here.
1030  
1031 #& send($self, $buf, [$flags, [$where]]) : boolean
1032 sub send
1033 4 ▶{
Subroutine send: called CC=16 SCAR=35.3
Pod documented
1034 4 my $whoami = $_[0]->_trace(\@_,3);
1035 4 my($self,$buf,$flags,$whither) = @_;
1036 4 ▶ croak "Invalid args to ${whoami}, called"
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or not ref $self 0 4 4
Condition33%1/3
@_ < 2 or not ref $self
l!l&&r!l&&!r
004
MC/DC0%0/2
@_ < 2 or not ref $self
@_ < 2 not ref $self
Truth table33%1/3
A or not(B)
A= @_ < 2B= not ref $self
ABresult
1X1
011
000
1037 if @_ < 2 or !ref $self;
1038 4 ▶ $flags = 0 unless defined $flags;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags 4 0 4
1039 4 ▶ carp "Excess arguments to ${whoami} ignored" if @_ > 4;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 4 0 4 4
1040 # send(2) requires connect(2)
1041 4 ▶ if (!(defined $whither or $self->isconnected)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $whither || $self->isconnected) { } 1 3 4
elsif ($self->isconnected and do { *$self }->{'Parms'}{'netgen_fakeconnect'}) { } 1 2 3
Condition66%2/3
defined $whither || $self->isconnected
l!l&&r!l&&!r
031
MC/DC50%1/2
defined $whither || $self->isconnected
defined $whither $self->isconnected
Truth table66%2/3
A || B
A= defined $whitherB= $self->isconnected
ABresult
1X1
011
000
1042 1 ▶ if ($self->getparams([qw(dstaddrlist dstaddr)],1) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getparams(['dstaddrlist', 'dstaddr'], 1) > 0) { } 0 1 1
1043 0 ▶ return undef unless $self->connect;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->connect 0 0 0
1044 0 ▶ if ($ {*$self}{Parms}{netgen_fakeconnect}) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{"Parms"}{"netgen_fakeconnect"}) 0 0 0
1045 0 $whither = $ {*$self}{Parms}{'dstaddr'};
1046 }
1047 }
1048 else {
1049 1 ▶ if ($flags & MSG_OOB) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & 1) { } 0 1 1
1050 0 $whither = $ {*$self}{lastOOBFrom};
1051 }
1052 else {
1053 1 $whither = $ {*$self}{lastRegFrom};
1054 }
1055 # Can't short-circuit this--need to get the right errno value.
1056 # return undef unless defined $whither or $self->connect;
1057 }
1058 }
1059 3 ▶ elsif ($self->isconnected && $ {*$self}{Parms}{netgen_fakeconnect}) {
Condition66%2/3
$self->isconnected and do { *$self }->{"Parms"}{"netgen_fakeconnect"}
!ll&&!rl&&r
021
MC/DC50%1/2
$self->isconnected and do { *$self }->{"Parms"}{"netgen_fakeconnect"}
$self->isconnected do { *$self }->{"Parms"}{"netgen_fakeconnect"}
Truth table66%2/3
A and B
A= $self->isconnectedB= do { *$self }->{"Parms"}{"netgen_fakeconnect"}
ABresult
0X0
100
111
1060 1 ▶ if (defined $whither) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $whither) 0 1 1
1061 # *sigh* -- what errno should I return?
1062 0 $! = EISCONN || EINVAL;
1063 0 return undef;
1064 }
1065 1 $whither = $ {*$self}{Parms}{'dstaddr'};
1066 }
1067 4 ▶ return getsockopt($self,SOL_SOCKET,SO_TYPE) unless
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isopen 0 4 4
1068 $self->isopen; # generate EBADF return if not open
1069 4 ▶ defined $whither
Branch: 1 branch
BranchTrueFalseTotal
defined $whither ? : 2 2 4
1070 ? CORE::send($self, $buf, $flags, $whither)
1071 : CORE::send($self, $buf, $flags);
1072 }
1073  
1074 sub SEND;
1075 1 *SEND = \&send;
1076  
1077 #& put($self, @stuff) : boolean
1078 sub put
1079 0 ▶{
Subroutine put: not called CC=1 SCAR=6.9
Pod documented
1080 0 $_[0]->_trace(\@_,3);
1081 0 my($self,@args) = @_;
1082 0 print {$self} @args;
1083 }
1084  
1085 sub PRINT; # avoid -w error
1086 1 *PRINT = \&put; # alias that may someday be used for tied FH
1087 sub print; # avoid -w error
1088 3 *print = \&put; # maybe-useful alias
1089  
1090 #& ckeof($self) : boolean
1091 sub ckeof
1092 0 ▶{
Subroutine ckeof: not called CC=8 SCAR=40.0
Pod documented
1093 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
1094 0 my $saverr = $!+0;
1095 0 local $!; # preserve this over fcntl() and such
1096 0 my $whoami = $_[0]->_trace(\@_,3);
1097 0 my($self) = @_;
1098 0 ▶ croak "Invalid args to ${whoami}, called"
Branch: 1 branch
BranchTrueFalseTotal
unless @_ and ref $self 0 0 0
Condition0%0/3
@_ and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and ref $self
@_ ref $self
Truth table0%0/3
A and B
A= @_B= ref $self
ABresult
0X0
100
111
1099 if !@_ or !ref $self;
1100 # Bug out if we shouldn't have been called.
1101 0 return 1 if EOF_NONBLOCK or $saverr != $eagain;
1102 # Bug out early if not a socket where EOF is possible.
1103 0 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless unpack("I", getsockopt($self, 1, 3)) == 1 0 0 0
1104 unless unpack('I',getsockopt($self,SOL_SOCKET,SO_TYPE)) == SOCK_STREAM;
1105 # See whether need to test for non-blocking status.
1106 0 ▶ my $flags = ($F_GETFL ? CORE::fcntl($self,$F_GETFL,0+0) : undef);
Branch: 1 branch
BranchTrueFalseTotal
$F_GETFL ? : 0 0 0
1107 0 ▶ if ((defined($flags) && defined($nonblock_flag))
Branch: 2 branches
BranchTrueFalseTotal
if (defined $flags && defined $nonblock_flag ? $flags & 2048 : 1) 0 0 0
defined $flags && defined $nonblock_flag ? : 0 0 0
Condition0%0/3
defined $flags and defined $nonblock_flag
!ll&&!rl&&r
000
MC/DC0%0/2
defined $flags and defined $nonblock_flag
defined $flags defined $nonblock_flag
Truth table0%0/3
A and B
A= defined $flagsB= defined $nonblock_flag
ABresult
0X0
100
111
1108 ? ($flags & VAL_O_NONBLOCK)
1109 : 1)
1110 {
1111 # *sigh* -- no way to tell, here
1112 0 return 0;
1113 }
1114 0 1; # wrong errno or blocking
1115 }
1116  
1117 #& recv($self, [$maxlen, [$flags, [$from]]]) : {$buf | undef}
1118 sub recv
1119 3 ▶{
Subroutine recv: called CC=26 SCAR=45.5
Pod documented
1120 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
1121 3 my $whoami = $_[0]->_trace(\@_,3);
1122 3 my($self,$maxlen,$flags) = @_;
1123 3 my($buf,$from,$xfrom) = '';
1124 3 ▶ croak "Invalid args to ${whoami}, called"
Branch: 1 branch
BranchTrueFalseTotal
unless @_ and ref $self 0 3 3
Condition33%1/3
@_ and ref $self
!ll&&!rl&&r
003
MC/DC0%0/2
@_ and ref $self
@_ ref $self
Truth table33%1/3
A and B
A= @_B= ref $self
ABresult
0X0
100
111
1125 if !@_ or !ref $self;
1126 3 ▶ carp "Excess arguments to ${whoami} ignored"
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 4 0 3 3
1127 if @_ > 4;
1128 3 ▶ return getsockopt($self,SOL_SOCKET,SO_TYPE) unless
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isopen or $self->open 0 3 3
Condition33%1/3
$self->isopen or $self->open
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->isopen or $self->open
$self->isopen $self->open
Truth table33%1/3
A or B
A= $self->isopenB= $self->open
ABresult
1X1
011
000
1129 $self->isopen or $self->open; # generate EBADF return if not open
1130 3 ▶ $maxlen = unpack('I',getsockopt($self,SOL_SOCKET,SO_RCVBUF)) ||
Branch: 1 branch
BranchTrueFalseTotal
unless $maxlen 2 1 3
Condition40%2/5
unpack('I', getsockopt($self, 1, 8)) || (stat $self)[11] || 8192
l!l
20
unpack "I", getsockopt($self, 1, 8) or (stat $self)[11]
l!l&&r!l&&!r
200
MC/DC0%0/2
unpack('I', getsockopt($self, 1, 8)) || (stat $self)[11] || 8192
unpack "I", getsockopt($self, 1, 8) (stat $self)[11]
Truth table33%1/3
A or B
A= unpack "I", getsockopt($self, 1, 8)B= (stat $self)[11]
ABresult
1X1
011
000
1131 (stat $self)[11] || 8192
1132 unless $maxlen;
1133 3 ▶ $flags = 0 unless defined $flags;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags 3 0 3
1134 3 ▶ if (defined($ {*$self}{sockLineBuf}) && !$flags) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined do { *$self }->{"sockLineBuf"} and not $flags) 0 3 3
Condition33%1/3
defined do { *$self }->{"sockLineBuf"} and not $flags
!ll&&!rl&&r
300
MC/DC0%0/2
defined do { *$self }->{"sockLineBuf"} and not $flags
defined do { *$self }->{"sockLineBuf"} not $flags
Truth table33%1/3
A and not(B)
A= defined do { *$self }->{"sockLineBuf"}B= not $flags
ABresult
0X0
100
111
1135 0 $buf = $ {*$self}{sockLineBuf};
1136 0 ▶ if (length($buf) > $maxlen) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $buf > $maxlen) { } 0 0 0
1137 0 $ {*$self}{sockLineBuf} = substr($buf, $maxlen);
1138 0 substr($buf, $maxlen) = '';
1139 }
1140 else {
1141 0 undef $ {*$self}{sockLineBuf};
1142 }
1143 0 ▶ $_[3] = $ {*$self}{lastRegFrom} if @_ > 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 3 0 0 0
1144 0 return $buf;
1145 }
1146 3 $! = 0; # ease EOF checking
1147 3 $xfrom = $from = CORE::recv($self,$buf,$maxlen,$flags);
1148 3 my $errnum = $!+0; # preserve possible recv failure
1149 3 ▶ $xfrom = getpeername($self) if defined($from) and $from eq '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $from and $from eq "" 2 1 3
Condition66%2/3
defined $from and $from eq ""
!ll&&!rl&&r
012
MC/DC50%1/2
defined $from and $from eq ""
defined $from $from eq ""
Truth table66%2/3
A and B
A= defined $fromB= $from eq ""
ABresult
0X0
100
111
1150 3 ▶ $from = $xfrom if defined($xfrom) and $from eq '' and $xfrom ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $xfrom and $from eq "" and $xfrom ne "" 1 2 3
Condition83%5/6
defined $xfrom and $from eq "" and $xfrom ne ""
!ll&&!rl&&r
201
defined $xfrom and $from eq ""
!ll&&!rl&&r
111
MC/DC66%2/3
defined $xfrom and $from eq "" and $xfrom ne ""
defined $xfrom $from eq "" $xfrom ne ""
Truth table75%3/4
A and B and C
A= defined $xfromB= $from eq ""C= $xfrom ne ""
ABCresult
0XX0
10X0
1100
1111
1151 3 $ {*$self}{lastFrom} = $from;
1152 3 ▶ $_[3] = $from if @_ > 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 3 0 3 3
1153 3 ▶ if ($flags & MSG_OOB) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & 1) { } 0 3 3
1154 0 $ {*$self}{lastOOBFrom} = $from;
1155 }
1156 else {
1157 3 $ {*$self}{lastRegFrom} = $from;
1158 }
1159 3 $! = $errnum; # restore possible failure in case we return
1160 3 ▶ return undef if !defined $from and (EOF_NONBLOCK or $errnum != $eagain);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $from and 1 0 3 3
Condition50%1/2
not defined $from and 1
!ll
30
MC/DC0%0/1
not defined $from and 1
not defined $from
Truth table50%1/2
not(A)
A= not defined $from
Aresult
00
11
1161 3 ▶ return $buf if length $buf;
Branch: 1 branch
BranchTrueFalseTotal
if length $buf 3 0 3
1162 # At this point, we had a 0-length read with no error (or EAGAIN).
1163 # Especially for a SOCK_STREAM connection, this may mean EOF.
1164 0 $! = $errnum; # restore possible failure just in case
1165 0 ▶ unless ($self->ckeof) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->ckeof) 0 0 0
1166 0 ▶ return defined($from) ? $buf : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $from ? : 0 0 0
1167 }
1168 0 $self->shutdown(SHUT_RD); # make sure I know about this EOF
1169 0 $! = 0; # no error for EOF
1170 0 undef; # no buffer, either, though
1171 }
1172  
1173 sub get; # (helps with -w)
1174 3 *get = \&recv; # a name that works for indirect references
1175  
1176 #& getline($self) : like scalar(<$fhandle>)
1177 sub getline
1178 2 ▶{
Subroutine getline: called CC=17 SCAR=36.6
Pod documented
1179 2 ▶ use attrs qw(locked method);
Subroutine BEGIN: called CC=1 SCAR=0.0
1180 2 my $whoami = $_[0]->_trace(\@_,4);
1181 2 ▶ carp "Excess arguments to ${whoami} ignored"
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 2 2
1182 if @_ > 1;
1183 2 my ($self) = @_;
1184 2 ▶ croak "Invalid arguments to ${whoami}, called"
Branch: 1 branch
BranchTrueFalseTotal
unless @_ and ref $self 0 2 2
Condition33%1/3
@_ and ref $self
!ll&&!rl&&r
002
MC/DC0%0/2
@_ and ref $self
@_ ref $self
Truth table33%1/3
A and B
A= @_B= ref $self
ABresult
0X0
100
111
1185 if !@_ or !ref($self);
1186 2 my ($rval, $buf, $tbuf);
1187 2 $buf = $ {*$self}{sockLineBuf};
1188 2 undef $ {*$self}{sockLineBuf}; # keep get from returning this again
1189 2 ▶ if (!defined($/)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $/) 0 2 2
1190 0 $rval = <$self>; # return all of the input
1191 # what about non-blocking sockets here?!?
1192 # $self->shutdown(SHUT_RD); # keep track of EOF
1193 # Above removed because ->recv does it on real EOF already.
1194 0 ▶ if (defined($buf) and defined($rval)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buf and defined $rval) 0 0 0
Condition0%0/3
defined $buf and defined $rval
!ll&&!rl&&r
000
MC/DC0%0/2
defined $buf and defined $rval
defined $buf defined $rval
Truth table0%0/3
A and B
A= defined $bufB= defined $rval
ABresult
0X0
100
111
1195 0 return $buf . $rval
1196 }
1197 0 ▶ if (defined($buf)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buf) 0 0 0
1198 0 return $buf
1199 }
1200 0 return $rval
1201 }
1202 2 my $sep = $/; # get the current separator
1203 2 ▶ $sep = "\n\n" if $sep eq ''; # account for paragraph mode
Branch: 1 branch
BranchTrueFalseTotal
if $sep eq "" 0 2 2
1204 2 ▶ while (!defined($buf) or $buf !~ /\Q$sep/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $buf and $buf =~ /\Q$sep\E/) 2 2 4
Condition66%2/3
defined $buf and $buf =~ /\Q$sep\E/
!ll&&!rl&&r
202
MC/DC50%1/2
defined $buf and $buf =~ /\Q$sep\E/
defined $buf $buf =~ /\Q$sep\E/
Truth table66%2/3
A and B
A= defined $bufB= $buf =~ /\Q$sep\E/
ABresult
0X0
100
111
1205 2 $rval = $self->get;
1206 2 ▶ last unless defined $rval;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rval 0 2 2
1207 2 ▶ if (defined $buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buf) { } 0 2 2
1208 0 $buf .= $rval;
1209 }
1210 else {
1211 2 $buf = $rval;
1212 }
1213 }
1214 2 ▶ if (defined($buf) and ($tbuf = index($buf, $sep)) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buf and ($tbuf = index($buf, $sep)) >= 0) { } 2 0 2
Condition33%1/3
defined $buf and ($tbuf = index($buf, $sep)) >= 0
!ll&&!rl&&r
002
MC/DC0%0/2
defined $buf and ($tbuf = index($buf, $sep)) >= 0
defined $buf ($tbuf = index($buf, $sep)) >= 0
Truth table33%1/3
A and B
A= defined $bufB= ($tbuf = index($buf, $sep)) >= 0
ABresult
0X0
100
111
1215 2 $rval = substr($buf, 0, $tbuf + length($sep));
1216 2 $tbuf = substr($buf, length($rval));
1217 # duplicate annoyance of paragraph mode
1218 2 ▶ $tbuf =~ s/^\n+//s if $/ eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $/ eq "" 0 2 2
1219 0 ▶ $ {*$self}{sockLineBuf} = $tbuf if length($tbuf);
Branch: 1 branch
BranchTrueFalseTotal
if length $tbuf 0 2 2
1220 2 return $rval;
1221 }
1222 else {
1223 0 return $buf;
1224 }
1225 }
1226  
1227 sub gets; # an alias for FileHandle:: or POSIX:: compat.
1228 3 *gets = \&getline;
1229  
1230 sub DESTROY
1231 5 ▶{
Subroutine DESTROY: called CC=1 SCAR=0.0
1232 5 $_[0]->_trace(\@_,1);
1233 }
1234  
1235 #& isopen($self [, @ignored]) : boolean
1236 sub isopen
1237 49 ▶{
Subroutine isopen: called CC=1 SCAR=0.0
Pod documented
1238 #$_[0]->_trace(\@_,4," - ".($ {*{$_[0]}}{'isopen'} ? "yes" : "no"));
1239 49 $ {*{$_[0]}}{'isopen'};
1240 }
1241  
1242 #& isconnected($self [, @ignored]) : boolean
1243 sub isconnected
1244 20 ▶{
Subroutine isconnected: called CC=1 SCAR=0.0
Pod documented
1245 #$_[0]->_trace(\@_,4," - ".($ {*{$_[0]}}{'isconnected'} ? "yes" : "no"));
1246 20 $ {*{$_[0]}}{'isconnected'};
1247 }
1248  
1249 #& isconnecting($self [, @ignored]) : boolean
1250 sub isconnecting
1251 4 ▶{
Subroutine isconnecting: called CC=1 SCAR=0.0
Pod documented
1252 #$_[0]->_trace(\@_,4," - ".($ {*{$_[0]}}{'isconnecting'} ? "yes" : "no"));
1253 4 $ {*{$_[0]}}{'isconnecting'};
1254 }
1255  
1256 #& wasconnected($self [, @ignored]) : boolean
1257 sub wasconnected
1258 2 ▶{
Subroutine wasconnected: called CC=1 SCAR=0.0
Pod documented
1259 #$_[0]->_trace(\@_,4," - ".($ {*{$_[0]}}{'wasconnected'} ? "yes" : "no"));
1260 2 $ {*{$_[0]}}{'wasconnected'};
1261 }
1262  
1263 #& isbound($self [, @ignored]) : boolean
1264 sub isbound
1265 13 ▶{
Subroutine isbound: called CC=1 SCAR=0.0
Pod documented
1266 #$_[0]->_trace(\@_,4," - ".($ {*{$_[0]}}{'isbound'} ? "yes" : "no"));
1267 13 $ {*{$_[0]}}{'isbound'};
1268 }
1269  
1270 3 1;
1271  
1272 # autoloaded methods go after the END clause (& pod) below
1273  
1274 __END__
« blib/lib/Net/TCP.pm ↑ Summary blib/lib/Net/UNIX.pm »