line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Consts; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = 0.04; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
57107
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
106
|
|
6
|
4
|
|
|
4
|
|
14
|
use Carp; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
1072
|
|
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
|
|
8790
|
shift; |
28
|
|
|
|
|
|
|
|
29
|
13
|
100
|
|
|
|
63
|
return unless @_; |
30
|
|
|
|
|
|
|
|
31
|
9
|
|
|
|
|
18
|
my @args = @_; |
32
|
|
|
|
|
|
|
|
33
|
9
|
100
|
100
|
|
|
84
|
if (my (@bad) = grep !$ok{+uc} && $_ ne ':ALL' => @args) { |
34
|
1
|
|
|
|
|
142
|
croak('Bad argument(s): ' . join ', ' => @bad); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
8
|
|
|
|
|
21
|
my @unit = grep $_ eq lc, @args; |
38
|
8
|
100
|
|
|
|
96
|
croak("Too many units: @unit") if @unit > 1; |
39
|
7
|
|
|
|
|
9
|
push @unit => 'sec'; |
40
|
7
|
|
|
|
|
12
|
my $unit = $secs{uc $unit[0]}; |
41
|
|
|
|
|
|
|
|
42
|
7
|
|
|
|
|
7
|
my @consts = keys %{{ |
43
|
32
|
|
|
|
|
59
|
map { $_ => 1 } |
44
|
22
|
100
|
|
|
|
42
|
map { $_ eq ':ALL' ? keys %ok : $_ } |
45
|
7
|
|
|
|
|
8
|
grep { $_ eq uc } |
|
25
|
|
|
|
|
35
|
|
46
|
|
|
|
|
|
|
@args |
47
|
|
|
|
|
|
|
}}; |
48
|
|
|
|
|
|
|
|
49
|
7
|
|
|
|
|
26
|
my $pkg = caller; |
50
|
|
|
|
|
|
|
|
51
|
7
|
|
|
|
|
14
|
for (@consts) { |
52
|
32
|
|
|
|
|
39
|
my $t = $secs{$_} / $unit; |
53
|
|
|
|
|
|
|
|
54
|
4
|
|
|
4
|
|
19
|
no strict 'refs'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
366
|
|
55
|
32
|
|
|
0
|
|
132
|
*{"$pkg\::$_"} = sub () { $t }; |
|
32
|
|
|
|
|
2365
|
|
|
0
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__PACKAGE__; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |