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