| 1 | package Test::Mock::Time; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | our $VERSION = 'v0.2.1'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use Export::Attrs; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use List::Util qw( any ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Scalar::Util qw( weaken ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 8 | ▶ | use Test::MockModule; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | ▶ | use constant TIME_HIRES_CLOCK_NOT_SUPPORTED => -1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | use constant MICROSECONDS => 1_000_000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | ▶ | use constant NANOSECONDS => 1_000_000_000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 8 | ▶ | use constant DEFAULT_WAIT_ONE_TICK => 0.05; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | our $WAIT_ONE_TICK = DEFAULT_WAIT_ONE_TICK; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 8 | my $Absolute = time; # usual time starts at current actual time | |||||||||||||||||||||||||||||||||||||||||
| 23 | 8 | my $Monotonic = 0; # monotonic time starts at 0 if not available | |||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | my $Relative = 0; # how many deterministic time passed since start | |||||||||||||||||||||||||||||||||||||||||
| 25 | 8 | my @Timers; # active timers | |||||||||||||||||||||||||||||||||||||||||
| 26 | my @Timers_ns; # inactive timers | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 8 | my %Module; # keep module mocks | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 8 | _mock_core_global(); | |||||||||||||||||||||||||||||||||||||||||
| 31 | ## no critic (RequireCheckingReturnValueOfEval) | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 8 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 33 | 8 | require Time::HiRes; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 8 | Time::HiRes->import(qw( CLOCK_REALTIME CLOCK_MONOTONIC )); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 8 | _mock_time_hires(); | |||||||||||||||||||||||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 8 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 38 | 8 | require EV; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 8 | _mock_ev(); | |||||||||||||||||||||||||||||||||||||||||
| 40 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | require Mojolicious; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 8 | Mojolicious->VERSION('6'); # may be compatible with older ones, needs testing | |||||||||||||||||||||||||||||||||||||||||
| 44 | 8 | require Mojo::Reactor::Poll; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | _mock_mojolicious(); | |||||||||||||||||||||||||||||||||||||||||
| 46 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # FIXME make ff() reentrant | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 51 | ▶ | sub ff :Export(:DEFAULT) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ff: called CC=11 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 51 | my ($dur) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | @Timers = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 51 | $a->{start}+$a->{after} <=> $b->{start}+$b->{after} or | |||||||||||||||||||||||||||||||||||||||||
| 55 | $a->{id} cmp $b->{id} # preserve order to simplify tests | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | } @Timers; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$Test::Mock::Time::a->{'start'} + $Test::Mock::Time::a->{'after'} <=> $Test::Mock::Time::b->{'start'} + $Test::Mock::Time::b->{'after'} || $Test::Mock::Time::a->{'id'} cmp $Test::Mock::Time::b->{'id'}
MC/DC0%0/2
$Test::Mock::Time::a->{'start'} + $Test::Mock::Time::a->{'after'} <=> $Test::Mock::Time::b->{'start'} + $Test::Mock::Time::b->{'after'} || $Test::Mock::Time::a->{'id'} cmp $Test::Mock::Time::b->{'id'}
$Test::Mock::Time::a->{'start'} + $Test::Mock::Time::a->{'after'} <=> $Test::Mock::Time::b->{'start'} + $Test::Mock::Time::b->{'after'}
$Test::Mock::Time::a->{'id'} cmp $Test::Mock::Time::b->{'id'}
Truth table0%0/3
A || B
A= $Test::Mock::Time::a->{'start'} + $Test::Mock::Time::a->{'after'} <=> $Test::Mock::Time::b->{'start'} + $Test::Mock::Time::b->{'after'}B= $Test::Mock::Time::a->{'id'} cmp $Test::Mock::Time::b->{'id'}
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 51 | ▶ | my $next_at = @Timers ? $Timers[0]{start}+$Timers[0]{after} : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 51 | $next_at = sprintf '%.6f', $next_at; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 51 | ▶ | if (!defined $dur) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 23 | ▶ | $dur = $next_at > $Relative ? $next_at - $Relative : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 23 | $dur = sprintf '%.6f', $dur; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 51 | ▶ | croak "ff($dur): negative time not invented yet" if $dur < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 51 | ▶ | if ($next_at == 0 || $next_at > $Relative+$dur) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$next_at == 0 or $next_at > $Relative + $dur
MC/DC100%2/2
$next_at == 0 or $next_at > $Relative + $dur
$next_at == 0
$next_at > $Relative + $dur
Truth table100%3/3
A or B
A= $next_at == 0B= $next_at > $Relative + $dur
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 28 | $Relative += $dur; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 28 | $Relative = sprintf '%.6f', $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 28 | return; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 23 | ▶ | if ($next_at > $Relative) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 23 | $dur -= $next_at - $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 23 | $dur = sprintf '%.6f', $dur; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 23 | $Relative = $next_at; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 23 | my $cb = $Timers[0]{cb}; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 23 | ▶ | if ($Timers[0]{repeat} == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 7 | ▶ | if ($Timers[0]{watcher}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | _stop_timer($Timers[0]{watcher}); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | shift @Timers; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 16 | $Timers[0]{after} = $Timers[0]{repeat}; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 16 | $Timers[0]{start} = $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 23 | $cb->(); | |||||||||||||||||||||||||||||||||||||||||
| 91 | 23 | @_ = ($dur); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 23 | goto &ff; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 8 | my $next_id = 0; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 20 | ▶ | sub _add_timer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_timer: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 20 | my ($loop, $after, $repeat, $cb, $watcher) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 20 | my $id = sprintf 'fake_%05d', $next_id++; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 20 | ▶ | push @Timers, { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | id => $id, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | start => $Relative, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | loop => $loop, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | after => sprintf('%.6f', $after < 0 ? 0 : $after), | ||||||||||||||||||||||||||||||||||||||||||
| 105 | repeat => sprintf('%.6f', $repeat < 0 ? 0 : $repeat), | ||||||||||||||||||||||||||||||||||||||||||
| 106 | cb => $cb, | ||||||||||||||||||||||||||||||||||||||||||
| 107 | watcher => $watcher, | ||||||||||||||||||||||||||||||||||||||||||
| 108 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 20 | ▶ | if ($watcher) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 13 | weaken($Timers[-1]{watcher}); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 20 | return $id; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | ▶ | sub _start_timer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_start_timer: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | my ($watcher) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | ▶ | my ($timer) = grep { $_->{watcher} && $_->{watcher} eq $watcher } @Timers_ns; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->{'watcher'} && $_->{'watcher'} eq $watcher
MC/DC50%1/2
$_->{'watcher'} && $_->{'watcher'} eq $watcher
$_->{'watcher'}
$_->{'watcher'} eq $watcher
Truth table66%2/3
A && B
A= $_->{'watcher'}B= $_->{'watcher'} eq $watcher
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | ▶ | if ($timer) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | ▶ | @Timers_ns = grep { !$_->{watcher} || $_->{watcher} ne $watcher } @Timers_ns; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
!$_->{'watcher'} || $_->{'watcher'} ne $watcher
MC/DC50%1/2
!$_->{'watcher'} || $_->{'watcher'} ne $watcher
!$_->{'watcher'}
$_->{'watcher'} ne $watcher
Truth table66%2/3
not(A) || B
A= !$_->{'watcher'}B= $_->{'watcher'} ne $watcher
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | push @Timers, $timer; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 13 | ▶ | sub _stop_timer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stop_timer: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 13 | my ($watcher) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 13 | ▶ | my ($timer) = grep { $_->{watcher} && $_->{watcher} eq $watcher } @Timers; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_->{'watcher'} && $_->{'watcher'} eq $watcher
MC/DC0%0/2
$_->{'watcher'} && $_->{'watcher'} eq $watcher
$_->{'watcher'}
$_->{'watcher'} eq $watcher
Truth table33%1/3
A && B
A= $_->{'watcher'}B= $_->{'watcher'} eq $watcher
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 13 | ▶ | if ($timer) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 6 | ▶ | @Timers = grep { !$_->{watcher} || $_->{watcher} ne $watcher } @Timers; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
!$_->{'watcher'} || $_->{'watcher'} ne $watcher
MC/DC0%0/2
!$_->{'watcher'} || $_->{'watcher'} ne $watcher
!$_->{'watcher'}
$_->{'watcher'} ne $watcher
Truth table33%1/3
not(A) || B
A= !$_->{'watcher'}B= $_->{'watcher'} ne $watcher
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 6 | push @Timers_ns, $timer; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 8 | ▶ | sub _mock_core_global { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mock_core_global: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 8 | $Module{'CORE::GLOBAL'} = Test::MockModule->new('CORE::GLOBAL', no_auto=>1); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 46 | ▶ | $Module{'CORE::GLOBAL'}->mock(time => sub () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 46 | return int($Absolute + $Relative); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 12 | ▶ | $Module{'CORE::GLOBAL'}->mock(localtime => sub (;$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 12 | ▶ | my $time = defined $_[0] ? $_[0] : int($Absolute + $Relative); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 12 | return CORE::localtime($time); | |||||||||||||||||||||||||||||||||||||||||
| 144 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 13 | ▶ | $Module{'CORE::GLOBAL'}->mock(gmtime => sub (;$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 13 | ▶ | my $time = defined $_[0] ? $_[0] : int($Absolute + $Relative); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 13 | return CORE::gmtime($time); | |||||||||||||||||||||||||||||||||||||||||
| 148 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 149 | 16 | ▶ | $Module{'CORE::GLOBAL'}->mock(sleep => sub ($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 16 | my $dur = int $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 16 | ▶ | croak 'sleep with negative value is not supported' if $dur < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 14 | $Relative += $dur; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 14 | $Relative = sprintf '%.6f', $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 14 | return $dur; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 156 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 8 | ▶ | sub _mock_time_hires { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mock_time_hires: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | # Do not improve precision of current actual time to simplify tests. | ||||||||||||||||||||||||||||||||||||||||||
| 161 | #$Absolute = Time::HiRes::time(); | ||||||||||||||||||||||||||||||||||||||||||
| 162 | # Use current actual monotonic time. | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 8 | $Monotonic = Time::HiRes::clock_gettime(CLOCK_MONOTONIC()); | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 8 | $Module{'Time::HiRes'} = Test::MockModule->new('Time::HiRes'); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 8 | ▶ | $Module{'Time::HiRes'}->mock(time => sub () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 8 | return 0+sprintf '%.6f', $Absolute + $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | ▶ | $Module{'Time::HiRes'}->mock(gettimeofday => sub () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | my $t = sprintf '%.6f', $Absolute + $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 4 | ▶ | return wantarray ? (map {0+$_} split qr/[.]/ms, $t) : 0+$t; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 173 | 51 | ▶ | $Module{'Time::HiRes'}->mock(clock_gettime => sub (;$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 51 | my ($which) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 51 | ▶ | if ($which == CLOCK_REALTIME()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | return 0+sprintf '%.6f', $Absolute + $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | elsif ($which == CLOCK_MONOTONIC()) { | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 49 | return 0+sprintf '%.6f', $Monotonic + $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | return TIME_HIRES_CLOCK_NOT_SUPPORTED; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 183 | 3 | ▶ | $Module{'Time::HiRes'}->mock(clock_getres => sub (;$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | my ($which) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | ▶ | if ($which == CLOCK_REALTIME() || $which == CLOCK_MONOTONIC()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$which == CLOCK_REALTIME() or $which == CLOCK_MONOTONIC()
MC/DC100%2/2
$which == CLOCK_REALTIME() or $which == CLOCK_MONOTONIC()
$which == CLOCK_REALTIME()
$which == CLOCK_MONOTONIC()
Truth table100%3/3
A or B
A= $which == CLOCK_REALTIME()B= $which == CLOCK_MONOTONIC()
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | return $Module{'Time::HiRes'}->original('clock_getres')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | return TIME_HIRES_CLOCK_NOT_SUPPORTED; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | ▶ | $Module{'Time::HiRes'}->mock(sleep => sub (;@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 3 | my ($seconds) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 3 | ▶ | croak 'sleep without arg is not supported' if !@_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 2 | ▶ | croak "Time::HiRes::sleep($seconds): negative time not invented yet" if $seconds < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | $Relative += $seconds; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | $Relative = sprintf '%.6f', $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | return $seconds; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 198 | 10 | ▶ | $Module{'Time::HiRes'}->mock(usleep => sub ($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 10 | my ($useconds) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 10 | ▶ | croak "Time::HiRes::usleep($useconds): negative time not invented yet" if $useconds < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 9 | $Relative += $useconds / MICROSECONDS; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 9 | $Relative = sprintf '%.6f', $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 9 | return $useconds; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 205 | 2 | ▶ | $Module{'Time::HiRes'}->mock(nanosleep => sub ($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | my ($nanoseconds) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 2 | ▶ | croak "Time::HiRes::nanosleep($nanoseconds): negative time not invented yet" if $nanoseconds < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 1 | $Relative += $nanoseconds / NANOSECONDS; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | $Relative = sprintf '%.6f', $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | return $nanoseconds; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 212 | 5 | ▶ | $Module{'Time::HiRes'}->mock(clock_nanosleep => sub ($$;$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 5 | my ($which, $nanoseconds, $flags) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 5 | ▶ | croak "Time::HiRes::clock_nanosleep(..., $nanoseconds): negative time not invented yet" if $nanoseconds < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 4 | ▶ | croak 'only CLOCK_REALTIME and CLOCK_MONOTONIC are supported' if $which != CLOCK_REALTIME() && $which != CLOCK_MONOTONIC(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$which != CLOCK_REALTIME() and $which != CLOCK_MONOTONIC()
MC/DC100%2/2
$which != CLOCK_REALTIME() and $which != CLOCK_MONOTONIC()
$which != CLOCK_REALTIME()
$which != CLOCK_MONOTONIC()
Truth table100%3/3
A and B
A= $which != CLOCK_REALTIME()B= $which != CLOCK_MONOTONIC()
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 3 | ▶ | croak 'only flags=0 is supported' if $flags; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | $Relative += $nanoseconds / NANOSECONDS; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 2 | $Relative = sprintf '%.6f', $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 2 | return $nanoseconds; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 221 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | # TODO Distinguish timers set on different event loops / Mojo reactor | ||||||||||||||||||||||||||||||||||||||||||
| 225 | # objects while one_tick? | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 8 | ▶ | sub _mock_ev { ## no critic (ProhibitExcessComplexity) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mock_ev: called CC=1 SCAR=0.7
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 8 | $Module{'EV'} = Test::MockModule->new('EV'); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 8 | $Module{'EV::Watcher'} = Test::MockModule->new('EV::Watcher', no_auto=>1); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 8 | $Module{'EV::Timer'} = Test::MockModule->new('EV::Timer', no_auto=>1); | |||||||||||||||||||||||||||||||||||||||||
| 231 | 8 | $Module{'EV::Periodic'} = Test::MockModule->new('EV::Periodic', no_auto=>1); | |||||||||||||||||||||||||||||||||||||||||
| 232 | 7 | ▶ | $Module{'EV'}->mock(time => sub () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 7 | return 0+sprintf '%.6f', $Absolute + $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 235 | 21 | ▶ | $Module{'EV'}->mock(now => sub () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 21 | return 0+sprintf '%.6f', $Absolute + $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 238 | 4 | ▶ | $Module{'EV'}->mock(sleep => sub ($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | my ($seconds) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 4 | ▶ | if ($seconds < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | $seconds = 0; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 4 | $Relative += $seconds; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | $Relative = sprintf '%.6f', $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 247 | 23 | ▶ | $Module{'EV'}->mock(run => sub (;$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 23 | my ($flags) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 23 | my $tick = 0; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 23 | my $w; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 23 | ▶ | if (@Timers) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | $w = $Module{'EV'}->original('timer')->( | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 23 | ▶ | $WAIT_ONE_TICK, $WAIT_ONE_TICK, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=20.7
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 23 | my $me = shift; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 23 | my $k; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 23 | ▶ | if (!$tick++ || !$flags) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tick++ and $flags
MC/DC50%1/2
$tick++ and $flags
$tick++
$flags
Truth table66%2/3
A and B
A= $tick++B= $flags
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 15 | $k = $me->keepalive(0); | |||||||||||||||||||||||||||||||||||||||||
| 258 | 15 | ff(); | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 23 | ▶ | if (!@Timers) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 7 | $me->stop; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | elsif ($k && ($flags || any {$_->{watcher} && $_->{watcher}->keepalive} @Timers)) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=11.6
Branch: 1 branch
Condition50%3/6
$k and $flags || &any(sub {
$_->{"watcher"} and $_->{"watcher"}->keepalive;
}
, @Timers)
$flags or &any(sub {
$_->{"watcher"} and $_->{"watcher"}->keepalive;
}
, @Timers)
MC/DC33%1/3
$k and $flags || &any(sub {
$_->{"watcher"} and $_->{"watcher"}->keepalive;
}
, @Timers)
$k
$flags
&any(sub {
$_->{"watcher"} and $_->{"watcher"}->keepalive;
}
, @Timers)
Truth table50%2/4
A and B or C
A= $kB= $flagsC= &any(sub {
$_->{"watcher"} and $_->{"watcher"}->keepalive;
}
, @Timers)
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 8 | $me->keepalive(1); | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 15 | ); | |||||||||||||||||||||||||||||||||||||||||
| 268 | 15 | ▶ | if (!($flags || any {$_->{watcher} && $_->{watcher}->keepalive} @Timers)) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 2 branches
Condition66%2/3
$flags or &any(sub {
$_->{"watcher"} and $_->{"watcher"}->keepalive;
}
, @Timers)
MC/DC0%0/2
$flags or &any(sub {
$_->{"watcher"} and $_->{"watcher"}->keepalive;
}
, @Timers)
$flags
&any(sub {
$_->{"watcher"} and $_->{"watcher"}->keepalive;
}
, @Timers)
Truth table66%2/3
A or B
A= $flagsB= &any(sub {
$_->{"watcher"} and $_->{"watcher"}->keepalive;
}
, @Timers)
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | $w->keepalive(0); | |||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | # $tick above and this second RUN_ONCE is work around bug in EV-4.10+ | ||||||||||||||||||||||||||||||||||||||||||
| 273 | # http://lists.schmorp.de/pipermail/libev/2016q1/002656.html | ||||||||||||||||||||||||||||||||||||||||||
| 274 | # FIXME I believe this workaround isn't correct with EV-4.03 - calling | ||||||||||||||||||||||||||||||||||||||||||
| 275 | # RUN_ONCE twice must have side effect in processing two events | ||||||||||||||||||||||||||||||||||||||||||
| 276 | # (at least one of them must be a non-timer event) instead of one. | ||||||||||||||||||||||||||||||||||||||||||
| 277 | # To make it correct we probably need to mock all watcher types | ||||||||||||||||||||||||||||||||||||||||||
| 278 | # to intercept invoking their callbacks and thus make it possible | ||||||||||||||||||||||||||||||||||||||||||
| 279 | # to find out is first RUN_ONCE has actually called any callbacks. | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 23 | ▶ | if ($flags && $flags == EV::RUN_ONCE()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$flags and $flags == &EV::RUN_ONCE()
MC/DC50%1/2
$flags and $flags == &EV::RUN_ONCE()
$flags
$flags == &EV::RUN_ONCE()
Truth table66%2/3
A and B
A= $flagsB= $flags == &EV::RUN_ONCE()
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 18 | $Module{'EV'}->original('run')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 23 | return $Module{'EV'}->original('run')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 284 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 285 | 11 | ▶ | $Module{'EV'}->mock(timer => sub ($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 11 | my ($after, $repeat, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 11 | my $w = $Module{'EV'}->original('timer_ns')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 288 | 11 | weaken(my $weakw = $w); | |||||||||||||||||||||||||||||||||||||||||
| 289 | 11 | ▶ | _add_timer('EV', $after, $repeat, sub { $weakw && $weakw->invoke(EV::TIMER()) }, $w); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 11 | return $w; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | ▶ | $Module{'EV'}->mock(timer_ns => sub ($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | my ($after, $repeat, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | my $w = EV::timer($after, $repeat, $cb); | |||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | _stop_timer($w); | |||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | return $w; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 298 | 2 | ▶ | $Module{'EV'}->mock(periodic => sub ($$$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 2 | my ($at, $repeat, $reschedule_cb, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 2 | ▶ | croak 'reschedule_cb is not supported yet' if $reschedule_cb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 2 | ▶ | $at = sprintf '%.6f', $at < 0 ? 0 : $at; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | ▶ | $repeat = sprintf '%.6f', $repeat < 0 ? 0 : $repeat; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | my $now = sprintf '%.6f', $Absolute + $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 2 | ▶ | if ($repeat > 0 && $at < $now) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$repeat > 0 and $at < $now
MC/DC50%1/2
$repeat > 0 and $at < $now
$repeat > 0
$at < $now
Truth table66%2/3
A and B
A= $repeat > 0B= $at < $now
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 8 | ▶ | use bignum; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | $at += $repeat * int(($now - $at) / $repeat + 1); | |||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | $at = sprintf '%.6f', $at; | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 2 | ▶ | my $after = $at > $now ? $at - $now : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | $after = sprintf '%.6f', $after; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | my $w = $Module{'EV'}->original('periodic_ns')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 312 | 2 | weaken(my $weakw = $w); | |||||||||||||||||||||||||||||||||||||||||
| 313 | 2 | ▶ | _add_timer('EV', $after, $repeat, sub { $weakw && $weakw->invoke(EV::TIMER()) }, $w); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | return $w; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | $Module{'EV'}->mock(periodic_ns => sub ($$$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my ($at, $repeat, $reschedule_cb, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $w = EV::periodic($at, $repeat, $reschedule_cb, $cb); | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | _stop_timer($w); | |||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | return $w; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | ▶ | $Module{'EV::Watcher'}->mock(is_active => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | my ($w) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 324 | 2 | ▶ | my ($active) = grep { $_->{watcher} && $_->{watcher} eq $w } @Timers; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->{'watcher'} && $_->{'watcher'} eq $w
MC/DC50%1/2
$_->{'watcher'} && $_->{'watcher'} eq $w
$_->{'watcher'}
$_->{'watcher'} eq $w
Truth table66%2/3
A && B
A= $_->{'watcher'}B= $_->{'watcher'} eq $w
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 2 | ▶ | my ($inactive) = grep { $_->{watcher} && $_->{watcher} eq $w } @Timers_ns; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->{'watcher'} && $_->{'watcher'} eq $w
MC/DC50%1/2
$_->{'watcher'} && $_->{'watcher'} eq $w
$_->{'watcher'}
$_->{'watcher'} eq $w
Truth table66%2/3
A && B
A= $_->{'watcher'}B= $_->{'watcher'} eq $w
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 2 | ▶ | if ($active) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | elsif ($inactive) { | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | return $Module{'EV::Watcher'}->original('is_active')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 333 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 334 | 26 | ▶ | $Module{'EV::Timer'}->mock(DESTROY => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 26 | my ($w) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 26 | ▶ | @Timers = grep { !$_->{watcher} || $_->{watcher} ne $w } @Timers; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
!$_->{'watcher'} || $_->{'watcher'} ne $w
MC/DC50%1/2
!$_->{'watcher'} || $_->{'watcher'} ne $w
!$_->{'watcher'}
$_->{'watcher'} ne $w
Truth table66%2/3
not(A) || B
A= !$_->{'watcher'}B= $_->{'watcher'} ne $w
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 26 | ▶ | @Timers_ns = grep { !$_->{watcher} || $_->{watcher} ne $w } @Timers_ns; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
!$_->{'watcher'} || $_->{'watcher'} ne $w
MC/DC50%1/2
!$_->{'watcher'} || $_->{'watcher'} ne $w
!$_->{'watcher'}
$_->{'watcher'} ne $w
Truth table66%2/3
not(A) || B
A= !$_->{'watcher'}B= $_->{'watcher'} ne $w
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 26 | return $Module{'EV::Timer'}->original('DESTROY')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 339 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | ▶ | $Module{'EV::Timer'}->mock(start => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 1 | return _start_timer(@_); | |||||||||||||||||||||||||||||||||||||||||
| 342 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 343 | 9 | ▶ | $Module{'EV::Timer'}->mock(stop => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 9 | return _stop_timer(@_); | |||||||||||||||||||||||||||||||||||||||||
| 345 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | $Module{'EV::Timer'}->mock(set => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my ($w, $after, $repeat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if (!defined $repeat) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $repeat = 0; | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | my ($timer) = grep { $_->{watcher} && $_->{watcher} eq $w } @Timers, @Timers_ns; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->{'watcher'} && $_->{'watcher'} eq $w
MC/DC0%0/2
$_->{'watcher'} && $_->{'watcher'} eq $w
$_->{'watcher'}
$_->{'watcher'} eq $w
Truth table0%0/3
A && B
A= $_->{'watcher'}B= $_->{'watcher'} eq $w
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if ($timer) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | $timer->{start} = $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | $timer->{after} = sprintf '%.6f', $after < 0 ? 0 : $after; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | $timer->{repeat}= sprintf '%.6f', $repeat < 0 ? 0 : $repeat; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | $Module{'EV::Timer'}->mock(remaining => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my ($w) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | my ($timer) = grep { $_->{watcher} && $_->{watcher} eq $w } @Timers, @Timers_ns; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->{'watcher'} && $_->{'watcher'} eq $w
MC/DC0%0/2
$_->{'watcher'} && $_->{'watcher'} eq $w
$_->{'watcher'}
$_->{'watcher'} eq $w
Truth table0%0/3
A && B
A= $_->{'watcher'}B= $_->{'watcher'} eq $w
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | if ($timer) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | return 0+sprintf '%.6f', $timer->{start} + $timer->{after} - $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 366 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 367 | 3 | ▶ | $Module{'EV::Timer'}->mock(again => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=26.8
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 3 | my ($w, $repeat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 3 | ▶ | if (defined $repeat && $repeat < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $repeat and $repeat < 0
MC/DC0%0/2
defined $repeat and $repeat < 0
defined $repeat
$repeat < 0
Truth table33%1/3
A and B
A= defined $repeatB= $repeat < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $repeat = 0; | |||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 3 | ▶ | my ($active) = grep { $_->{watcher} && $_->{watcher} eq $w } @Timers; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_->{'watcher'} && $_->{'watcher'} eq $w
MC/DC0%0/2
$_->{'watcher'} && $_->{'watcher'} eq $w
$_->{'watcher'}
$_->{'watcher'} eq $w
Truth table33%1/3
A && B
A= $_->{'watcher'}B= $_->{'watcher'} eq $w
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 3 | ▶ | my ($inactive) = grep { $_->{watcher} && $_->{watcher} eq $w } @Timers_ns; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->{'watcher'} && $_->{'watcher'} eq $w
MC/DC50%1/2
$_->{'watcher'} && $_->{'watcher'} eq $w
$_->{'watcher'}
$_->{'watcher'} eq $w
Truth table66%2/3
A && B
A= $_->{'watcher'}B= $_->{'watcher'} eq $w
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 3 | ▶ | if ($active) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 2 | ▶ | $active->{repeat} = sprintf '%.6f', defined $repeat ? $repeat : $active->{repeat}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | ▶ | if ($active->{repeat} > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 2 | $active->{after} = $active->{repeat}; | |||||||||||||||||||||||||||||||||||||||||
| 378 | 2 | $active->{start} = $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | _stop_timer($active->{watcher}); | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | elsif ($inactive) { | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | ▶ | $inactive->{repeat} = sprintf '%.6f', defined $repeat ? $repeat : $inactive->{repeat}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | ▶ | if ($inactive->{repeat} > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | $inactive->{after} = $inactive->{repeat}; | |||||||||||||||||||||||||||||||||||||||||
| 388 | 1 | $inactive->{start} = $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | _start_timer($inactive->{watcher}); | |||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 394 | 2 | ▶ | $Module{'EV::Periodic'}->mock(DESTROY => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 2 | my ($w) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 2 | ▶ | @Timers = grep { !$_->{watcher} || $_->{watcher} ne $w } @Timers; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
!$_->{'watcher'} || $_->{'watcher'} ne $w
MC/DC0%0/2
!$_->{'watcher'} || $_->{'watcher'} ne $w
!$_->{'watcher'}
$_->{'watcher'} ne $w
Truth table33%1/3
not(A) || B
A= !$_->{'watcher'}B= $_->{'watcher'} ne $w
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 2 | ▶ | @Timers_ns = grep { !$_->{watcher} || $_->{watcher} ne $w } @Timers_ns; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
!$_->{'watcher'} || $_->{'watcher'} ne $w
MC/DC50%1/2
!$_->{'watcher'} || $_->{'watcher'} ne $w
!$_->{'watcher'}
$_->{'watcher'} ne $w
Truth table66%2/3
not(A) || B
A= !$_->{'watcher'}B= $_->{'watcher'} ne $w
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 2 | return $Module{'EV::Periodic'}->original('DESTROY')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 399 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | $Module{'EV::Periodic'}->mock(start => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | return _start_timer(@_); | |||||||||||||||||||||||||||||||||||||||||
| 402 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | $Module{'EV::Periodic'}->mock(stop => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return _stop_timer(@_); | |||||||||||||||||||||||||||||||||||||||||
| 405 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | $Module{'EV::Periodic'}->mock(set => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=9 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my ($w, $at, $repeat, $reschedule_cb, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | croak 'reschedule_cb is not supported yet' if $reschedule_cb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | $at = sprintf '%.6f', $at < 0 ? 0 : $at; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | $repeat = sprintf '%.6f', $repeat < 0 ? 0 : $repeat; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | my $now = sprintf '%.6f', $Absolute + $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | if ($repeat > 0 && $at < $now) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$repeat > 0 and $at < $now
MC/DC0%0/2
$repeat > 0 and $at < $now
$repeat > 0
$at < $now
Truth table0%0/3
A and B
A= $repeat > 0B= $at < $now
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 8 | ▶ | use bignum; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $at += $repeat * int(($now - $at) / $repeat + 1); | |||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $at = sprintf '%.6f', $at; | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | my $after = $at > $now ? $at - $now : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | $after = sprintf '%.6f', $after; | |||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | my ($timer) = grep { $_->{watcher} && $_->{watcher} eq $w } @Timers, @Timers_ns; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->{'watcher'} && $_->{'watcher'} eq $w
MC/DC0%0/2
$_->{'watcher'} && $_->{'watcher'} eq $w
$_->{'watcher'}
$_->{'watcher'} eq $w
Truth table0%0/3
A && B
A= $_->{'watcher'}B= $_->{'watcher'} eq $w
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | if ($timer) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | $timer->{start} = $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $timer->{after} = $after; | |||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | $timer->{repeat}= $repeat; | |||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | $Module{'EV::Periodic'}->mock(again => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | return _start_timer(@_); | |||||||||||||||||||||||||||||||||||||||||
| 429 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | $Module{'EV::Periodic'}->mock(at => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | my ($w) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | my ($timer) = grep { $_->{watcher} && $_->{watcher} eq $w } @Timers, @Timers_ns; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->{'watcher'} && $_->{'watcher'} eq $w
MC/DC0%0/2
$_->{'watcher'} && $_->{'watcher'} eq $w
$_->{'watcher'}
$_->{'watcher'} eq $w
Truth table0%0/3
A && B
A= $_->{'watcher'}B= $_->{'watcher'} eq $w
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | if ($timer) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | return 0+sprintf '%.6f', $timer->{start} + $timer->{after}; | |||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 438 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 8 | ▶ | sub _mock_mojolicious { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mock_mojolicious: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 8 | $Module{'Mojo::Reactor::Poll'} = Test::MockModule->new('Mojo::Reactor::Poll'); | |||||||||||||||||||||||||||||||||||||||||
| 443 | 10 | ▶ | $Module{'Mojo::Reactor::Poll'}->mock(one_tick => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | 10 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 10 | ▶ | if (!@Timers) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 2 | return $Module{'Mojo::Reactor::Poll'}->original('one_tick')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | my $id = $Module{'Mojo::Reactor::Poll'}->original('timer')->( | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 8 | ▶ | $self, $WAIT_ONE_TICK, sub { ff() } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 8 | ); | |||||||||||||||||||||||||||||||||||||||||
| 451 | 8 | $Module{'Mojo::Reactor::Poll'}->original('one_tick')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 452 | 8 | $Module{'Mojo::Reactor::Poll'}->original('remove')->($self, $id); | |||||||||||||||||||||||||||||||||||||||||
| 453 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||
| 454 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 455 | 5 | ▶ | $Module{'Mojo::Reactor::Poll'}->mock(timer => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | 5 | my ($self, $delay, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 457 | 5 | ▶ | if ($delay == 0) { # do not fake timer for 0 seconds to avoid hang | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | return $Module{'Mojo::Reactor::Poll'}->original('timer')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 5 | ▶ | return _add_timer($self, $delay, 0, sub { $cb->($self) }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 462 | 2 | ▶ | $Module{'Mojo::Reactor::Poll'}->mock(recurring => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 2 | my ($self, $delay, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 2 | ▶ | return _add_timer($self, $delay, $delay, sub { $cb->($self) }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 466 | 2 | ▶ | $Module{'Mojo::Reactor::Poll'}->mock(again => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 2 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 468 | 2 | ▶ | if ($id !~ /\Afake_\d+\z/ms) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | $Module{'Mojo::Reactor::Poll'}->original('again')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||
| 471 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 2 | my ($timer) = grep { $_->{id} eq $id } @Timers; | |||||||||||||||||||||||||||||||||||||||||
| 473 | 2 | ▶ | if ($timer) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 2 | $timer->{start} = $Relative; | |||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 478 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 479 | 12 | ▶ | $Module{'Mojo::Reactor::Poll'}->mock(remove => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 12 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 481 | 12 | ▶ | if ($id !~ /\Afake_\d+\z/ms) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 10 | $Module{'Mojo::Reactor::Poll'}->original('remove')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 2 | ▶ | @Timers = grep { $_->{loop} ne $self || $_->{id} ne $id } @Timers; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_->{'loop'} ne $self || $_->{'id'} ne $id
MC/DC0%0/2
$_->{'loop'} ne $self || $_->{'id'} ne $id
$_->{'loop'} ne $self
$_->{'id'} ne $id
Truth table33%1/3
A || B
A= $_->{'loop'} ne $selfB= $_->{'id'} ne $id
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 489 | 2 | ▶ | $Module{'Mojo::Reactor::Poll'}->mock(reset => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 491 | 2 | @Timers = grep { $_->{loop} ne $self } @Timers; | |||||||||||||||||||||||||||||||||||||||||
| 492 | 2 | return $Module{'Mojo::Reactor::Poll'}->original('reset')->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 493 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 494 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 499 | __END__ | ||||||||||||||||||||||||||||||||||||||||||