line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
36938
|
use 5.006; # Our |
|
3
|
|
|
|
|
9
|
|
2
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
83
|
|
3
|
3
|
|
|
3
|
|
19
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
281
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Acme::Time::Constant; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.001006'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Run any code in constant time. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
1496
|
use Sub::Exporter::Progressive -setup => { exports => [qw( constant_time )] }; |
|
3
|
|
|
|
|
2910
|
|
|
3
|
|
|
|
|
25
|
|
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
1712
|
use Time::HiRes qw( gettimeofday ); |
|
3
|
|
|
|
|
3732
|
|
|
3
|
|
|
|
|
12
|
|
16
|
3
|
|
|
3
|
|
1741
|
use Time::Warp qw( to time ); |
|
3
|
|
|
|
|
1275
|
|
|
3
|
|
|
|
|
255
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $old_import; |
19
|
3
|
|
|
3
|
|
67
|
BEGIN { $old_import = \&import } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
{ |
22
|
|
|
|
|
|
|
## no critic (TestingAndDebugging::ProhibitNoWarnings) |
23
|
3
|
|
|
3
|
|
17
|
no warnings 'redefine'; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
420
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub import { |
26
|
2
|
|
|
2
|
|
35
|
*CORE::GLOBAL::time = *Time::Warp::time; |
27
|
2
|
|
|
|
|
6
|
goto $old_import; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub constant_time { |
39
|
3
|
|
|
3
|
1
|
1142
|
my $nargs = ( my ( $time, $callback ) = @_ ); |
40
|
|
|
|
|
|
|
|
41
|
3
|
100
|
|
|
|
12
|
if ( $nargs < 2 ) { |
42
|
1
|
|
|
|
|
2
|
$callback = $time; |
43
|
1
|
|
|
|
|
3
|
$time = 1; |
44
|
|
|
|
|
|
|
} |
45
|
3
|
|
|
|
|
6
|
my $now = time; |
46
|
3
|
|
|
|
|
6
|
$callback->(); |
47
|
3
|
|
|
|
|
922844
|
to( $now + $time ); |
48
|
3
|
|
|
|
|
9
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |