line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Fake; |
2
|
1
|
|
|
1
|
|
2306
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
752
|
|
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
48
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars '$VERSION'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
2014
|
|
5
|
|
|
|
|
|
|
$VERSION = "0.11"; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
##################### |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $OFFSET = 0; |
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
16
|
*CORE::GLOBAL::time = sub() { CORE::time() + $OFFSET }; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
*CORE::GLOBAL::localtime = sub(;$) { |
14
|
5
|
100
|
|
5
|
|
896
|
@_ ? CORE::localtime($_[0]) |
15
|
|
|
|
|
|
|
: CORE::localtime(CORE::time() + $OFFSET); |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
*CORE::GLOBAL::gmtime = sub(;$) { |
19
|
2
|
100
|
|
2
|
|
23
|
@_ ? CORE::gmtime($_[0]) |
20
|
|
|
|
|
|
|
: CORE::gmtime(CORE::time() + $OFFSET); |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub import { |
24
|
1
|
|
|
1
|
|
11
|
my $pkg = shift; |
25
|
1
|
|
|
|
|
4
|
$pkg->offset(shift); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub offset { |
29
|
4
|
|
|
4
|
1
|
19
|
my $pkg = shift; |
30
|
4
|
50
|
|
|
|
16
|
return $OFFSET if !@_; |
31
|
|
|
|
|
|
|
|
32
|
4
|
|
|
|
|
6
|
my $old_offset = $OFFSET; |
33
|
4
|
|
|
|
|
11
|
$OFFSET = _to_offset(shift); |
34
|
4
|
|
|
|
|
49
|
return $old_offset; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub reset { |
38
|
1
|
|
|
1
|
1
|
6
|
shift->offset(0); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my %mult = ( |
42
|
|
|
|
|
|
|
s => 1, |
43
|
|
|
|
|
|
|
m => 60, |
44
|
|
|
|
|
|
|
h => 60*60, |
45
|
|
|
|
|
|
|
d => 60*60*24, |
46
|
|
|
|
|
|
|
M => 60*60*24*30, |
47
|
|
|
|
|
|
|
y => 60*60*24*365, |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _to_offset { |
51
|
4
|
|
100
|
4
|
|
14
|
my $t = shift || return 0; |
52
|
|
|
|
|
|
|
|
53
|
2
|
100
|
|
|
|
20
|
if ($t =~ m/^([+-]\d+)([smhdMy]?)$/) { |
|
|
50
|
|
|
|
|
|
54
|
1
|
|
50
|
|
|
11
|
$t = $1 * $mult{ $2 || "s" }; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} elsif ($t !~ m/\D/) { |
57
|
1
|
|
|
|
|
2
|
$t = $t - CORE::time; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} else { |
60
|
0
|
|
|
|
|
0
|
croak "Invalid time offset: `$t'"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
|
|
|
5
|
return $t; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |