line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::DateTime::Duration::Numeric; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1465
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
84
|
|
4
|
3
|
|
|
3
|
|
38
|
use 5.8.1; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
488
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
1894
|
use overload '""' => \&value, '+0' => \&value, fallback => 1; |
|
3
|
|
|
|
|
949
|
|
|
3
|
|
|
|
|
26
|
|
8
|
3
|
|
|
3
|
|
18850
|
use DateTime; |
|
3
|
|
|
|
|
248098
|
|
|
3
|
|
|
|
|
139
|
|
9
|
3
|
|
|
3
|
|
32
|
use DateTime::Duration; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
483
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub import { |
12
|
|
|
|
|
|
|
## Should we do this for 'float' as well? |
13
|
24
|
|
|
24
|
|
164
|
overload::constant integer => sub { Acme::DateTime::Duration::Numeric->new(@_) }; |
|
18
|
|
|
18
|
|
254
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
## Gross hack to bypass DateTime's Params::Validate check |
16
|
18
|
|
|
|
|
550
|
$Params::Validate::NO_VALIDATION = 1; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
24
|
|
|
24
|
0
|
51
|
my($class, $value) = @_; |
21
|
24
|
|
|
|
|
4756
|
bless { value => $value }, $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
14
|
|
|
14
|
0
|
685
|
sub value { $_[0]->{value} } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
for my $accessor (qw( day hour minute month second week year )) { |
27
|
3
|
|
|
3
|
|
65
|
no strict 'refs'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
910
|
|
28
|
|
|
|
|
|
|
my $plural = $accessor . "s"; |
29
|
|
|
|
|
|
|
*$accessor = *$plural = sub { |
30
|
15
|
|
|
15
|
|
147
|
my $self = shift; |
31
|
15
|
|
|
|
|
91
|
DateTime::Duration->new($plural => $self->{value}); |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub fortnight { |
36
|
1
|
|
|
1
|
0
|
7
|
my $self = shift; |
37
|
1
|
|
|
|
|
10
|
DateTime::Duration->new(weeks => 2 * $self->{value}); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
*fortnights = \&fortnight; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub DateTime::Duration::ago { |
43
|
2
|
|
|
2
|
0
|
205
|
my $duration = shift; |
44
|
2
|
50
|
|
|
|
59
|
my $dt = $_[0] ? $_[0]->clone : DateTime->now; |
45
|
2
|
|
|
|
|
127
|
$dt->subtract_duration($duration); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
*DateTime::Duration::until = \&DateTime::Duration::ago; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub DateTime::Duration::from_now { |
51
|
2
|
|
|
2
|
0
|
154
|
my $duration = shift; |
52
|
2
|
50
|
|
|
|
9
|
my $dt = $_[0] ? $_[0]->clone : DateTime->now; |
53
|
2
|
|
|
|
|
122
|
$dt->add_duration($duration); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
*DateTime::Duration::since = \&DateTime::Duration::from_now; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
__END__ |