Event/Emulate.pm

filter: Statementstmt 69.1% 217 / 314 Branchbran 51.8% 57 / 110 Conditioncond 47.5% 19 / 40 MC/DCmcdc 16.0% 4 / 25 Subroutinesub 69.8% 37 / 53 Podpod 0.0% 0 / 10 totaltotal 60.5% 334 / 552 CC 79 SCAR 39.1
CC
79
Cov
63%
ie_loop
190.2
now
19.1
invoke_idlers
16.5
CRAP 49.9
« Event.pm ↑ Summary Event/Callback.pm »
1  
2 #
3 # Use a pure-perl event handler that kinda emulates's Event
4 # for IO::Event's event handler.
5 #
6  
7 20 my $sdebug = 0;
8  
9 {
10 package IO::Event::Emulate;
11  
12 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 20 our @ISA = qw(IO::Event::Common);
16  
17 20 my %want_read;
18 my %want_write;
19 20 my %want_exception;
20 20 my %active;
21  
22 20 my $rin = '';
23 20 my $win = '';
24 20 my $ein = '';
25  
26 20 my $unloop;
27  
28 sub import
29 0 ▶{
Subroutine import: not called CC=1 SCAR=6.9
30 0 require IO::Event;
31 0 IO::Event->import('emulate_Event');
32 }
33  
34 sub new
35 195 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
36 195 my ($pkg, @stuff) = @_;
37 195 $pkg->SUPER::new(@stuff);
38 }
39  
40 # a replacement for Event::loop
41 sub ie_loop
42 4 ▶{
Subroutine ie_loop: called CC=31 SCAR=52.5
Pod undocumented
43 4 $unloop = 0;
44 4 my ($rout, $wout, $eout);
45 4 for(;;) {
46 307 ▶ print STDERR "EMULATE LOOP-TOP\n" if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $sdebug 0 307 307
47 307 ▶ last if $unloop;
Branch: 1 branch
BranchTrueFalseTotal
if $unloop 2 305 307
48  
49 305 my $timer_timeout = IO::Event::Emulate::Timer->get_time_to_timer;
50  
51 305 ▶ my $timeout = $timer_timeout || IO::Event::Emulate::Idle->get_time_to_idle;
Condition100%3/3
$timer_timeout || 'IO::Event::Emulate::Idle'->get_time_to_idle
l!l&&r!l&&!r
244160
MC/DC100%2/2
$timer_timeout || 'IO::Event::Emulate::Idle'->get_time_to_idle
$timer_timeout 'IO::Event::Emulate::Idle'->get_time_to_idle
Truth table100%3/3
A || B
A= $timer_timeoutB= 'IO::Event::Emulate::Idle'->get_time_to_idle
ABresult
1X1
011
000
52  
53 305 ▶ if ($sdebug > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sdebug > 3) 0 305 305
54 0 print STDERR "Readers:\n";
55 0 for my $ioe (values %want_read) {
56 0 print STDERR "\t${*$ioe}{ie_desc}\n";
57 }
58 0 print STDERR "Writers:\n";
59 0 for my $ioe (values %want_write) {
60 0 print STDERR "\t${*$ioe}{ie_desc}\n";
61 }
62 0 print STDERR "Exceptions:\n";
63 0 for my $ioe (values %want_exception) {
64 0 print STDERR "\t${*$ioe}{ie_desc}\n";
65 }
66 }
67 305 my ($nfound, $timeleft) = select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
68 305 ▶ print STDERR "SELECT: N$nfound\n" if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $sdebug 0 305 305
69 305 ▶ if ($nfound) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nfound) 196 109 305
70 EVENT:
71 {
72 196 ▶ if ($rout) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rout) 196 0 196
73 196 for my $ioe (values %want_read) {
74 357 ▶ next unless vec($rout, ${*$ioe}{ie_fileno}, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless vec $rout, do { *$ioe }->{"ie_fileno"}, 1 135 222 357
75 222 my $ret = $ioe->ie_dispatch_read(${*$ioe}{ie_fh});
76 220 ▶ if ($ret && vec($wout, ${*$ioe}{ie_fileno}, 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret and vec $wout, do { *$ioe }->{"ie_fileno"}, 1) 0 220 220
Condition66%2/3
$ret and vec $wout, do { *$ioe }->{"ie_fileno"}, 1
!ll&&!rl&&r
182380
MC/DC0%0/2
$ret and vec $wout, do { *$ioe }->{"ie_fileno"}, 1
$ret vec $wout, do { *$ioe }->{"ie_fileno"}, 1
Truth table66%2/3
A and B
A= $retB= vec $wout, do { *$ioe }->{"ie_fileno"}, 1
ABresult
0X0
100
111
77 0 vec($wout, ${*$ioe}{ie_fileno}, 1) = 0;
78 0 $nfound--;
79 }
80 220 ▶ if ($ret && vec($eout, ${*$ioe}{ie_fileno}, 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret and vec $eout, do { *$ioe }->{"ie_fileno"}, 1) 0 220 220
Condition66%2/3
$ret and vec $eout, do { *$ioe }->{"ie_fileno"}, 1
!ll&&!rl&&r
182380
MC/DC0%0/2
$ret and vec $eout, do { *$ioe }->{"ie_fileno"}, 1
$ret vec $eout, do { *$ioe }->{"ie_fileno"}, 1
Truth table66%2/3
A and B
A= $retB= vec $eout, do { *$ioe }->{"ie_fileno"}, 1
ABresult
0X0
100
111
81 0 vec($eout, ${*$ioe}{ie_fileno}, 1) = 0;
82 0 $nfound--;
83 }
84 220 $nfound--;
85 220 ▶ last EVENT unless $nfound > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $nfound > 0 194 26 220
86 }
87 }
88 0 ▶ if ($wout) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wout) 0 0 0
89 0 for my $ioe (values %want_write) {
90 0 ▶ next unless vec($wout, ${*$ioe}{ie_fileno}, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless vec $wout, do { *$ioe }->{"ie_fileno"}, 1 0 0 0
91 0 my $ret = $ioe->ie_dispatch_write(${*$ioe}{ie_fh});
92 0 ▶ if ($ret && vec($eout, ${*$ioe}{ie_fileno}, 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret and vec $eout, do { *$ioe }->{"ie_fileno"}, 1) 0 0 0
Condition0%0/3
$ret and vec $eout, do { *$ioe }->{"ie_fileno"}, 1
!ll&&!rl&&r
000
MC/DC0%0/2
$ret and vec $eout, do { *$ioe }->{"ie_fileno"}, 1
$ret vec $eout, do { *$ioe }->{"ie_fileno"}, 1
Truth table0%0/3
A and B
A= $retB= vec $eout, do { *$ioe }->{"ie_fileno"}, 1
ABresult
0X0
100
111
93 0 vec($eout, ${*$ioe}{ie_fileno}, 1) = 0;
94 0 $nfound--;
95 }
96 0 $nfound--;
97 0 ▶ last EVENT unless $nfound > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $nfound > 0 0 0 0
98 }
99 }
100 0 ▶ if ($eout) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eout) 0 0 0
101 0 for my $ioe (values %want_exception) {
102 0 ▶ next unless vec($eout, ${*$ioe}{ie_fileno}, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless vec $eout, do { *$ioe }->{"ie_fileno"}, 1 0 0 0
103 0 $ioe->ie_dispatch_exception(${*$ioe}{ie_fh});
104 0 $nfound--;
105 0 ▶ last EVENT unless $nfound > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $nfound > 0 0 0 0
106 }
107 }
108 }
109 }
110 303 ▶ IO::Event::Emulate::Timer->invoke_timers if $timer_timeout;
Branch: 1 branch
BranchTrueFalseTotal
if $timer_timeout 243 60 303
111 303 IO::Event::Emulate::Idle->invoke_idlers($nfound == 0);
112 }
113 2 ▶ die unless ref($unloop);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $unloop 0 2 2
114 2 my @r = @$unloop;
115 2 shift(@r);
116 2 ▶ return $r[0] if @r == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @r == 1 2 0 2
117 0 return @r;
118 }
119  
120 sub loop
121 4 ▶{
Subroutine loop: called CC=1 SCAR=0.0
Pod undocumented
122 4 ie_loop(@_);
123 }
124  
125 sub timer
126 3 ▶{
Subroutine timer: called CC=1 SCAR=0.0
Pod undocumented
127 3 shift;
128 3 IO::Event::Emulate::Timer->new(@_);
129 }
130  
131 sub idle
132 1 ▶{
Subroutine idle: called CC=1 SCAR=0.0
Pod undocumented
133 1 shift;
134 1 IO::Event::Emulate::Idle->new(@_);
135 }
136  
137 sub unloop_all
138 2 ▶{
Subroutine unloop_all: called CC=1 SCAR=0.0
Pod undocumented
139 2 $unloop = [1, @_];
140 }
141  
142 sub set_write_polling
143 195 ▶{
Subroutine set_write_polling: called CC=3 SCAR=11.7
Pod undocumented
144 195 my ($self, $new) = @_;
145 195 my $fileno = ${*$self}{ie_fileno};
146 195 ▶ if ($new) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new) { } 0 195 195
147 0 vec($win, $fileno, 1) = 1;
148 0 $want_write{$fileno} = $want_exception{$fileno} = $self;
149 } else {
150 195 vec($win, $fileno, 1) = 0;
151 195 delete $want_write{$fileno};
152 delete $want_exception{$fileno}
153 195 ▶ unless $want_read{$fileno};
Branch: 1 branch
BranchTrueFalseTotal
unless $want_read{$fileno} 0 195 195
154 }
155 195 $ein = $rin | $win;
156 }
157  
158 sub set_read_polling
159 378 ▶{
Subroutine set_read_polling: called CC=4 SCAR=13.9
Pod undocumented
160 378 my ($self, $new) = @_;
161 378 my $fileno = ${*$self}{ie_fileno};
162 378 ▶ if ($new) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new) { } 195 183 378
163 195 vec($rin, $fileno, 1) = 1;
164 195 $want_read{$fileno} = $want_exception{$fileno} = $self;
165 } else {
166 183 ▶ if (defined $fileno) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fileno) 183 0 183
167 183 vec($rin, $fileno, 1) = 0;
168 183 delete $want_read{$fileno};
169 delete $want_exception{$fileno}
170 183 ▶ unless $want_write{$fileno}
Branch: 1 branch
BranchTrueFalseTotal
unless $want_write{$fileno} 183 0 183
171 }
172 }
173 378 $ein = $rin | $win;
174 }
175  
176 sub ie_register
177 195 ▶{
Subroutine ie_register: called CC=1 SCAR=0.0
Pod undocumented
178 195 my ($self) = @_;
179 195 my ($fh, $fileno) = $self->SUPER::ie_register();
180 195 $active{$fileno} = $self;
181 195 $self->readevents(! ${*$self}{ie_readclosed});
182 195 $self->writeevents(0);
183 }
184  
185 sub ie_deregister
186 164 ▶{
Subroutine ie_deregister: called CC=1 SCAR=0.0
Pod undocumented
187 164 my ($self) = @_;
188 164 $self->SUPER::ie_deregister();
189 164 delete $active{${*$self}{ie_fileno}};
190 }
191  
192 20 }{package IO::Event::Emulate::Timer;
193  
194 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
195 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
196 20 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
197 20 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
198 20 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
199  
200 20 our @ISA = qw(IO::Event);
201 20 our %timers = ();
202 20 our %levels = ();
203 20 our %next = ();
204  
205 20 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=9.2
206 20 for $a (qw(at after interval hard cb desc prio repeat timeout)) {
207 180 my $attrib = $a;
208 20 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
209 180 ▶ *{"IO::Event::Emulate::Timer::$a"} = sub {
Subroutine __ANON__: not called CC=2 SCAR=15.4
210 0 my $self = shift;
211 0 ▶ return $self->{$attrib} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
212 0 my $val = shift;
213 0 $self->{$attrib} = $val;
214 0 return $val;
215 180 };
216 }
217 }
218  
219 20 my $tcount = 1;
220  
221 20 my @timers;
222  
223 sub get_time_to_timer
224 305 ▶{
Subroutine get_time_to_timer: called CC=4 SCAR=13.9
225 305 @timers = sort { $a <=> $b } keys %next;
226 305 my $t = time;
227 305 ▶ if (@timers) {
Branch: 1 branch
BranchTrueFalseTotal
if (@timers) 244 61 305
228 244 ▶ if ($timers[0] > $t) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timers[0] > $t) { } 244 0 244
229 244 my $timeout = $timers[0] - $t;
230 244 ▶ $timeout = 0.01 if $timeout < 0.01;
Branch: 1 branch
BranchTrueFalseTotal
if $timeout < "0.01" 1 243 244
231 244 return $timeout;
232 } else {
233 0 return 0.01;
234 }
235 }
236 61 return undef;
237 }
238  
239 sub invoke_timers
240 243 ▶{
Subroutine invoke_timers: called CC=7 SCAR=19.5
241 243 ▶ while (@timers && $timers[0] < time) {
Branch: 1 branch
BranchTrueFalseTotal
if (@timers and $timers[0] < &IO::Event::Emulate::Timer::time()) 108 243 351
Condition100%3/3
@timers and $timers[0] < &IO::Event::Emulate::Timer::time()
!ll&&!rl&&r
4239108
MC/DC100%2/2
@timers and $timers[0] < &IO::Event::Emulate::Timer::time()
@timers $timers[0] < &IO::Event::Emulate::Timer::time()
Truth table100%3/3
A and B
A= @timersB= $timers[0] < &IO::Event::Emulate::Timer::time()
ABresult
0X0
100
111
242 108 ▶ print STDERR "Ti" if $sdebug;
Branch: 1 branch
BranchTrueFalseTotal
if $sdebug 0 108 108
243 108 my $t = shift(@timers);
244 108 my $te = delete $next{$t};
245 108 for my $tnum (keys %$te) {
246 108 my $timer = $te->{$tnum};
247 108 ▶ next unless $timer->{next};
Branch: 1 branch
BranchTrueFalseTotal
unless $timer->{"next"} 0 108 108
248 108 ▶ next unless $timer->{next} eq $t;
Branch: 1 branch
BranchTrueFalseTotal
unless $timer->{"next"} eq $t 12 96 108
249 96 $timer->now();
250 }
251 }
252 }
253  
254 sub new
255 3 ▶{
Subroutine new: called CC=4 SCAR=14.8
256 3 my ($pkg, %param) = @_;
257 3 ▶ confess unless $param{cb};
Branch: 1 branch
BranchTrueFalseTotal
unless $param{"cb"} 0 3 3
258 3 ▶ die if $param{after} && $param{at};
Branch: 1 branch
BranchTrueFalseTotal
if $param{"after"} and $param{"at"} 0 3 3
Condition33%1/3
$param{"after"} and $param{"at"}
!ll&&!rl&&r
300
MC/DC0%0/2
$param{"after"} and $param{"at"}
$param{"after"} $param{"at"}
Truth table33%1/3
A and B
A= $param{"after"}B= $param{"at"}
ABresult
0X0
100
111
259 3 my $timer = bless {
260 tcount => $tcount,
261 last_time => time,
262 %param
263 }, __PACKAGE__;
264 3 $timers{$tcount++} = $timer;
265 3 $timer->schedule;
266 3 return $timer;
267 }
268  
269 sub schedule
270 124 ▶{
Subroutine schedule: called CC=9 SCAR=27.7
271 124 my ($self) = @_;
272 124 my $next;
273 124 ▶ if ($self->{invoked}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->{'invoked'}) { } 96 28 124
elsif ($self->{'at'}) { } 0 28 28
elsif ($self->{'after'}) { } 0 28 28
elsif ($self->{'interval'}) { } 28 0 28
274 96 ▶ if ($self->{interval}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'interval'}) { } 96 0 96
275 96 $next = $self->{last_time} + $self->{interval};
276 96 ▶ if ($self->{hard} && $self->{next}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"hard"} and $self->{"next"}) 0 96 96
Condition33%1/3
$self->{"hard"} and $self->{"next"}
!ll&&!rl&&r
9600
MC/DC0%0/2
$self->{"hard"} and $self->{"next"}
$self->{"hard"} $self->{"next"}
Truth table33%1/3
A and B
A= $self->{"hard"}B= $self->{"next"}
ABresult
0X0
100
111
277 0 $next = $self->{next} + $self->{interval};
278 }
279 } else {
280 0 $next = undef;
281 }
282 } elsif ($self->{at}) {
283 0 $next = $self->{at};
284 } elsif ($self->{after}) {
285 0 $next = $self->{after} + time;
286 } elsif ($self->{interval}) {
287 28 $next = $self->{interval} + time;
288 } else {
289 0 die;
290 }
291 124 ▶ if ($next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next) { } 124 0 124
292 124 $next{$next}{$self->{tcount}} = $self;
293 124 $self->{next} = $next;
294 } else {
295 0 $self->{next} = 0;
296 0 $self->stop();
297 }
298 }
299  
300 sub start
301 25 ▶{
Subroutine start: called CC=1 SCAR=0.0
302 25 my ($self) = @_;
303 25 $timers{$self->{tcount}} = $self;
304 25 delete $self->{stopped};
305 25 $self->schedule;
306 }
307  
308 sub again
309 25 ▶{
Subroutine again: called CC=1 SCAR=0.0
310 25 my ($self) = @_;
311 25 $self->{last_time} = time;
312 25 $self->start;
313 }
314  
315 sub now
316 96 ▶{
Subroutine now: called CC=4 SCAR=14.1
317 96 my ($self) = @_;
318 96 $self->{last_time} = time;
319 96 ▶ local($levels{$self->{tcount}}) = ($levels{$self->{tcount}} || 0)+1;
Condition50%1/2
$IO::Event::Emulate::Timer::levels{$self->{'tcount'}} || 0
l!l
096
MC/DC0%0/1
$IO::Event::Emulate::Timer::levels{$self->{'tcount'}} || 0
$IO::Event::Emulate::Timer::levels{$self->{'tcount'}}
Truth table50%1/2
A
A= $IO::Event::Emulate::Timer::levels{$self->{'tcount'}}
Aresult
11
00
320 96 $self->{invoked}++;
321 96 ▶ if (reftype($self->{cb}) eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::reftype($self->{'cb'}) eq 'CODE') { } 4 92 96
elsif (builtin::reftype($self->{'cb'}) eq 'ARRAY') { } 92 0 92
322 4 $self->{cb}->($self);
323 } elsif (reftype($self->{cb}) eq 'ARRAY') {
324 92 my ($o, $m) = @{$self->{cb}};
325 92 $o->$m($self);
326 } else {
327 0 die;
328 }
329 96 $self->schedule;
330 }
331  
332  
333 sub stop
334 25 ▶{
Subroutine stop: called CC=1 SCAR=0.0
335 25 my ($self) = @_;
336 25 delete $timers{$self->{tcount}};
337 25 $self->{stopped} = time;
338 }
339  
340 sub cancel
341 0 ▶{
Subroutine cancel: not called CC=1 SCAR=6.9
342 0 my ($self) = @_;
343 0 $self->{cancelled} = time;
344 0 delete $timers{$self->{tcount}};
345 }
346  
347 sub is_cancelled
348 0 ▶{
Subroutine is_cancelled: not called CC=1 SCAR=6.9
349 0 my ($self) = @_;
350 0 return $self->{cancelled};
351 }
352  
353 sub is_active
354 0 ▶{
Subroutine is_active: not called CC=1 SCAR=6.9
355 0 my ($self) = @_;
356 0 return exists $timers{$self->{tcount}};
357 }
358  
359 sub is_running
360 0 ▶{
Subroutine is_running: not called CC=1 SCAR=6.9
361 0 my ($self) = @_;
362 0 return $levels{$self->{tcount}};
363 }
364  
365 sub is_suspended
366 0 ▶{
Subroutine is_suspended: not called CC=1 SCAR=6.9
367 0 my ($self) = @_;
368 0 return 0;
369 }
370  
371 sub pending
372 0 ▶{
Subroutine pending: not called CC=1 SCAR=6.9
373 0 return;
374 }
375  
376  
377 20 }{package IO::Event::Emulate::Idle;
378  
379 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
380 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
381 20 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
382 20 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
383 20 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
384  
385 20 our @ISA = qw(IO::Event);
386 20 our %timers = ();
387 20 our %levels = ();
388 20 our %next = ();
389  
390 20 my $icount = 0;
391 20 my %idlers;
392  
393 20 our $time_to_idle_timeout = 1;
394  
395 sub new
396 1 ▶{
Subroutine new: called CC=4 SCAR=15.0
397 1 my ($pkg, %param) = @_;
398 1 ▶ confess unless $param{cb};
Branch: 1 branch
BranchTrueFalseTotal
unless $param{"cb"} 0 1 1
399 1 ▶ die if $param{after} && $param{at};
Branch: 1 branch
BranchTrueFalseTotal
if $param{"after"} and $param{"at"} 0 1 1
Condition33%1/3
$param{"after"} and $param{"at"}
!ll&&!rl&&r
100
MC/DC0%0/2
$param{"after"} and $param{"at"}
$param{"after"} $param{"at"}
Truth table33%1/3
A and B
A= $param{"after"}B= $param{"at"}
ABresult
0X0
100
111
400 1 my $idler = bless {
401 icount => $icount,
402 last_time => time,
403 %param
404 }, __PACKAGE__;
405 1 $idlers{$icount++} = $idler;
406 1 return $idler;
407 }
408  
409 sub get_time_to_idle
410 61 ▶{
Subroutine get_time_to_idle: called CC=2 SCAR=6.9
411 61 ▶ return undef unless %idlers;
Branch: 1 branch
BranchTrueFalseTotal
unless %idlers 60 1 61
412 1 return $time_to_idle_timeout;
413 }
414  
415 sub start
416 0 ▶{
Subroutine start: not called CC=1 SCAR=6.9
417 0 my ($self) = @_;
418 0 $idlers{$self->{icount}} = $self;
419 0 delete $self->{stopped};
420 0 $self->schedule;
421 }
422  
423 sub again
424 0 ▶{
Subroutine again: not called CC=1 SCAR=6.9
425 0 my ($self) = @_;
426 0 $self->{last_time} = time;
427 0 $self->start;
428 }
429  
430 sub invoke_idlers
431 303 ▶{
Subroutine invoke_idlers: called CC=7 SCAR=28.0
432 303 my ($pkg, $is_idle) = @_;
433 303 for my $idler (values %idlers) {
434 1 ▶ if ($idler->{min} && (time - $idler->{last_time}) < $idler->{min}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idler->{"min"} and &IO::Event::Emulate::Idle::time() - $idler->{"last_time"} < $idler->{"min"}) 0 1 1
Condition33%1/3
$idler->{"min"} and &IO::Event::Emulate::Idle::time() - $idler->{"last_time"} < $idler->{"min"}
!ll&&!rl&&r
100
MC/DC0%0/2
$idler->{"min"} and &IO::Event::Emulate::Idle::time() - $idler->{"last_time"} < $idler->{"min"}
$idler->{"min"} &IO::Event::Emulate::Idle::time() - $idler->{"last_time"} < $idler->{"min"}
Truth table33%1/3
A and B
A= $idler->{"min"}B= &IO::Event::Emulate::Idle::time() - $idler->{"last_time"} < $idler->{"min"}
ABresult
0X0
100
111
435 0 next;
436 }
437 1 ▶ unless ($is_idle) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_idle) 0 1 1
438 0 ▶ next unless $idler->{max};
Branch: 1 branch
BranchTrueFalseTotal
unless $idler->{"max"} 0 0 0
439 0 ▶ next unless (time - $idler->{last_time}) > $idler->{max};
Branch: 1 branch
BranchTrueFalseTotal
unless &IO::Event::Emulate::Idle::time() - $idler->{"last_time"} > $idler->{"max"} 0 0 0
440 }
441 1 $idler->now;
442 }
443 }
444  
445 sub now
446 1 ▶{
Subroutine now: called CC=9 SCAR=29.5
447 1 my ($self) = @_;
448 1 $self->{last_time} = time;
449 1 ▶ local($levels{$self->{icount}}) = ($levels{$self->{icount}} || 0)+1;
Condition50%1/2
$IO::Event::Emulate::Idle::levels{$self->{'icount'}} || 0
l!l
01
MC/DC0%0/1
$IO::Event::Emulate::Idle::levels{$self->{'icount'}} || 0
$IO::Event::Emulate::Idle::levels{$self->{'icount'}}
Truth table50%1/2
A
A= $IO::Event::Emulate::Idle::levels{$self->{'icount'}}
Aresult
11
00
450 1 ▶ if (defined($self->{reentrant}) && ! $self->{reentrant} && $self->{icount}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"reentrant"} and not $self->{"reentrant"} and $self->{"icount"}) 0 1 1
Condition33%2/6
defined $self->{"reentrant"} and not $self->{"reentrant"} and $self->{"icount"}
!ll&&!rl&&r
010
defined $self->{"reentrant"} and not $self->{"reentrant"}
!ll&&!rl&&r
001
MC/DC0%0/3
defined $self->{"reentrant"} and not $self->{"reentrant"} and $self->{"icount"}
defined $self->{"reentrant"} not $self->{"reentrant"} $self->{"icount"}
Truth table25%1/4
A and not(B) and C
A= defined $self->{"reentrant"}B= not $self->{"reentrant"}C= $self->{"icount"}
ABCresult
0XX0
10X0
1100
1111
451 0 return;
452 }
453 1 $self->{invoked}++;
454 1 ▶ if (defined($self->{repeat}) && ! $self->{repeat}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"repeat"} and not $self->{"repeat"}) 1 0 1
Condition33%1/3
defined $self->{"repeat"} and not $self->{"repeat"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $self->{"repeat"} and not $self->{"repeat"}
defined $self->{"repeat"} not $self->{"repeat"}
Truth table33%1/3
A and not(B)
A= defined $self->{"repeat"}B= not $self->{"repeat"}
ABresult
0X0
100
111
455 1 $self->cancel;
456 }
457 1 ▶ if (reftype($self->{cb}) eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::reftype($self->{'cb'}) eq 'CODE') { } 1 0 1
elsif (builtin::reftype($self->{'cb'}) eq 'ARRAY') { } 0 0 0
458 1 $self->{cb}->($self);
459 } elsif (reftype($self->{cb}) eq 'ARRAY') {
460 0 my ($o, $m) = @{$self->{cb}};
461 0 $o->$m($self);
462 } else {
463 0 die;
464 }
465 1 $self->{last_time} = time;
466 }
467  
468  
469 sub stop
470 0 ▶{
Subroutine stop: not called CC=1 SCAR=6.9
471 0 my ($self) = @_;
472 0 delete $idlers{$self->{icount}};
473 0 $self->{stopped} = time;
474 }
475  
476 sub cancel
477 1 ▶{
Subroutine cancel: called CC=1 SCAR=0.0
478 1 my ($self) = @_;
479 1 $self->{cancelled} = time;
480 1 delete $idlers{$self->{icount}};
481 }
482  
483 sub is_cancelled
484 0 ▶{
Subroutine is_cancelled: not called CC=1 SCAR=6.9
485 0 my ($self) = @_;
486 0 return $self->{cancelled};
487 }
488  
489 sub is_active
490 0 ▶{
Subroutine is_active: not called CC=1 SCAR=6.9
491 0 my ($self) = @_;
492 0 return exists $idlers{$self->{icount}};
493 }
494  
495 sub is_running
496 0 ▶{
Subroutine is_running: not called CC=1 SCAR=6.9
497 0 my ($self) = @_;
498 0 return $levels{$self->{icount}};
499 }
500  
501 sub is_suspended
502 0 ▶{
Subroutine is_suspended: not called CC=1 SCAR=6.9
503 0 my ($self) = @_;
504 0 return 0;
505 }
506  
507 sub pending
508 0 ▶{
Subroutine pending: not called CC=1 SCAR=6.9
509 0 return;
510 }
511  
512  
513 }#end package
514 20 1;
« Event.pm ↑ Summary Event/Callback.pm »