Event.pm

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