line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::MockSleep; |
2
|
2
|
|
|
2
|
|
56213
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
89
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
108
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = 0.02; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
10
|
no warnings 'redefine'; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
620
|
|
8
|
|
|
|
|
|
|
my $time_hires_sleep; |
9
|
|
|
|
|
|
|
my $have_mock_time; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $use_mock_time = 0; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $Slept; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub mock_sleep (;@) { |
16
|
8
|
|
|
8
|
0
|
348
|
my $seconds = shift; |
17
|
8
|
|
50
|
|
|
22
|
$seconds ||= 0; |
18
|
8
|
|
|
|
|
14
|
$Slept += $seconds; |
19
|
8
|
100
|
33
|
|
|
40
|
if($have_mock_time && $use_mock_time) { |
20
|
1
|
|
|
|
|
5
|
Test::MockTime::set_relative_time($seconds); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub slept { |
25
|
5
|
|
|
5
|
0
|
9
|
my $ret = $Slept; |
26
|
5
|
|
|
|
|
7
|
$Slept = 0; |
27
|
5
|
|
|
|
|
21
|
return $ret; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
eval { |
31
|
|
|
|
|
|
|
require Time::HiRes; |
32
|
|
|
|
|
|
|
$time_hires_sleep = \&Time::HiRes::sleep; |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
eval { |
36
|
|
|
|
|
|
|
require Test::MockTime; |
37
|
|
|
|
|
|
|
$have_mock_time = 1; |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub import { |
41
|
2
|
|
|
2
|
|
19
|
my $cls = shift; |
42
|
2
|
|
|
|
|
5
|
my @args = @_; |
43
|
|
|
|
|
|
|
|
44
|
2
|
100
|
|
|
|
13
|
if(grep $_ eq ':with_mocktime', @args) { |
45
|
1
|
|
|
|
|
2
|
$use_mock_time = 1; |
46
|
|
|
|
|
|
|
} else { |
47
|
1
|
|
|
|
|
2
|
$use_mock_time = 0; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
17
|
my $cpkg = caller(); |
51
|
2
|
|
|
2
|
|
10
|
no strict 'refs'; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
382
|
|
52
|
2
|
|
|
|
|
4
|
*{$cpkg.'::slept'} = \&slept; |
|
2
|
|
|
|
|
13
|
|
53
|
2
|
|
|
|
|
5
|
*CORE::GLOBAL::sleep = \&mock_sleep; |
54
|
2
|
50
|
|
|
|
8
|
if($time_hires_sleep) { |
55
|
2
|
|
|
|
|
7
|
*Time::HiRes::sleep = \&mock_sleep; |
56
|
|
|
|
|
|
|
} |
57
|
2
|
|
|
|
|
1650
|
1; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub restore { |
61
|
1
|
|
|
1
|
0
|
2
|
my ($cpkg,@args); |
62
|
|
|
|
|
|
|
|
63
|
1
|
50
|
33
|
|
|
5
|
if($have_mock_time && $use_mock_time) { |
64
|
0
|
|
|
|
|
0
|
Test::MockTime::restore(); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
1
|
|
8
|
*CORE::GLOBAL::sleep = sub (;@) { CORE::sleep(shift) }; |
|
1
|
|
|
|
|
1000123
|
|
68
|
1
|
50
|
|
|
|
4
|
if($time_hires_sleep) { |
69
|
1
|
|
|
|
|
4
|
*Time::HiRes::sleep = $time_hires_sleep; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |