Event.pm

filter: Statementstmt 51.5% 485 / 941 Branchbran 40.0% 161 / 402 Conditioncond 37.4% 49 / 131 MC/DCmcdc 25.6% 21 / 82 Subroutinesub 69.7% 60 / 86 Podpod 16.6% 1 / 6 totaltotal 47.1% 777 / 1648 CC 250 SCAR 40.2
CC
250
Cov
47%
ie_dispatch_write
420.0
AUTOLOAD
240.0
ie_dispatch_exception
90.0
CRAP 55.7
↑ Summary Event/Emulate.pm »
1  
2 60 our $debug = 0;
3 60 our $edebug = 0;
4 60 our $sdebug = 0;
5  
6 {
7 package IO::Event;
8  
9 60 our $VERSION = 0.813;
10  
11 60 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 60 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 60 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 60 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 60 our $base;
17 60 our @ISA;
18  
19 sub idle
20 3 ▶{
Subroutine idle: called CC=2 SCAR=7.1
Pod undocumented
21 3 ▶ IO::Event->import('no_emulate_Event') unless $base;
Branch: 1 branch
BranchTrueFalseTotal
unless $IO::Event::base 0 3 3
22 3 &{$base . "::idle"}(@_);
23 }
24  
25 sub loop
26 12 ▶{
Subroutine loop: called CC=2 SCAR=7.1
Pod undocumented
27 12 ▶ IO::Event->import('no_emulate_Event') unless $base;
Branch: 1 branch
BranchTrueFalseTotal
unless $IO::Event::base 0 12 12
28 12 &{$base . "::loop"}(@_);
29 }
30  
31 sub unloop
32 0 ▶{
Subroutine unloop: not called CC=1 SCAR=6.9
Pod undocumented
33 0 &{$base . "::unloop"}(@_);
34 }
35  
36 sub unloop_all
37 5 ▶{
Subroutine unloop_all: called CC=1 SCAR=0.0
Pod undocumented
38 5 &{$base . "::unloop_all"}(@_);
39 }
40  
41 sub timer
42 9 ▶{
Subroutine timer: called CC=2 SCAR=7.1
Pod undocumented
43 9 shift;
44 9 ▶ IO::Event->import('no_emulate_Event') unless $base;
Branch: 1 branch
BranchTrueFalseTotal
unless $IO::Event::base 0 9 9
45 9 $base->timer(@_);
46 }
47  
48 sub new
49 585 ▶{
Subroutine new: called CC=2 SCAR=6.9
Pod documented
50 585 ▶ IO::Event->import('no_emulate_Event') unless $base;
Branch: 1 branch
BranchTrueFalseTotal
unless $IO::Event::base 18 567 585
51 585 &{$base . "::new"}(@_);
52 }
53  
54 sub import
55 138 ▶{
Subroutine import: called CC=5 SCAR=16.1
56 138 my ($pkg, @stuff) = @_;
57 138 for my $s (@stuff) {
58 58 ▶ if ($s eq 'emulate_Event') {
Branch: 3 branches
BranchTrueFalseTotal
if ($s eq 'emulate_Event') { } 20 38 58
elsif ($s eq 'no_emulate_Event') { } 18 20 38
elsif ($s eq 'AnyEvent') { } 20 0 20
59 20 $base = 'IO::Event::Emulate';
60 20 require IO::Event::Emulate;
61 } elsif ($s eq 'no_emulate_Event') {
62 18 require Event;
63 18 require IO::Event::Event;
64 18 $base = 'IO::Event::Event';
65 } elsif ($s eq 'AnyEvent') {
66 20 require AnyEvent;
67 20 require IO::Event::AnyEvent;
68 20 $base = 'IO::Event::AnyEvent';
69 } else {
70 0 die "unknown import: $s";
71 }
72 58 @ISA = $base;
73 }
74 138 return 1;
75 }
76  
77 sub AUTOLOAD
78 0 ▶{
Subroutine AUTOLOAD: not called CC=15 SCAR=54.8
79 0 my $self = shift;
80 0 our $AUTOLOAD;
81 0 my $a = $AUTOLOAD;
82 0 $a =~ s/.*:://;
83
84 # for whatever reason, UNIVERSAL::can()
85 # doesn't seem to work on some filehandles
86  
87 0 my $r;
88 my @r;
89 0 my $fh = ${*$self}{ie_fh};
90 0 ▶ if ($fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) { } 0 0 0
91 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
92 0 eval { @r = $fh->$a(@_) };
93 } else {
94 0 eval { $r = $fh->$a(@_) };
95 }
96 0 ▶ if ($@ && $@ =~ /Can't locate object method "(.*?)" via package/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ and $@ =~ /Can't locate object method "(.*?)" via package/) 0 0 0
Condition0%0/3
$@ and $@ =~ /Can't locate object method "(.*?)" via package/
!ll&&!rl&&r
000
MC/DC0%0/2
$@ and $@ =~ /Can't locate object method "(.*?)" via package/
$@ $@ =~ /Can't locate object method "(.*?)" via package/
Truth table0%0/3
A and B
A= $@B= $@ =~ /Can't locate object method "(.*?)" via package/
ABresult
0X0
100
111
97 0 my $event = ${*$self}{ie_event};
98 0 ▶ if ($1 ne $a) {
Branch: 2 branches
BranchTrueFalseTotal
if ($1 ne $a) { } 0 0 0
elsif ($event and $event->can($a)) { } 0 0 0
99 # nothing to do
100 ▶ } elsif ($event && $event->can($a)) {
Condition0%0/3
$event and $event->can($a)
!ll&&!rl&&r
000
MC/DC0%0/2
$event and $event->can($a)
$event $event->can($a)
Truth table0%0/3
A and B
A= $eventB= $event->can($a)
ABresult
0X0
100
111
101 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
102 0 eval { @r = $event->$a(@_) };
103 } else {
104 0 eval { $r = $event->$a(@_) };
105 }
106 } else {
107 0 ▶ confess qq{Can't locate object method "$a" via "@{[ ref($self) ]}", "@{[ ref($fh)||'IO::Handle' ]}", or "@{[ ref($event) ]}"};
Condition0%0/2
ref $fh || 'IO::Handle'
l!l
00
MC/DC0%0/1
ref $fh || 'IO::Handle'
ref $fh
Truth table0%0/2
A
A= ref $fh
Aresult
11
00
108 }
109 }
110 } else {
111 0 my $event = ${*$self}{ie_event};
112 0 ▶ if ($event && $event->can($a)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event and $event->can($a)) { } 0 0 0
Condition0%0/3
$event and $event->can($a)
!ll&&!rl&&r
000
MC/DC0%0/2
$event and $event->can($a)
$event $event->can($a)
Truth table0%0/3
A and B
A= $eventB= $event->can($a)
ABresult
0X0
100
111
113 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
114 0 eval { @r = $event->$a(@_) };
115 } else {
116 0 eval { $r = $event->$a(@_) };
117 }
118 } else {
119 0 confess qq{Can't locate object method "$a" via "@{[ ref($self) ]}" or "@{[ ref($event) ]}"};
120 }
121 }
122 0 ▶ confess $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
123 0 ▶ return @r if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
124 0 return $r;
125 }
126  
127 60 }{package IO::Event::Common;
128  
129 60 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
130 60 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
131 60 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
132 60 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
133 60 require IO::Handle;
134 60 ▶use POSIX qw(BUFSIZ EAGAIN EBADF EINVAL ETIMEDOUT);
Subroutine BEGIN: called CC=1 SCAR=0.0
135 60 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
136 60 ▶use Scalar::Util qw(weaken reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
137 60 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
138  
139 60 our $in_callback = 0;
140  
141 60 my %fh_table;
142 my %rxcache;
143  
144 60 my @pending_callbacks;
145  
146 sub display_bits
147 0 ▶{
Subroutine display_bits: not called CC=1 SCAR=6.9
148 0 print STDERR unpack("b*", $_[0]);
149 }
150  
151 sub count_bits
152 0 ▶{
Subroutine count_bits: not called CC=1 SCAR=6.9
153 0 scalar(grep { $_ } split(//, unpack("b*", $_[0])));
154 }
155  
156 sub display_want
157 0 ▶{
Subroutine display_want: not called CC=2 SCAR=17.9
158 0 my ($name, $vec, %hash) = @_;
159 0 my ($pkg, $file, $line) = caller;
160 0 print STDERR "\n\nAT $file: $line\n";
161 0 print STDERR "$name\n";
162 0 for my $ioe (values %hash) {
163 0 printf STDERR "%03d-", fileno(${*$ioe}{ie_fh});
164 # display_bits(${*$ioe}{ie_vec});
165 0 print STDERR "\n";
166 }
167 0 print STDERR "----------";
168 0 display_bits($vec);
169 0 printf STDERR " - %d\n", count_bits($vec);
170 0 print STDERR scalar(keys(%hash));
171 0 print STDERR "\n";
172 0 exit 1;
173 }
174  
175 60 my $counter = 1;
176  
177 sub new
178 585 ▶{
Subroutine new: called CC=8 SCAR=21.2
179 585 my ($pkg, $fh, $handler, $options) = @_;
180  
181 # stolen from IO::Handle
182 585 my $self = bless gensym(), $pkg;
183  
184 585 ▶ $handler = (caller(2))[0]
Branch: 1 branch
BranchTrueFalseTotal
unless $handler 3 582 585
185 unless $handler;
186  
187 585 ▶ confess unless ref $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $fh 0 585 585
188  
189 585 ▶ unless (ref $options) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $options) 585 0 585
190 585 $options = {
191 description => $options,
192 };
193 }
194  
195 # some bits stolen from IO::Socket
196 585 ${*$self}{ie_fh} = $fh;
197 585 ${*$self}{ie_handler} = $handler;
198 585 ${*$self}{ie_ibuf} = '';
199 585 ${*$self}{ie_obuf} = '';
200 585 ${*$self}{ie_obufsize} = BUFSIZ*4;
201 585 ${*$self}{ie_autoread} = 1;
202 585 ${*$self}{ie_pending} = {};
203 585 ▶ ${*$self}{ie_desc} = $options->{description} || "wrapper for $fh";
Condition100%2/2
$options->{'description'} || "wrapper for $fh"
l!l
5823
MC/DC100%1/1
$options->{'description'} || "wrapper for $fh"
$options->{'description'}
Truth table100%2/2
A
A= $options->{'description'}
Aresult
11
00
204 585 ▶ ${*$self}{ie_writeclosed} = EINVAL if $options->{read_only};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"read_only"} 0 585 585
205 585 ▶ ${*$self}{ie_readclosed} = EINVAL if $options->{write_only};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"write_only"} 0 585 585
206  
207 585 $self->ie_register();
208 585 $fh->blocking(0);
209 585 ▶ print "New IO::Event: ${*$self}{ie_desc} - now nonblocking\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $T::debug 0 585 585
210
211 # stolen from IO::Multiplex
212 585 tie(*$self, $pkg, $self);
213 585 return $self;
214 }
215  
216 sub reset
217 0 ▶{
Subroutine reset: not called CC=1 SCAR=6.9
218 0 my $self = shift;
219 0 delete ${*$self}{ie_writeclosed};
220 0 delete ${*$self}{ie_readclosed};
221 0 delete ${*$self}{ie_eofinvoked};
222 0 delete ${*$self}{ie_overflowinvoked};
223 }
224  
225 # mark as listener
226 sub listener
227 12 ▶{
Subroutine listener: called CC=2 SCAR=7.0
228 12 my ($self, $listener) = @_;
229 12 ▶ $listener = 1 unless defined $listener;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $listener 0 12 12
230 12 my $o = ${*$self}{ie_listener};
231 12 ${*$self}{ie_listener} = $listener;
232 12 return $o;
233 }
234  
235 # call out
236 sub ie_invoke
237 922 ▶{
Subroutine ie_invoke: called CC=7 SCAR=19.8
238 922 my ($self, $required, $method, @args) = @_;
239  
240 922 ▶ if ($in_callback && ! ${*$self}->{ie_reentrant}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($IO::Event::Common::in_callback and not ${*$self;}->{"ie_reentrant"}) 57 865 922
Condition66%2/3
$IO::Event::Common::in_callback and not ${*$self;}->{"ie_reentrant"}
!ll&&!rl&&r
865057
MC/DC50%1/2
$IO::Event::Common::in_callback and not ${*$self;}->{"ie_reentrant"}
$IO::Event::Common::in_callback not ${*$self;}->{"ie_reentrant"}
Truth table66%2/3
A and not(B)
A= $IO::Event::Common::in_callbackB= not ${*$self;}->{"ie_reentrant"}
ABresult
0X0
100
111
241 # we'll do this later
242 push(@pending_callbacks, [ $self, $required, $method, @args ])
243 57 ▶ unless exists ${*$self}{ie_pending}{$method};
Branch: 1 branch
BranchTrueFalseTotal
unless exists do { *$self }->{"ie_pending"}{$method} 57 0 57
244 57 ${*$self}{ie_pending}{$method} = 1; # prevent double invocation. needed?
245 57 ▶ print STDERR "Delaying invocation of $method on ${*$self}{ie_desc} because we're already in a callback\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $T::debug 0 57 57
246 57 return;
247 }
248  
249 865 local($in_callback) = 1;
250  
251 865 $self->ie_do_invoke($required, $method, @args);
252  
253 859 ▶ while (@pending_callbacks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pending_callbacks) 57 859 916
254 57 my ($ie, $req, $meth, @a) = @{shift @pending_callbacks};
255 57 delete ${*$ie}{ie_pending}{$meth};
256 57 ▶ print STDERR "Processing delayed invocation of $meth on ${*$ie}{ie_desc}\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $T::debug 0 57 57
257 57 $ie->ie_do_invoke($req, $meth, @a);
258 }
259 859 return;
260 }
261  
262 sub ie_do_invoke
263 922 ▶{
Subroutine ie_do_invoke: called CC=8 SCAR=29.3
264 922 my ($self, $required, $method, @args) = @_;
265  
266 922 ▶ print STDERR "invoking ${*$self}{ie_fileno} ${*$self}{ie_handler}->$method\n"
Branch: 1 branch
BranchTrueFalseTotal
if $T::debug 0 922 922
267 if $debug;
268  
269 922 ▶ return if ! $required && ! ${*$self}{ie_handler}->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $required or do { *$self }->{"ie_handler"}->can($method) 0 922 922
Condition66%2/3
$required or do { *$self }->{"ie_handler"}->can($method)
l!l&&r!l&&!r
6842380
MC/DC0%0/2
$required or do { *$self }->{"ie_handler"}->can($method)
$required do { *$self }->{"ie_handler"}->can($method)
Truth table66%2/3
A or B
A= $requiredB= do { *$self }->{"ie_handler"}->can($method)
ABresult
1X1
011
000
270 922 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T::debug) 0 922 922
271 0 my ($pkg, $line, $func) = caller();
272 0 print "DISPATCHING $method on ${*$self}{ie_desc} from $func at line $line\n";
273 }
274 922 eval {
275 922 ${*$self}{ie_handler}->$method($self, @args);
276 };
277  
278 916 ▶ print STDERR "return from ${*$self}{ie_fileno} ${*$self}{ie_handler}->$method handler: $@\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $T::debug 0 916 916
279  
280 916 ▶ return unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 916 0 916
281 0 ▶ if (${*$self}{ie_handler}->can('ie_died')) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{'ie_handler'}->can('ie_died')) { } 0 0 0
282 0 ${*$self}{ie_handler}->ie_died($self, $method, $@);
283 } else {
284 0 confess $@;
285 0 exit 1;
286 }
287  
288 }
289  
290 #
291 # we use a single event handler so that the AUTOLOAD
292 # function can try a single $event object when looking for
293 # methods
294 #
295 sub ie_dispatch
296 235 ▶{
Subroutine ie_dispatch: called CC=8 SCAR=23.9
297 235 ▶ print STDERR "D" if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $T::sdebug 0 235 235
298 235 my ($self, $ievent) = @_;
299 235 my $fh = ${*$self}{ie_fh};
300 235 my $got = $ievent->got;
301 {
302 235 ▶ if ($got & Event::Watcher::R()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got & 1) 235 0 235
303 235 ▶ last if $self->ie_dispatch_read($fh);
Branch: 1 branch
BranchTrueFalseTotal
if $self->ie_dispatch_read($fh) 35 198 233
304 }
305 198 ▶ if ($got & Event::Watcher::W()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got & 2) 0 198 198
306 0 ▶ last if $self->ie_dispatch_write($fh);
Branch: 1 branch
BranchTrueFalseTotal
if $self->ie_dispatch_write($fh) 0 0 0
307 }
308 198 ▶ if ($got & Event::Watcher::E()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got & 4) 0 198 198
309 0 $self->ie_dispatch_exception($fh);
310 }
311 198 ▶ if ($got & Event::Watcher::T()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got & 8) 0 198 198
312 0 $self->ie_dispatch_timer();
313 }
314 }
315 }
316  
317  
318 sub ie_dispatch_read
319 717 ▶{
Subroutine ie_dispatch_read: called CC=6 SCAR=18.2
320 717 my ($self, $fh) = @_;
321 717 ▶ printf STDERR "R%d", $self->fileno if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $T::sdebug 0 717 717
322 717 ▶ if (${*$self}{ie_listener}) {
Branch: 2 branches
BranchTrueFalseTotal
if (do { *$self }->{'ie_listener'}) { } 144 573 717
elsif (do { *$self }->{'ie_autoread'}) { } 573 0 573
323 144 $self->ie_invoke(1, 'ie_connection');
324 573 } elsif (${*$self}{ie_autoread}) {
325 573 $self->ie_input();
326 } else {
327 0 $self->ie_invoke(1, 'ie_read_ready', $fh);
328 }
329 711 ▶ return 1 if ${*$self}{ie_writeclosed} && ${*$self}{ie_readclosed};
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"} 112 599 711
Condition66%2/3
do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"}
!ll&&!rl&&r
5990112
MC/DC50%1/2
do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"}
do { *$self }->{"ie_writeclosed"} do { *$self }->{"ie_readclosed"}
Truth table66%2/3
A and B
A= do { *$self }->{"ie_writeclosed"}B= do { *$self }->{"ie_readclosed"}
ABresult
0X0
100
111
330 599 return 0;
331 }
332  
333 sub ie_dispatch_write
334 0 ▶{
Subroutine ie_dispatch_write: not called CC=20 SCAR=60.4
335 0 my ($self, $fh) = @_;
336 0 ▶ printf STDERR "W%d", $self->fileno if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $T::sdebug 0 0 0
337 0 ▶ if (${*$self}{ie_connecting}) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{'ie_connecting'}) { } 0 0 0
338 0 $self->writeevents(0);
339 0 delete ${*$self}{ie_connecting};
340 0 delete ${*$self}{ie_connect_timeout};
341 0 $self->ie_invoke(0, 'ie_connected');
342 } else {
343 0 my $obuf = \${*$self}{ie_obuf};
344 0 my $rv;
345 0 ▶ if (length($$obuf)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$obuf) 0 0 0
346 0 $rv = syswrite($fh, $$obuf);
347 0 ▶ if (defined $rv) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $rv) { } 0 0 0
elsif ($! == 11) { } 0 0 0
348 0 substr($$obuf, 0, $rv) = '';
349 } elsif ($! == EAGAIN) {
350 # this shouldn't happen, but
351 # it's not that big a deal
352 } else {
353 # the file descriptor is toast
354 0 ${*$self}{ie_writeclosed} = $!;
355 0 $self->ie_invoke(0, 'ie_werror', $obuf);
356 }
357 }
358 0 ▶ if (${*$self}{ie_closerequested}) {
Branch: 2 branches
BranchTrueFalseTotal
if (do { *$self }->{'ie_closerequested'}) { } 0 0 0
elsif (do { *$self }->{'ie_shutdownrequested'}) { } 0 0 0
359 0 ▶ if (! length($$obuf)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $$obuf) 0 0 0
360 0 $self->ie_deregister();
361 0 ${*$self}{ie_fh}->close();
362 0 delete ${*$self}{ie_closerequested};
363 }
364 0 } elsif (${*$self}{ie_shutdownrequested}) {
365 0 ▶ if (! length($$obuf)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $$obuf) 0 0 0
366 0 shutdown(${*$self}{ie_fh}, 1);
367 0 ${*$self}{ie_writeclosed} = 1;
368 0 delete ${*$self}{ie_shutdownrequested};
369 0 $self->ie_invoke(0, 'ie_outputdone', $obuf, 0);
370 }
371 } else {
372 0 $self->ie_invoke(0, 'ie_output', $obuf, $rv);
373 0 return 1 if ${*$self}{ie_writeclosed}
374 0 ▶ && ${*$self}{ie_readclosed};
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"} 0 0 0
Condition0%0/3
do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"}
!ll&&!rl&&r
000
MC/DC0%0/2
do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"}
do { *$self }->{"ie_writeclosed"} do { *$self }->{"ie_readclosed"}
Truth table0%0/3
A and B
A= do { *$self }->{"ie_writeclosed"}B= do { *$self }->{"ie_readclosed"}
ABresult
0X0
100
111
375 0 ▶ if (! length($$obuf)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $$obuf) 0 0 0
376 0 $self->ie_invoke(0, 'ie_outputdone', $obuf, 1);
377 0 return 1 if ${*$self}{ie_writeclosed}
378 0 ▶ && ${*$self}{ie_readclosed};
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"} 0 0 0
Condition0%0/3
do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"}
!ll&&!rl&&r
000
MC/DC0%0/2
do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"}
do { *$self }->{"ie_writeclosed"} do { *$self }->{"ie_readclosed"}
Truth table0%0/3
A and B
A= do { *$self }->{"ie_writeclosed"}B= do { *$self }->{"ie_readclosed"}
ABresult
0X0
100
111
379 0 ▶ if (! length($$obuf)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $$obuf) 0 0 0
380 0 $self->writeevents(0);
381 }
382 }
383 0 ▶ if (length($$obuf) > ${*$self}{ie_obufsize}) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $$obuf > do { *$self }->{'ie_obufsize'}) { } 0 0 0
elsif (do { *$self }->{'ie_overflowinvoked'}) { } 0 0 0
384 0 ${*$self}{ie_overflowinvoked} = 1;
385 0 $self->ie_invoke(0, 'ie_outputoverflow', 1, $obuf);
386 0 } elsif (${*$self}{ie_overflowinvoked}) {
387 0 ${*$self}{ie_overflowinvoked} = 0;
388 0 $self->ie_invoke(0, 'ie_outputoverflow', 0, $obuf);
389 }
390 }
391 }
392 0 ▶ return 1 if ${*$self}{ie_writeclosed} && ${*$self}{ie_readclosed};
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"} 0 0 0
Condition0%0/3
do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"}
!ll&&!rl&&r
000
MC/DC0%0/2
do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"}
do { *$self }->{"ie_writeclosed"} do { *$self }->{"ie_readclosed"}
Truth table0%0/3
A and B
A= do { *$self }->{"ie_writeclosed"}B= do { *$self }->{"ie_readclosed"}
ABresult
0X0
100
111
393 0 return 0;
394 }
395  
396 sub ie_dispatch_exception
397 0 ▶{
Subroutine ie_dispatch_exception: not called CC=9 SCAR=45.0
398 0 my ($self, $fh) = @_;
399 0 ▶ printf STDERR "E%d", fileno(${*$self}{ie_fh}) if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $T::sdebug 0 0 0
400 0 ▶ if (${*$self}{ie_closerequested}) {
Branch: 3 branches
BranchTrueFalseTotal
if (do { *$self }->{'ie_closerequested'}) { } 0 0 0
elsif (do { *$self }->{'ie_writeclosed'} and do { *$self }->{'ie_readclosed'}) { } 0 0 0
elsif ($fh->eof) { } 0 0 0
401 0 $self->forceclose;
402 0 ▶ } elsif (${*$self}{ie_writeclosed} && ${*$self}{ie_readclosed}) {
Condition0%0/3
do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"}
!ll&&!rl&&r
000
MC/DC0%0/2
do { *$self }->{"ie_writeclosed"} and do { *$self }->{"ie_readclosed"}
do { *$self }->{"ie_writeclosed"} do { *$self }->{"ie_readclosed"}
Truth table0%0/3
A and B
A= do { *$self }->{"ie_writeclosed"}B= do { *$self }->{"ie_readclosed"}
ABresult
0X0
100
111
403 0 $self->forceclose;
404 } elsif ($fh->eof) {
405 0 ▶ if (length(${*$self}{ie_ibuf})) {
Branch: 1 branch
BranchTrueFalseTotal
if (length do { *$self }->{"ie_ibuf"}) 0 0 0
406 0 $self->ie_invoke(0, 'ie_input', \${*$self}{ie_ibuf});
407 }
408 0 ▶ if (${*$self}{ie_eofinvoked}++) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{'ie_eofinvoked'}++) { } 0 0 0
409 0 warn "EOF repeat";
410 } else {
411 0 ${*$self}{ie_closecalled} = 0;
412 0 $self->ie_invoke(0, 'ie_eof', \${*$self}{ie_ibuf});
413 0 ▶ unless (${*$self}{ie_closecalled}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (do { *$self }->{"ie_closecalled"}) 0 0 0
414 0 $self->close;
415 }
416 }
417 } else {
418 # print STDERR "!?!";
419 0 $self->ie_invoke(0, 'ie_exception');
420 }
421 }
422  
423  
424 sub ie_dispatch_timer
425 0 ▶{
Subroutine ie_dispatch_timer: not called CC=6 SCAR=37.4
426 0 my ($self) = @_;
427 0 ▶ printf STDERR "T%d", fileno(${*$self}{ie_fh}) if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $T::sdebug 0 0 0
428 0 ▶ if (${*$self}{ie_connecting}
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{'ie_connecting'} and do { *$self }->{'ie_connect_timeout'} and &IO::Event::Common::time() >= do { *$self }->{'ie_connect_timeout'}) { } 0 0 0
Condition0%0/6
do { *$self }->{"ie_connecting"} and do { *$self }->{"ie_connect_timeout"} and &IO::Event::Common::time() >= do { *$self }->{"ie_connect_timeout"}
!ll&&!rl&&r
000
do { *$self }->{"ie_connecting"} and do { *$self }->{"ie_connect_timeout"}
!ll&&!rl&&r
000
MC/DC0%0/3
do { *$self }->{"ie_connecting"} and do { *$self }->{"ie_connect_timeout"} and &IO::Event::Common::time() >= do { *$self }->{"ie_connect_timeout"}
do { *$self }->{"ie_connecting"} do { *$self }->{"ie_connect_timeout"} &IO::Event::Common::time() >= do { *$self }->{"ie_connect_timeout"}
Truth table0%0/4
A and B and C
A= do { *$self }->{"ie_connecting"}B= do { *$self }->{"ie_connect_timeout"}C= &IO::Event::Common::time() >= do { *$self }->{"ie_connect_timeout"}
ABCresult
0XX0
10X0
1100
1111
429 0 && ${*$self}{ie_connect_timeout}
430 0 && time >= ${*$self}{ie_connect_timeout})
431 {
432 0 delete ${*$self}{ie_connect_timeout};
433 0 ▶ $self->ie_invoke(0, 'ie_connect_failed', ETIMEDOUT)
Branch: 1 branch
BranchTrueFalseTotal
$self->ie_invoke(0, "ie_connect_failed", 110) or $self->ie_invoke(0, "ie_timer") 0 0 0
434 or $self->ie_invoke(0, 'ie_timer');
435 } else {
436 0 $self->ie_invoke(0, 'ie_timer');
437 }
438 }
439  
440  
441 # same name as handler since we want to intercept invocations
442 # when processing pending callbacks. Why?
443 sub ie_input
444 573 ▶{
Subroutine ie_input: called CC=9 SCAR=23.9
445 573 my $self = shift;
446 573 my $ibuf = \${*$self}{ie_ibuf};
447  
448 #
449 # We'll loop just to make sure we don't miss an event
450 #
451 573 for (;;) {
452 1000 my $ol = length($$ibuf);
453 1000 my $rv = ${*$self}{ie_fh}->sysread($$ibuf, BUFSIZ, $ol);
454  
455 # my $x = defined($rv) ? $rv : "$!"; # LOST EVENTS
456 # print STDERR "<INPUT ${*$self}{ie_desc}=$x>"; # LOST EVENTS
457  
458 1000 ▶ if ($rv) {
Branch: 3 branches
BranchTrueFalseTotal
if ($rv) { } 430 570 1000
elsif (defined $rv) { } 172 398 570
elsif ($! == 11) { } 398 0 398
459 430 delete ${*$self}{ie_readclosed};
460 } elsif (defined($rv)) {
461 # must be 0 and closed!
462 172 ${*$self}{ie_readclosed} = 1;
463 172 last;
464 } elsif ($! == EAGAIN) {
465 # readclosed = 0?
466 398 last;
467 } else {
468 # errors other than EAGAIN aren't recoverable
469 0 ${*$self}{ie_readclosed} = $!;
470 0 last;
471 }
472  
473 430 $self->ie_invoke(1, 'ie_input', $ibuf);
474 427 ▶ last if ${*$self}{ie_readclosed};
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"ie_readclosed"} 0 427 427
475 }
476  
477 570 ▶ if (${*$self}{ie_readclosed}) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{"ie_readclosed"}) 172 398 570
478 172 ▶ $self->ie_invoke(1, 'ie_input', $ibuf)
Branch: 1 branch
BranchTrueFalseTotal
if length $$ibuf 110 62 172
479 if length($$ibuf);
480 172 ▶ if (${*$self}{ie_connecting}) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{'ie_connecting'}) { } 0 172 172
481 0 ${*$self}{ie_writeclosed} = $!;
482 0 $self->writeevents(0);
483 0 delete ${*$self}{ie_connecting};
484 0 delete ${*$self}{ie_connect_timeout};
485 0 $self->ie_invoke(0, 'ie_connect_failed', $!);
486 } else {
487 $self->ie_invoke(0, 'ie_eof', $ibuf)
488 172 ▶ unless ${*$self}{ie_eofinvoked}++;
Branch: 1 branch
BranchTrueFalseTotal
unless do { *$self }->{"ie_eofinvoked"}++ 172 0 172
489 }
490 169 $self->readevents(0);
491 }
492 }
493  
494 sub reentrant
495 0 ▶{
Subroutine reentrant: not called CC=2 SCAR=17.9
496 0 my $self = shift;
497 0 my $old = ${*$self}{ie_reentrant};
498 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
499 0 ${*$self}{ie_reentrant} = $_[0];
500 }
501 0 return $old;
502 }
503
504 sub output_bufsize
505 0 ▶{
Subroutine output_bufsize: not called CC=4 SCAR=30.0
506 0 my $self = shift;
507 0 my $old = ${*$self}{ie_obufsize};
508 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
509 0 ${*$self}{ie_obufsize} = $_[0];
510 0 ▶ if (length(${*$self}{ie_obuf}) > ${*$self}{ie_obufsize}) {
Branch: 2 branches
BranchTrueFalseTotal
if (length do { *$self }->{'ie_obuf'} > do { *$self }->{'ie_obufsize'}) { } 0 0 0
elsif (do { *$self }->{'ie_overflowinvoked'}) { } 0 0 0
511 0 $self->ie_invoke(0, 'ie_outputoverflow', 1, ${*$self}{ie_obuf});
512 0 ${*$self}{ie_overflowinvoked} = 1;
513 0 } elsif (${*$self}{ie_overflowinvoked}) {
514 0 $self->ie_invoke(0, 'ie_outputoverflow', 0, ${*$self}{ie_obuf});
515 0 ${*$self}{ie_overflowinvoked} = 0;
516 }
517 # while this should trigger callbacks, we don't want to assume
518 # that our caller's code is re-enterant.
519 }
520 0 return $old;
521 }
522  
523 # get/set autoread
524 sub autoread
525 0 ▶{
Subroutine autoread: not called CC=3 SCAR=24.8
526 0 my $self = shift;
527 0 my $old = ${*$self}{ie_autoread};
528 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
529 0 ${*$self}{ie_autoread} = $_[0];
530 0 ▶ if (${*$self}{ie_readclosed}) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{"ie_readclosed"}) 0 0 0
531 0 delete ${*$self}{ie_readclosed};
532 0 $self->readevents(1);
533 }
534 }
535 0 return $old;
536 }
537  
538 sub writeevents
539 685 ▶{
Subroutine writeevents: called CC=4 SCAR=13.9
540 685 my $self = shift;
541 685 my $old = ${*$self}{ie_want_write_events};
542 685 ▶ return !! $old unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 685 685
543 685 my $new = !! shift;
544 685 ▶ return $old if defined($old) && $old eq $new;
Branch: 1 branch
BranchTrueFalseTotal
if defined $old and $old eq $new 490 195 685
Condition66%2/3
defined $old and $old eq $new
!ll&&!rl&&r
1950490
MC/DC50%1/2
defined $old and $old eq $new
defined $old $old eq $new
Truth table66%2/3
A and B
A= defined $oldB= $old eq $new
ABresult
0X0
100
111
545 195 ${*$self}{ie_want_write_events} = $new;
546 195 $self->set_write_polling($new);
547 195 return $old;
548 }
549  
550 sub readevents
551 854 ▶{
Subroutine readevents: called CC=4 SCAR=13.9
552 854 my $self = shift;
553 854 my $old = ${*$self}{ie_want_read_events};
554 854 ▶ return !! $old unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 854 854
555 854 my $new = !! shift;
556 # print STDERR "<READEVENTS ${*$self}{ie_desc} = $new>"; # LOST EVENTS
557 854 ▶ return $old if defined($old) && $old eq $new;
Branch: 1 branch
BranchTrueFalseTotal
if defined $old and $old eq $new 112 742 854
Condition100%3/3
defined $old and $old eq $new
!ll&&!rl&&r
195547112
MC/DC100%2/2
defined $old and $old eq $new
defined $old $old eq $new
Truth table100%3/3
A and B
A= defined $oldB= $old eq $new
ABresult
0X0
100
111
558 742 ${*$self}{ie_want_read_events} = $new;
559 742 $self->set_read_polling($new);
560 742 return $old;
561 }
562  
563 sub drain
564 0 ▶{
Subroutine drain: not called CC=1 SCAR=6.9
565 0 my $self = shift;
566 0 $self->writeevents(1);
567 }
568  
569 # register with Event
570 sub ie_register
571 585 ▶{
Subroutine ie_register: called CC=1 SCAR=0.0
572 585 my ($self) = @_;
573 585 my $fh = ${*$self}{ie_fh};
574 585 $fh->blocking(0);
575 585 $fh->autoflush(1);
576  
577 585 my $fileno = ${*$self}{ie_fileno} = $fh->fileno;
578 585 return ($fh, $fileno);
579 }
580  
581 # deregister with Event
582 sub ie_deregister
583 490 ▶{
Subroutine ie_deregister: called CC=1 SCAR=0.0
584 490 my ($self) = @_;
585 490 my $fh = ${*$self}{ie_fh};
586 490 delete $fh_table{$fh};
587 490 $self->readevents(0);
588 490 $self->writeevents(0);
589 }
590  
591 # the standard max() function
592 sub ie_max
593 0 ▶{
Subroutine ie_max: not called CC=3 SCAR=24.8
594 0 my ($max, @stuff) = @_;
595 0 for my $t (@stuff) {
596 0 ▶ $max = $t if $t > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $t > $max 0 0 0
597 }
598 0 return $max;
599 }
600  
601 # get the Filehandle
602 sub filehandle
603 12 ▶{
Subroutine filehandle: called CC=1 SCAR=0.0
604 12 my ($self) = @_;
605 12 return ${*$self}{ie_fh};
606 }
607  
608 # get the Event
609 sub event
610 0 ▶{
Subroutine event: not called CC=1 SCAR=6.9
611 0 my ($self) = @_;
612 0 return ${*$self}{ie_event};
613 }
614  
615 # set the handler
616 sub handler
617 0 ▶{
Subroutine handler: not called CC=2 SCAR=17.9
618 0 my $self = shift;
619 0 my $old = ${*$self}{ie_handler};
620 0 ▶ ${*$self}{ie_handler} = $_[0]
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
621 if @_;
622 0 return $old;
623 }
624  
625 # is there enough?
626 sub can_read
627 0 ▶{
Subroutine can_read: not called CC=4 SCAR=30.0
628 0 my ($self, $length) = @_;
629 0 my $l = length(${*$self}{ie_ibuf});
630 0 ▶ return $l if $l && $l >= $length;
Branch: 1 branch
BranchTrueFalseTotal
if $l and $l >= $length 0 0 0
Condition0%0/3
$l and $l >= $length
!ll&&!rl&&r
000
MC/DC0%0/2
$l and $l >= $length
$l $l >= $length
Truth table0%0/3
A and B
A= $lB= $l >= $length
ABresult
0X0
100
111
631 0 ▶ return "0 but true" if $length <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $length <= 0 0 0 0
632 0 return 0;
633 }
634  
635 # reads N characters or returns undef if it can't
636 sub getsome
637 54 ▶{
Subroutine getsome: called CC=5 SCAR=16.3
638 54 my ($self, $length) = @_;
639 54 ▶ return undef unless ${*$self}{ie_autoread};
Branch: 1 branch
BranchTrueFalseTotal
unless do { *$self }->{"ie_autoread"} 0 54 54
640 54 my $ibuf = \${*$self}{ie_ibuf};
641 54 ▶ $length = length($$ibuf)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $length 0 54 54
642 unless defined $length;
643 54 my $tmp = substr($$ibuf, 0, $length);
644 54 substr($$ibuf, 0, $length) = '';
645 54 ▶ return undef if ! length($tmp) && ! $self->eof2;
Branch: 1 branch
BranchTrueFalseTotal
unless length $tmp or $self->eof2 3 51 54
Condition66%2/3
length $tmp or $self->eof2
l!l&&r!l&&!r
5103
MC/DC50%1/2
length $tmp or $self->eof2
length $tmp $self->eof2
Truth table66%2/3
A or B
A= length $tmpB= $self->eof2
ABresult
1X1
011
000
646 51 return $tmp;
647 }
648  
649 # from base perl
650 # will this work right for SOCK_DGRAM?
651 sub connect
652 0 ▶{
Subroutine connect: not called CC=3 SCAR=24.8
653 0 my $self = shift;
654 0 my $fh = ${*$self}{ie_fh};
655 0 my $rv = $fh->connect(@_);
656 0 $self->reset;
657 0 $self->readevents(1);
658 0 ▶ unless($fh->connected()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh->connected) 0 0 0
659 0 ${*$self}{ie_connecting} = 1;
660 0 $self->writeevents(1);
661 0 ${*$self}{ie_connect_timeout} = time
662 0 + ${*$self}{ie_socket_timeout}
663 0 ▶ if ${*$self}{ie_socket_timeout};
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"ie_socket_timeout"} 0 0 0
664 }
665 0 return $rv;
666 }
667  
668 # from IO::Socket
669 sub listen
670 0 ▶{
Subroutine listen: not called CC=1 SCAR=6.9
671 0 my $self = shift;
672 0 my $fh = ${*$self}{ie_fh};
673 0 my $rv = $fh->listen();
674 0 $self->listener(1);
675 0 return $rv;
676 }
677  
678 # from IO::Socket
679 sub accept
680 144 ▶{
Subroutine accept: called CC=6 SCAR=20.4
681 144 my ($self, $handler) = @_;
682 144 my $fh = ${*$self}{ie_fh};
683 144 my $newfh = $fh->accept();
684 144 ▶ return undef unless $newfh;
Branch: 1 branch
BranchTrueFalseTotal
unless $newfh 0 144 144
685  
686 # it appears that sockdomain isn't set on accept()ed sockets
687 144 my $sd = $fh->sockdomain;
688  
689 144 my $desc;
690 144 ▶ if ($sd == &AF_INET) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sd == &AF_INET) { } 144 0 144
elsif ($sd == &AF_UNIX) { } 0 0 0
691 144 $desc = sprintf "Accepted socket from %s:%s to %s:%s",
692 $newfh->peerhost, $newfh->peerport,
693 $newfh->sockhost, $newfh->sockport;
694 } elsif ($sd == &AF_UNIX) {
695 # Unset peerpath crashes on FreeBSD 9
696 0 my $pp = eval { $newfh->peerpath };
697 0 ▶ if ($pp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pp) { } 0 0 0
698 0 $desc = sprintf "Accepted socket from %s to %s",
699 $pp, $newfh->hostpath;
700 } else {
701 0 $desc = sprintf "Accepted socket from to %s",
702 $newfh->hostpath;
703 }
704 } else {
705 0 $desc = "Accept for ${*$self}{ie_desc}";
706 }
707 60 $handler = ${*$self}{ie_handler}
708 144 ▶ unless defined $handler;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $handler 60 84 144
709 144 my $new = IO::Event->new($newfh, $handler, $desc);
710 144 ${*$new}{ie_obufsize} = ${*$self}{ie_obufsize};
711 144 ${*$new}{ie_reentrant} = ${*$self}{ie_reentrant};
712 144 return $new;
713 }
714  
715 # not the same as IO::Handle
716 sub input_record_separator
717 81 ▶{
Subroutine input_record_separator: called CC=3 SCAR=13.2
718 81 my $self = shift;
719 81 my $old = ${*$self}{ie_irs};
720 81 ▶ ${*$self}{ie_irs} = $_[0]
Branch: 1 branch
BranchTrueFalseTotal
if @_ 81 0 81
721 if @_;
722 81 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T::debug) 0 81 81
723 0 my $fn = $self->fileno;
724 0 my $x = ${*$self}{ie_irs};
725 0 $x =~ s/\n/\\n/g;
726 0 print "input_record_separator($fn) = '$x'\n";
727 }
728 81 return $old;
729 }
730  
731 # 0 = read
732 # 1 = write
733 # 2 = both
734 sub shutdown
735 0 ▶{
Subroutine shutdown: not called CC=9 SCAR=45.0
736 0 my ($self, $what) = @_;
737 0 my $r;
738 0 ▶ if ($what == 1 || $what == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($what == 1 or $what == 2) { } 0 0 0
elsif ($what == 0) { } 0 0 0
Condition0%0/3
$what == 1 or $what == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$what == 1 or $what == 2
$what == 1 $what == 2
Truth table0%0/3
A or B
A= $what == 1B= $what == 2
ABresult
1X1
011
000
739 0 ▶ if (length(${*$self}{ie_obuf})) {
Branch: 1 branch
BranchTrueFalseTotal
if (length do { *$self }->{'ie_obuf'}) { } 0 0 0
740 0 ${*$self}{ie_shutdownrequested} = $what;
741 0 ▶ if ($what == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what == 2) 0 0 0
742 0 $r = shutdown(${*$self}{ie_fh}, 0)
743 }
744 } else {
745 0 $r = shutdown(${*$self}{ie_fh}, $what);
746 0 ${*$self}{ie_writeclosed} = 1;
747 }
748 } elsif ($what == 0) {
749 0 $r = shutdown(${*$self}{ie_fh}, 0);
750 } else {
751 0 die;
752 }
753 0 ▶ if ($what == 0 || $what == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what == 0 or $what == 2) 0 0 0
Condition0%0/3
$what == 0 or $what == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$what == 0 or $what == 2
$what == 0 $what == 2
Truth table0%0/3
A or B
A= $what == 0B= $what == 2
ABresult
1X1
011
000
754 0 ${*$self}{ie_readclosed} = 1;
755 }
756 0 ▶ return 1 unless defined($r);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r 0 0 0
757 0 return $r;
758 }
759  
760 # from IO::Handle
761 sub close
762 490 ▶{
Subroutine close: called CC=2 SCAR=8.8
763 490 my ($self) = @_;
764 490 my $obuf = \${*$self}{ie_obuf};
765 490 ${*$self}{ie_closecalled} = 1;
766 490 ▶ if (length($$obuf)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$obuf) { } 0 490 490
767 0 ${*$self}{ie_closerequested} = 1;
768 0 ${*$self}{ie_writeclosed} = 1;
769 0 ${*$self}{ie_readclosed} = 1;
770 } else {
771 490 return $self->forceclose;
772 }
773 }
774  
775 sub forceclose
776 490 ▶{
Subroutine forceclose: called CC=2 SCAR=7.0
777 490 my ($self) = @_;
778 490 $self->ie_deregister();
779 490 my $ret = ${*$self}{ie_fh}->close();
780 490 ${*$self}{ie_writeclosed} = 1;
781 490 ${*$self}{ie_readclosed} = 1;
782 490 ${*$self}{ie_totallyclosed} = 1;
783 490 ▶ print STDERR "forceclose(${*$self}{ie_desc})\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $T::debug 0 490 490
784 490 return $ret;
785 }
786  
787 # from IO::Handle
788 sub open
789 0 ▶{
Subroutine open: not called CC=7 SCAR=40.3
790 0 my $self = shift;
791 0 my $fh = ${*$self}{ie_fh};
792 0 $self->ie_deregister();
793 0 ▶ $self->close()
Branch: 1 branch
BranchTrueFalseTotal
if $fh->opened 0 0 0
794 if $fh->opened;
795 0 $self->reset;
796 0 my $r;
797 0 ▶ if (@_ == 1) {
Branch: 4 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
elsif (@_ == 2) { } 0 0 0
elsif (@_ == 3) { } 0 0 0
elsif (@_ > 3) { } 0 0 0
798 0 $r = CORE::open($fh, $_[0]);
799 } elsif (@_ == 2) {
800 0 $r = CORE::open($fh, $_[0], $_[1]);
801 } elsif (@_ == 3) {
802 0 $r = CORE::open($fh, $_[0], $_[1], $_[4]);
803 } elsif (@_ > 3) {
804 0 $r = CORE::open($fh, $_[0], $_[1], $_[4], @_);
805 } else {
806 0 confess("open w/o enoug args");
807 }
808 0 ▶ return undef unless defined $r;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r 0 0 0
809 0 $self->ie_register();
810 0 return $r;
811 }
812  
813  
814 # from IO::Handle VAR LENGTH [OFFSET]
815 #
816 # this returns nothing unless there is enough to fill
817 # the request or it's at eof
818 #
819 sub sysread
820 90 ▶{
Subroutine sysread: called CC=8 SCAR=28.1
821 90 my $self = shift;
822  
823 90 ▶ unless (${*$self}{ie_autoread}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (do { *$self }->{"ie_autoread"}) 0 90 90
824 0 my $buf = shift;
825 0 my $length = shift;
826 0 my $rv = ${*$self}{ie_fh}->sysread($buf, $length, @_);
827  
828 0 ▶ if ($rv) {
Branch: 3 branches
BranchTrueFalseTotal
if ($rv) { } 0 0 0
elsif (defined $rv) { } 0 0 0
elsif ($! == 11) { } 0 0 0
829 0 delete ${*$self}{ie_readclosed};
830 } elsif (defined($rv)) {
831 # must be 0 and closed!
832 0 ${*$self}{ie_readclosed} = 1;
833 } elsif ($! == EAGAIN) {
834 # nothing there
835 } else {
836 # errors other than EAGAIN aren't recoverable
837 0 ${*$self}{ie_readclosed} = $!;
838 }
839 0 return $rv;
840 }
841  
842 90 my $ibuf = \${*$self}{ie_ibuf};
843 90 my $length = length($$ibuf);
844  
845 90 ▶ return undef unless $length >= $_[1] || $self->eof2;
Branch: 1 branch
BranchTrueFalseTotal
unless $length >= $_[1] or $self->eof2 12 78 90
Condition100%3/3
$length >= $_[1] or $self->eof2
l!l&&r!l&&!r
542412
MC/DC100%2/2
$length >= $_[1] or $self->eof2
$length >= $_[1] $self->eof2
Truth table100%3/3
A or B
A= $length >= $_[1]B= $self->eof2
ABresult
1X1
011
000
846  
847 78 ▶ (defined $_[2] ?
Branch: 1 branch
BranchTrueFalseTotal
defined $_[2] ? : 39 39 78
848 substr ($_[0], $_[2], length($_[0]))
849 : $_[0])
850 = substr($$ibuf, 0, $_[1]);
851  
852 78 substr($$ibuf, 0, $_[1]) = '';
853 78 return ($length-length($$ibuf));
854 }
855  
856 # from IO::Handle
857 sub syswrite
858 0 ▶{
Subroutine syswrite: not called CC=3 SCAR=24.8
859 0 my ($self, $data, $length, $offset) = @_;
860 0 ▶ if (defined $offset or defined $length) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset or defined $length) { } 0 0 0
Condition0%0/3
defined $offset or defined $length
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $offset or defined $length
defined $offset defined $length
Truth table0%0/3
A or B
A= defined $offsetB= defined $length
ABresult
1X1
011
000
861 0 return $self->print(substr($data, $offset, $length));
862 } else {
863 0 return $self->print($data);
864 }
865 }
866  
867 # like Data::LineBuffer
868 sub get
869 33 ▶{
Subroutine get: called CC=5 SCAR=16.1
870 33 my $self = shift;
871 33 ▶ return undef unless ${*$self}{ie_autoread};
Branch: 1 branch
BranchTrueFalseTotal
unless do { *$self }->{"ie_autoread"} 0 33 33
872 33 my $ibuf = \${*$self}{ie_ibuf};
873 33 my $irs = "\n";
874 33 my $index = index($$ibuf, $irs);
875 33 ▶ if ($index < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < 0) 15 18 33
876 15 ▶ return undef unless $self->eof2;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->eof2 9 6 15
877 6 my $l = $$ibuf;
878 6 $$ibuf = '';
879 6 ▶ return undef unless length($l);
Branch: 1 branch
BranchTrueFalseTotal
unless length $l 3 3 6
880 3 return $l;
881 }
882 18 my $line = substr($$ibuf, 0, $index - length($irs) + 1);
883 18 substr($$ibuf, 0, $index + 1) = '';
884 18 return $line;
885 }
886  
887 # like Data::LineBuffer
888 # input_record_separator is always "\n".
889 sub unget
890 0 ▶{
Subroutine unget: not called CC=1 SCAR=1.7
891 0 my $self = shift;
892 0 my $irs = "\n";
893 60 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
894 0 substr(${*$self}{ie_ibuf}, 0, 0)
895 = join($irs, @_, undef);
896 }
897  
898 # from IO::Handle
899 sub getline
900 1046 ▶{
Subroutine getline: called CC=20 SCAR=34.4
901 1046 my $self = shift;
902 1046 ▶ return undef unless ${*$self}{ie_autoread};
Branch: 1 branch
BranchTrueFalseTotal
unless do { *$self }->{"ie_autoread"} 0 1046 1046
903 1046 my $ibuf = \${*$self}{ie_ibuf};
904 1046 my $fh = ${*$self}{ie_fh};
905 1046 ▶ my $irs = exists ${*$self}{ie_irs} ? ${*$self}{ie_irs} : $/;
Branch: 1 branch
BranchTrueFalseTotal
exists do { *$self }->{'ie_irs'} ? : 350 696 1046
906 1046 my $line;
907  
908  
909 # perl's handling if input record separators is
910 # not completely simple.
911 1046 ▶ $irs = $$irs if ref $irs;
Branch: 1 branch
BranchTrueFalseTotal
if ref $irs 0 1046 1046
912 1046 my $index;
913 1046 ▶ if ($irs =~ /^\d/ && int($irs)) {
Branch: 3 branches
BranchTrueFalseTotal
if ($irs =~ /^\d/ and int $irs) { } 15 1031 1046
elsif (not defined $irs) { } 0 1031 1031
elsif ($irs eq '') { } 335 696 1031
Condition66%2/3
$irs =~ /^\d/ and int $irs
!ll&&!rl&&r
1031015
MC/DC50%1/2
$irs =~ /^\d/ and int $irs
$irs =~ /^\d/ int $irs
Truth table66%2/3
A and B
A= $irs =~ /^\d/B= int $irs
ABresult
0X0
100
111
914 15 ▶ if ($irs > 0 && length($$ibuf) >= $irs) {
Branch: 2 branches
BranchTrueFalseTotal
if ($irs > 0 and length $$ibuf >= $irs) { } 12 3 15
elsif ($self->eof2) { } 0 3 3
Condition66%2/3
$irs > 0 and length $$ibuf >= $irs
!ll&&!rl&&r
0312
MC/DC50%1/2
$irs > 0 and length $$ibuf >= $irs
$irs > 0 length $$ibuf >= $irs
Truth table66%2/3
A and B
A= $irs > 0B= length $$ibuf >= $irs
ABresult
0X0
100
111
915 12 $line = substr($$ibuf, 0, $irs);
916 } elsif ($self->eof2) {
917 0 $line = $$ibuf;
918 }
919 } elsif (! defined $irs) {
920 0 ▶ if ($self->eof2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->eof2) 0 0 0
921 0 $line = $$ibuf;
922 }
923 } elsif ($irs eq '') {
924 # paragraph mode
925 335 $$ibuf =~ s/^\n+//;
926 335 $irs = "\n\n";
927 335 $index = index($$ibuf, "\n\n");
928 } else {
929 # multi-character (or just \n)
930 696 $index = index($$ibuf, $irs);
931 }
932 1046 ▶ if (defined $index) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index) 1031 15 1046
933 1031 ▶ $line = $index > -1
Branch: 2 branches
BranchTrueFalseTotal
$index > -1 ? : 663 368 1031
$self->eof2 ? : 108 260 368
934 ? substr($$ibuf, 0, $index+length($irs))
935 : ($self->eof2 ? $$ibuf : undef);
936 }
937 1046 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T::debug) 0 1046 1046
938 60 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
939 0 my $x = $$ibuf;
940 0 substr($x, 0, length($line)) = '';
941 0 $x =~ s/\n/\\n/g;
942 0 my $y = $irs;
943 0 $y =~ s/\n/\\n/g;
944 0 ▶ print "looked for '$y', returning undef, keeping '$x'\n" unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
945 0 my $z = $line;
946 0 $z =~ s/\n/\\n/g;
947 0 ▶ print "looked for '$y', returning '$z', keeping '$x'\n" if defined $line;
Branch: 1 branch
BranchTrueFalseTotal
if defined $line 0 0 0
948 }
949 1046 ▶ return undef unless defined($line) && length($line);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line and length $line 317 729 1046
Condition100%3/3
defined $line and length $line
!ll&&!rl&&r
26354729
MC/DC100%2/2
defined $line and length $line
defined $line length $line
Truth table100%3/3
A and B
A= defined $lineB= length $line
ABresult
0X0
100
111
950 729 substr($$ibuf, 0, length($line)) = '';
951 729 return $line;
952 }
953  
954 # is the following a good idea?
955 #sub tell
956 #{
957 # my ($self) = @_;
958 # return ${*$self}{ie_fh}->tell() + length(${*$self}{ie_obuf});
959 #}
960  
961 # from IO::Handle
962 sub getlines
963 262 ▶{
Subroutine getlines: called CC=21 SCAR=36.2
964 262 my $self = shift;
965 262 ▶ return undef unless ${*$self}{ie_autoread};
Branch: 1 branch
BranchTrueFalseTotal
unless do { *$self }->{"ie_autoread"} 0 262 262
966 262 my $ibuf = \${*$self}{ie_ibuf};
967 #my $ol = length($$ibuf);
968 262 ▶ my $irs = exists ${*$self}{ie_irs} ? ${*$self}{ie_irs} : $/;
Branch: 1 branch
BranchTrueFalseTotal
exists do { *$self }->{'ie_irs'} ? : 250 12 262
969 262 my @lines;
970 262 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T::debug) 0 262 262
971 0 my $x = $irs;
972 0 $x =~ s/\n/\\n/g;
973 0 my $fn = $self->fileno;
974 0 print "getlines($fn, '$x')\n";
975 }
976 262 ▶ if ($irs =~ /^\d/ && int($irs)) {
Branch: 3 branches
BranchTrueFalseTotal
if ($irs =~ /^\d/ and int $irs) { } 3 259 262
elsif (not defined $irs) { } 0 259 259
elsif ($irs eq '') { } 241 18 259
Condition66%2/3
$irs =~ /^\d/ and int $irs
!ll&&!rl&&r
25903
MC/DC50%1/2
$irs =~ /^\d/ and int $irs
$irs =~ /^\d/ int $irs
Truth table66%2/3
A and B
A= $irs =~ /^\d/B= int $irs
ABresult
0X0
100
111
977 3 ▶ if ($irs > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($irs > 0) { } 3 0 3
978 3 @lines = unpack("(a$irs)*", $$ibuf);
979 3 $$ibuf = '';
980 3 ▶ $$ibuf = pop(@lines)
Branch: 1 branch
BranchTrueFalseTotal
if length $lines[$#lines] != $irs and not $self->eof2 0 3 3
Condition33%1/3
length $lines[$#lines] != $irs and not $self->eof2
!ll&&!rl&&r
300
MC/DC0%0/2
length $lines[$#lines] != $irs and not $self->eof2
length $lines[$#lines] != $irs not $self->eof2
Truth table33%1/3
A and not(B)
A= length $lines[$#lines] != $irsB= not $self->eof2
ABresult
0X0
100
111
981 if length($lines[$#lines]) != $irs && ! $self->eof2;
982 } else {
983 0 ▶ return undef unless $self->eof2;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->eof2 0 0 0
984 0 @lines = $$ibuf;
985 0 $$ibuf = '';
986 }
987 } elsif (! defined $irs) {
988 0 ▶ return undef unless $self->eof2;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->eof2 0 0 0
989 0 @lines = $$ibuf;
990 0 $$ibuf = '';
991 } elsif ($irs eq '') {
992 # paragraphish mode.
993 241 $$ibuf =~ s/^\n+//;
994 241 @lines = grep($_ ne '', split(/(.*?\n\n)\n*/s, $$ibuf));
995 241 $$ibuf = '';
996 241 ▶ $$ibuf = pop(@lines)
Branch: 1 branch
BranchTrueFalseTotal
if @lines and substr($lines[$#lines], -2) ne "\n\n" and not $self->eof2 119 122 241
Condition100%6/6
@lines and substr($lines[$#lines], -2) ne "\n\n" and not $self->eof2
!ll&&!rl&&r
8735119
@lines and substr($lines[$#lines], -2) ne "\n\n"
!ll&&!rl&&r
5829154
MC/DC100%3/3
@lines and substr($lines[$#lines], -2) ne "\n\n" and not $self->eof2
@lines substr($lines[$#lines], -2) ne "\n\n" not $self->eof2
Truth table100%4/4
A and B and not(C)
A= @linesB= substr($lines[$#lines], -2) ne "\n\n"C= not $self->eof2
ABCresult
0XX0
10X0
1100
1111
997 if @lines && substr($lines[$#lines], -2) ne "\n\n" && ! $self->eof2;
998 241 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T::debug) 0 241 241
999 0 my $x = join('|', @lines);
1000 0 $x =~ s/\n/\\n/g;
1001 0 my $y = $$ibuf;
1002 0 $y =~ s/\n/\\n/g;
1003 0 print "getlines returns '$x' but holds onto '$y'\n";
1004 }
1005 } else {
1006 # multicharacter
1007 $rxcache{$irs} = qr/(.*?\Q$irs\E)/s
1008 18 ▶ unless exists $rxcache{$irs};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rxcache{$irs} 6 12 18
1009 18 my $irsrx = $rxcache{$irs};
1010 18 @lines = grep($_ ne '', split(/$rxcache{$irs}/, $$ibuf));
1011 return undef
1012 18 ▶ unless @lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @lines 0 18 18
1013 18 $$ibuf = '';
1014 18 ▶ $$ibuf = pop(@lines)
Branch: 1 branch
BranchTrueFalseTotal
if substr($lines[$#lines], 0 - length($irs)) ne $irs and not $self->eof2 6 12 18
Condition100%3/3
substr($lines[$#lines], 0 - length($irs)) ne $irs and not $self->eof2
!ll&&!rl&&r
666
MC/DC100%2/2
substr($lines[$#lines], 0 - length($irs)) ne $irs and not $self->eof2
substr($lines[$#lines], 0 - length($irs)) ne $irs not $self->eof2
Truth table100%3/3
A and not(B)
A= substr($lines[$#lines], 0 - length($irs)) ne $irsB= not $self->eof2
ABresult
0X0
100
111
1015 if substr($lines[$#lines], 0-length($irs)) ne $irs && ! $self->eof2;
1016 }
1017 262 return @lines;
1018 }
1019  
1020 # from IO::Handle
1021 sub ungetc
1022 0 ▶{
Subroutine ungetc: not called CC=1 SCAR=6.9
1023 0 my ($self, $ord) = @_;
1024 0 my $ibuf = \${*$self}{ie_ibuf};
1025 0 substr($$ibuf, 0, 0) = chr($ord);
1026 }
1027  
1028 # from FileHandle::Unget & original
1029 sub ungets
1030 12 ▶{
Subroutine ungets: called CC=1 SCAR=0.0
1031 12 my $self = shift;
1032 12 substr(${*$self}{ie_ibuf}, 0, 0)
1033 = join('', @_);
1034 }
1035  
1036 60 *xungetc = \&ungets;
1037 60 *ungetline = \&ungets;
1038  
1039 # from IO::Handle
1040 sub getc
1041 54 ▶{
Subroutine getc: called CC=1 SCAR=0.0
1042 54 my ($self) = @_;
1043 54 $self->getsome(1);
1044 }
1045  
1046 # from IO::Handle
1047 sub print
1048 144 ▶{
Subroutine print: called CC=10 SCAR=31.1
1049 144 my ($self, @data) = @_;
1050 0 $! = ${*$self}{ie_writeclosed} && return undef
1051 144 ▶ if ${*$self}{ie_writeclosed};
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"ie_writeclosed"} 0 144 144
Condition0%0/2
do { *$self }->{'ie_writeclosed'} && (return undef)
!ll
00
MC/DC0%0/1
do { *$self }->{'ie_writeclosed'} && (return undef)
do { *$self }->{'ie_writeclosed'}
Truth table0%0/2
A
A= do { *$self }->{'ie_writeclosed'}
Aresult
00
11
1052 144 my $ol;
1053 my $rv;
1054 144 my $er;
1055 144 my $obuf = \${*$self}{ie_obuf};
1056 144 ▶ if ($ol = length($$obuf)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ol = length $$obuf) { } 0 144 144
1057 0 $$obuf .= join('', @data);
1058 0 $rv = length($$obuf) - $ol;
1059 } else {
1060 144 my $fh = ${*$self}{ie_fh};
1061 144 my $data = join('', @data);
1062 144 $rv = CORE::syswrite($fh, $data);
1063 144 ▶ if (defined($rv) && $rv < length($data)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $rv and $rv < length $data) { } 0 144 144
elsif (not defined $rv and $! == 11) { } 0 144 144
Condition33%1/3
defined $rv and $rv < length $data
!ll&&!rl&&r
01440
MC/DC0%0/2
defined $rv and $rv < length $data
defined $rv $rv < length $data
Truth table33%1/3
A and B
A= defined $rvB= $rv < length $data
ABresult
0X0
100
111
1064 0 $$obuf = substr($data, $rv, length($data)-$rv);
1065 0 $self->writeevents(1);
1066 0 $rv = 1;
1067 ▶ } elsif ((! defined $rv) && $! == EAGAIN) {
Condition33%1/3
not defined $rv and $! == 11
!ll&&!rl&&r
14400
MC/DC0%0/2
not defined $rv and $! == 11
not defined $rv $! == 11
Truth table33%1/3
not(A) and B
A= not defined $rvB= $! == 11
ABresult
0X0
100
111
1068 0 $$obuf = $data;
1069 0 $self->writeevents(1);
1070 0 $rv = 1;
1071 } else {
1072 144 $er = 0+$!;
1073 }
1074 }
1075 144 ▶ if (length($$obuf) > ${*$self}{ie_obufsize}) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $$obuf > do { *$self }->{'ie_obufsize'}) { } 0 144 144
elsif (do { *$self }->{'ie_overflowinvoked'}) { } 0 144 144
1076 0 $self->ie_invoke(0, 'ie_outputoverflow', 1, $obuf);
1077 0 ${*$self}{ie_overflowinvoked} = 1;
1078 144 } elsif (${*$self}{ie_overflowinvoked}) {
1079 0 $self->ie_invoke(0, 'ie_outputoverflow', 0, $obuf);
1080 0 ${*$self}{ie_overflowinvoked} = 0;
1081 }
1082 144 $! = $er;
1083 144 return $rv;
1084 }
1085  
1086 # from IO::Handle
1087 sub eof
1088 36 ▶{
Subroutine eof: called CC=3 SCAR=16.0
1089 36 my ($self) = @_;
1090 36 ▶ return 0 if length(${*$self}{ie_ibuf});
Branch: 1 branch
BranchTrueFalseTotal
if length do { *$self }->{"ie_ibuf"} 36 0 36
1091 0 ▶ return 1 if ${*$self}{ie_readclosed};
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"ie_readclosed"} 0 0 0
1092 0 return 0;
1093 # return ${*$self}{ie_fh}->eof;
1094 }
1095  
1096 # internal use only.
1097 # just like eof, but we assume the input buffer is empty
1098 sub eof2
1099 591 ▶{
Subroutine eof2: called CC=5 SCAR=23.9
1100 591 my ($self) = @_;
1101 591 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T::debug) 0 591 591
1102 0 my $fn = $self->fileno;
1103 0 print "eof2($fn)...";
1104 0 ▶ print " readclosed" if ${*$self}{ie_readclosed};
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"ie_readclosed"} 0 0 0
1105 #print " EOF" if ${*$self}{ie_fh}->eof;
1106 0 my $x = 0;
1107 0 ▶ $x = 1 if ${*$self}{ie_readclosed};
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"ie_readclosed"} 0 0 0
1108 # $x = ${*$self}{ie_fh}->eof unless defined $x;
1109 0 print " =$x\n";
1110 }
1111 591 ▶ return 1 if ${*$self}{ie_readclosed};
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"ie_readclosed"} 179 412 591
1112 412 return 0;
1113 # return ${*$self}{ie_fh}->eof;
1114 }
1115  
1116 sub fileno
1117 58 ▶{
Subroutine fileno: called CC=7 SCAR=27.5
1118 58 my $self = shift;
1119 58 ▶ return undef unless $self && ref($self) && reftype($self) eq 'GLOB';
Branch: 1 branch
BranchTrueFalseTotal
unless $self and ref $self and builtin::reftype($self) eq "GLOB" 1 57 58
Condition50%3/6
$self and ref $self and builtin::reftype($self) eq "GLOB"
!ll&&!rl&&r
0157
$self and ref $self
!ll&&!rl&&r
0058
MC/DC33%1/3
$self and ref $self and builtin::reftype($self) eq "GLOB"
$self ref $self builtin::reftype($self) eq "GLOB"
Truth table50%2/4
A and B and C
A= $selfB= ref $selfC= builtin::reftype($self) eq "GLOB"
ABCresult
0XX0
10X0
1100
1111
1120 57 return ${*$self}{ie_fileno}
1121 57 ▶ if defined ${*$self}{ie_fileno};
Branch: 1 branch
BranchTrueFalseTotal
if defined do { *$self }->{"ie_fileno"} 57 0 57
1122 0 ▶ return undef unless ${*$self}{ie_fh} && reftype(${*$self}{ie_fh}) eq 'GLOB';
Branch: 1 branch
BranchTrueFalseTotal
unless do { *$self }->{"ie_fh"} and builtin::reftype(do { *$self }->{"ie_fh"}) eq "GLOB" 0 0 0
Condition0%0/3
do { *$self }->{"ie_fh"} and builtin::reftype(do { *$self }->{"ie_fh"}) eq "GLOB"
!ll&&!rl&&r
000
MC/DC0%0/2
do { *$self }->{"ie_fh"} and builtin::reftype(do { *$self }->{"ie_fh"}) eq "GLOB"
do { *$self }->{"ie_fh"} builtin::reftype(do { *$self }->{"ie_fh"}) eq "GLOB"
Truth table0%0/3
A and B
A= do { *$self }->{"ie_fh"}B= builtin::reftype(do { *$self }->{"ie_fh"}) eq "GLOB"
ABresult
0X0
100
111
1123 0 return ${*$self}{ie_fh}->fileno();
1124 }
1125  
1126 sub DESTROY
1127 58 ▶{
Subroutine DESTROY: called CC=7 SCAR=20.8
1128 58 my $self = shift;
1129 58 my $no = $self->fileno;
1130 58 ▶ $no = '?' unless defined $no;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $no 1 57 58
1131 58 ▶ print "DESTROY $no...\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $T::debug 0 58 58
1132 58 ▶ return undef unless $self && ref($self) && reftype($self) eq 'GLOB';
Branch: 1 branch
BranchTrueFalseTotal
unless $self and ref $self and builtin::reftype($self) eq "GLOB" 1 57 58
Condition50%3/6
$self and ref $self and builtin::reftype($self) eq "GLOB"
!ll&&!rl&&r
0157
$self and ref $self
!ll&&!rl&&r
0058
MC/DC33%1/3
$self and ref $self and builtin::reftype($self) eq "GLOB"
$self ref $self builtin::reftype($self) eq "GLOB"
Truth table50%2/4
A and B and C
A= $selfB= ref $selfC= builtin::reftype($self) eq "GLOB"
ABCresult
0XX0
10X0
1100
1111
1133 0 ${*$self}{ie_event}->cancel
1134 57 ▶ if ${*$self}{ie_event};
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"ie_event"} 0 57 57
1135 }
1136  
1137  
1138 sub TIEHANDLE
1139 585 ▶{
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
1140 585 my ($pkg, $self) = @_;
1141 585 return $self;
1142 }
1143  
1144 sub PRINTF
1145 3 ▶{
Subroutine PRINTF: called CC=1 SCAR=0.0
1146 3 my $self = shift;
1147 3 $self->print(sprintf(shift, @_));
1148 }
1149  
1150 sub READLINE
1151 1299 ▶{
Subroutine READLINE: called CC=2 SCAR=6.9
1152 1299 my $self = shift;
1153 1299 ▶ wantarray ? $self->getlines : $self->getline;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 262 1037 1299
1154 }
1155  
1156 sub ie_desc
1157 0 ▶{
Subroutine ie_desc: not called CC=3 SCAR=24.8
1158 0 my ($self, $new) = @_;
1159 0 ▶ my $r = ${*$self}{ie_desc} || "no description";
Condition0%0/2
do { *$self }->{'ie_desc'} || 'no description'
l!l
00
MC/DC0%0/1
do { *$self }->{'ie_desc'} || 'no description'
do { *$self }->{'ie_desc'}
Truth table0%0/2
A
A= do { *$self }->{'ie_desc'}
Aresult
11
00
1160 0 ▶ ${*$self}{ie_desc} = $new if defined $new;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new 0 0 0
1161 0 return $r;
1162 }
1163  
1164 60 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1165  
1166 60 *PRINT = \&print;
1167  
1168 60 *READ = \&sysread;
1169  
1170 # from IO::Handle
1171 60 *read = \&sysread;
1172  
1173 60 *WRITE = \&syswrite;
1174  
1175 60 *CLOSE = \&close;
1176  
1177 60 *EOF = \&eof;
1178  
1179 60 *TELL = \&tell;
1180  
1181 60 *FILENO = \&fileno;
1182  
1183 60 *SEEK = \&seek;
1184  
1185 60 *BINMODE = \&binmode;
1186  
1187 60 *OPEN = \&open;
1188  
1189 60 *GETC = \&getc;
1190  
1191 60 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1192  
1193 60 }{package IO::Event::Socket::INET;
1194  
1195 # XXX version 1.26 required for IO::Socket::INET
1196  
1197 60 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1198 60 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1199 60 ▶use List::MoreUtils qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
1200  
1201 60 our @ISA = qw(IO::Event);
1202  
1203 sub new
1204 78 ▶{
Subroutine new: called CC=17 SCAR=33.4
1205 78 my ($pkg, $a, $b, %sock) = @_;
1206  
1207 # emulate behavior in the IO::Socket::INET API
1208 78 ▶ if (! %sock && ! $b) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %sock || $b) { } 0 78 78
Condition33%1/3
%sock || $b
l!l&&r!l&&!r
7800
MC/DC0%0/2
%sock || $b
%sock $b
Truth table33%1/3
A || B
A= %sockB= $b
ABresult
1X1
011
000
1209 0 $sock{PeerAddr} = $a;
1210 } else {
1211 78 $sock{$a} = $b;
1212 }
1213  
1214 78 ▶ my $handler = $sock{Handler} || (caller)[0];
Condition33%1/3
$sock{'Handler'} || (caller)[0]
l!l&&r!l&&!r
7800
MC/DC0%0/2
$sock{'Handler'} || (caller)[0]
$sock{'Handler'} (caller)[0]
Truth table33%1/3
A || B
A= $sock{'Handler'}B= (caller)[0]
ABresult
1X1
011
000
1215 78 delete $sock{Handler};
1216  
1217 78 my $timeout;
1218 78 ▶ if ($sock{Timeout}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sock{"Timeout"}) 0 78 78
1219 0 $timeout = $sock{Timeout};
1220 0 delete $sock{Timeout};
1221 }
1222  
1223 78 $sock{Blocking} = 0;
1224  
1225 78 my (%ds) = %sock;
1226  
1227 78 delete $sock{Description};
1228  
1229 78 require IO::Socket::INET;
1230 78 my $fh = new IO::Socket::INET(%sock);
1231 78 ▶ return undef unless defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 78 78
1232  
1233 78 ▶ my $peer = any { /Peer/ } keys %sock;
Subroutine __ANON__: called CC=1 SCAR=0.0
1234 78 ▶ if ($peer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($peer) 66 12 78
1235 $ds{LocalPort} = $fh->sockport
1236 66 ▶ unless defined $ds{LocalPort};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ds{"LocalPort"} 66 0 66
1237 $ds{LocalHost} = $fh->sockhost
1238 66 ▶ unless defined $ds{LocalHost};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ds{"LocalHost"} 66 0 66
1239 }
1240  
1241 my $desc = $ds{Description}
1242 || join(" ",
1243 map {
1244 78 ▶ defined $ds{$_}
Branch: 1 branch
BranchTrueFalseTotal
defined $ds{$_} ? : 36 0 36
Condition66%2/3
$ds{'Description'} || join(' ', map({defined $ds{$_} ? "$_=$ds{$_}" : $_;} sort(keys %ds)))
l!l&&r!l&&!r
7260
MC/DC0%0/2
$ds{'Description'} || join(' ', map({defined $ds{$_} ? "$_=$ds{$_}" : $_;} sort(keys %ds)))
$ds{'Description'} join(' ', map({defined $ds{$_} ? "$_=$ds{$_}" : $_;} sort(keys %ds)))
Truth table66%2/3
A || B
A= $ds{'Description'}B= join(' ', map({defined $ds{$_} ? "$_=$ds{$_}" : $_;} sort(keys %ds)))
ABresult
1X1
011
000
1245 ? "$_=$ds{$_}"
1246 : $_
1247 } sort keys %ds);
1248  
1249 78 ▶ return undef unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 78 78
1250 78 my $self = $pkg->SUPER::new($fh, $handler, $desc);
1251 78 bless $self, $pkg;
1252 $self->listener(1)
1253 78 ▶ if $sock{Listen};
Branch: 1 branch
BranchTrueFalseTotal
if $sock{"Listen"} 12 66 78
1254 78 $fh->blocking(0); # XXX may be redundant
1255 78 ▶ if ($peer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($peer) 66 12 78
1256 66 ▶ if ($fh->connected()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh->connected) { } 66 0 66
1257 66 $self->ie_invoke(0, 'ie_connected');
1258 } else {
1259 0 ${*$self}{ie_connecting} = 1;
1260 0 $self->writeevents(1);
1261 0 ▶ ${*$self}{ie_connect_timeout} = $timeout + time
Branch: 1 branch
BranchTrueFalseTotal
if $timeout 0 0 0
1262 if $timeout;
1263 }
1264 }
1265 78 ▶ ${*$self}{ie_socket_timeout} = $timeout
Branch: 1 branch
BranchTrueFalseTotal
if $timeout 0 78 78
1266 if $timeout;
1267  
1268 78 return $self;
1269 }
1270  
1271 }{
1272 60 package IO::Event::Socket::UNIX;
1273  
1274 60 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1275 60 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1276  
1277 60 our @ISA = qw(IO::Event);
1278  
1279 sub new
1280 0 ▶{
Subroutine new: not called CC=9 SCAR=45.0
1281 0 my ($pkg, $a, $b, %sock) = @_;
1282  
1283 # emulate behavior in the IO::Socket::INET API
1284 0 ▶ if (! %sock && ! $b) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %sock || $b) { } 0 0 0
Condition0%0/3
%sock || $b
l!l&&r!l&&!r
000
MC/DC0%0/2
%sock || $b
%sock $b
Truth table0%0/3
A || B
A= %sockB= $b
ABresult
1X1
011
000
1285 0 $sock{Peer} = $a;
1286 } else {
1287 0 $sock{$a} = $b;
1288 }
1289  
1290 0 ▶ my $handler = $sock{Handler} || (caller)[0];
Condition0%0/3
$sock{'Handler'} || (caller)[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$sock{'Handler'} || (caller)[0]
$sock{'Handler'} (caller)[0]
Truth table0%0/3
A || B
A= $sock{'Handler'}B= (caller)[0]
ABresult
1X1
011
000
1291 0 delete $sock{Handler};
1292  
1293 my $desc = $sock{Description}
1294 0 ▶ || join(" ", map { "$_=$sock{$_}" } sort keys %sock);
Condition0%0/3
$sock{'Description'} || join(' ', map({"$_=$sock{$_}";} sort(keys %sock)))
l!l&&r!l&&!r
000
MC/DC0%0/2
$sock{'Description'} || join(' ', map({"$_=$sock{$_}";} sort(keys %sock)))
$sock{'Description'} join(' ', map({"$_=$sock{$_}";} sort(keys %sock)))
Truth table0%0/3
A || B
A= $sock{'Description'}B= join(' ', map({"$_=$sock{$_}";} sort(keys %sock)))
ABresult
1X1
011
000
1295 0 delete $sock{Description};
1296  
1297 0 require IO::Socket::UNIX;
1298 0 my $fh = new IO::Socket::UNIX(%sock);
1299  
1300 0 ▶ return undef unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 0 0
1301 0 my $self = $pkg->SUPER::new($fh, $handler, $desc);
1302 0 bless $self, $pkg;
1303 $self->listener(1)
1304 0 ▶ if $sock{Listen};
Branch: 1 branch
BranchTrueFalseTotal
if $sock{"Listen"} 0 0 0
1305 0 $fh->blocking(0);
1306 0 ▶ if ($sock{Peer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sock{"Peer"}) 0 0 0
1307 0 ▶ if ($fh->connected()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh->connected) { } 0 0 0
1308 0 $self->ie_invoke(0, 'ie_connected');
1309 } else {
1310 0 ${*$self}{ie_connecting} = 1;
1311 0 $self->writeevents(1);
1312 }
1313 }
1314  
1315 0 return $self;
1316 }
1317  
1318 }#end package
1319 60 1;
1320  
↑ Summary Event/Emulate.pm »