| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 307 | ▶ | last if $unloop; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 305 | ▶ | if ($sdebug > 3) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 305 | ▶ | if ($nfound) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | EVENT: | ||||||||||||||||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 196 | ▶ | if ($rout) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 196 | for my $ioe (values %want_read) { | |||||||||||||||||||||||||||||||||||||||||
| 74 | 357 | ▶ | next unless vec($rout, ${*$ioe}{ie_fileno}, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 222 | my $ret = $ioe->ie_dispatch_read(${*$ioe}{ie_fh}); | |||||||||||||||||||||||||||||||||||||||||
| 76 | 220 | ▶ | if ($ret && vec($wout, ${*$ioe}{ie_fileno}, 1)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ret and vec $wout, do {
*$ioe
}->{"ie_fileno"}, 1
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$ret and vec $eout, do {
*$ioe
}->{"ie_fileno"}, 1
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ($wout) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | for my $ioe (values %want_write) { | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | next unless vec($wout, ${*$ioe}{ie_fileno}, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $ret = $ioe->ie_dispatch_write(${*$ioe}{ie_fh}); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ($ret && vec($eout, ${*$ioe}{ie_fileno}, 1)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ret and vec $eout, do {
*$ioe
}->{"ie_fileno"}, 1
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($eout) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | for my $ioe (values %want_exception) { | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | next unless vec($eout, ${*$ioe}{ie_fileno}, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $ioe->ie_dispatch_exception(${*$ioe}{ie_fh}); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $nfound--; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | last EVENT unless $nfound > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 303 | ▶ | IO::Event::Emulate::Timer->invoke_timers if $timer_timeout; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 303 | IO::Event::Emulate::Idle->invoke_idlers($nfound == 0); | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | ▶ | die unless ref($unloop); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | my @r = @$unloop; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | shift(@r); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | ▶ | return $r[0] if @r == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 244 | ▶ | if ($timers[0] > $t) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 244 | my $timeout = $timers[0] - $t; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 244 | ▶ | $timeout = 0.01 if $timeout < 0.01; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
@timers and $timers[0] < &IO::Event::Emulate::Timer::time()
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()
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 108 | ▶ | print STDERR "Ti" if $sdebug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 108 | ▶ | next unless $timer->{next} eq $t; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 3 | ▶ | die if $param{after} && $param{at}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$param{"after"} and $param{"at"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 96 | ▶ | if ($self->{interval}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 96 | $next = $self->{last_time} + $self->{interval}; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 96 | ▶ | if ($self->{hard} && $self->{next}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"hard"} and $self->{"next"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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'}}
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 96 | $self->{invoked}++; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 96 | ▶ | if (reftype($self->{cb}) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 1 | ▶ | die if $param{after} && $param{at}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$param{"after"} and $param{"at"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$idler->{"min"} and &IO::Event::Emulate::Idle::time() - $idler->{"last_time"} < $idler->{"min"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 1 | ▶ | unless ($is_idle) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | next unless $idler->{max}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | next unless (time - $idler->{last_time}) > $idler->{max}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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'}}
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 1 | ▶ | if (defined($self->{reentrant}) && ! $self->{reentrant} && $self->{icount}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $self->{"reentrant"} and not $self->{"reentrant"} and $self->{"icount"}
defined $self->{"reentrant"} and not $self->{"reentrant"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | $self->{invoked}++; | |||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | ▶ | if (defined($self->{repeat}) && ! $self->{repeat}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"repeat"} and not $self->{"repeat"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 1 | $self->cancel; | |||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 1 | ▶ | if (reftype($self->{cb}) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||