line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Consts; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = 0.05; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
56664
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
100
|
|
6
|
4
|
|
|
4
|
|
11
|
use Carp; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
977
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my %ok = map { $_ => 1 } qw/ |
9
|
|
|
|
|
|
|
MSEC |
10
|
|
|
|
|
|
|
SEC |
11
|
|
|
|
|
|
|
MIN |
12
|
|
|
|
|
|
|
HOUR |
13
|
|
|
|
|
|
|
DAY |
14
|
|
|
|
|
|
|
WEEK |
15
|
|
|
|
|
|
|
/; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %secs = ( |
18
|
|
|
|
|
|
|
MSEC => 1, |
19
|
|
|
|
|
|
|
SEC => 1000 * 1, |
20
|
|
|
|
|
|
|
MIN => 1000 * 60, |
21
|
|
|
|
|
|
|
HOUR => 1000 * 60 * 60, |
22
|
|
|
|
|
|
|
DAY => 1000 * 60 * 60 * 24, |
23
|
|
|
|
|
|
|
WEEK => 1000 * 60 * 60 * 24 * 7, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub import { |
27
|
13
|
|
|
13
|
|
8568
|
shift; |
28
|
|
|
|
|
|
|
|
29
|
13
|
100
|
|
|
|
70
|
return unless @_; |
30
|
|
|
|
|
|
|
|
31
|
9
|
|
|
|
|
16
|
my @args = @_; |
32
|
|
|
|
|
|
|
|
33
|
9
|
100
|
100
|
|
|
75
|
if (my (@bad) = grep !$ok{+uc} && $_ ne ':ALL' => @args) { |
34
|
1
|
|
|
|
|
133
|
croak('Bad argument(s): ' . join ', ' => @bad); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
8
|
|
|
|
|
23
|
my @unit = grep $_ eq lc, @args; |
38
|
8
|
100
|
|
|
|
94
|
croak("Too many units: @unit") if @unit > 1; |
39
|
7
|
|
|
|
|
10
|
push @unit => 'sec'; |
40
|
7
|
|
|
|
|
8
|
my $unit = $secs{uc $unit[0]}; |
41
|
|
|
|
|
|
|
|
42
|
7
|
|
|
|
|
5
|
my @consts = keys %{{ |
43
|
32
|
|
|
|
|
47
|
map { $_ => 1 } |
44
|
22
|
100
|
|
|
|
35
|
map { $_ eq ':ALL' ? keys %ok : $_ } |
45
|
7
|
|
|
|
|
7
|
grep { $_ eq uc } |
|
25
|
|
|
|
|
29
|
|
46
|
|
|
|
|
|
|
@args |
47
|
|
|
|
|
|
|
}}; |
48
|
|
|
|
|
|
|
|
49
|
7
|
|
|
|
|
26
|
my $pkg = caller; |
50
|
|
|
|
|
|
|
|
51
|
7
|
|
|
|
|
10
|
for (@consts) { |
52
|
32
|
|
|
|
|
37
|
my $t = $secs{$_} / $unit; |
53
|
|
|
|
|
|
|
|
54
|
4
|
|
|
4
|
|
17
|
no strict 'refs'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
348
|
|
55
|
32
|
|
|
0
|
|
115
|
*{"$pkg\::$_"} = sub () { $t }; |
|
32
|
|
|
|
|
2297
|
|
|
0
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__PACKAGE__; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |