line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OurCal::Span; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
4
|
use Carp qw(confess); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
5
|
1
|
|
|
1
|
|
1238
|
use DateTime; |
|
1
|
|
|
|
|
278911
|
|
|
1
|
|
|
|
|
356
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
OurCal::Span - a base class for OurCal spans of time |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 METHODS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head2 new |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Must have a date param |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
0
|
|
|
0
|
1
|
|
my ($class, %what) = @_; |
22
|
0
|
|
|
|
|
|
my $self = bless \%what, $class; |
23
|
0
|
0
|
|
|
|
|
confess "No date set" unless defined $self->date; |
24
|
0
|
|
|
|
|
|
my @names = qw(year month day); |
25
|
0
|
|
|
|
|
|
my @bits = split /-/, $self->date; |
26
|
0
|
|
|
|
|
|
my %opts; |
27
|
0
|
|
|
|
|
|
foreach my $name (@names) { |
28
|
0
|
|
|
|
|
|
my $val = shift @bits; |
29
|
0
|
0
|
|
|
|
|
last unless defined $val; |
30
|
0
|
|
|
|
|
|
$opts{$name} = $val; |
31
|
|
|
|
|
|
|
} |
32
|
0
|
|
|
|
|
|
$self->{_dt} = DateTime->new( %opts ); |
33
|
0
|
|
|
|
|
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 date |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
The date for this span |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub date { |
43
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
return $self->{date}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 calendar |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Return the OurCal calendar object this is attached to |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub calendar { |
54
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
55
|
0
|
|
|
|
|
|
return $self->{calendar}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _span { |
60
|
0
|
|
|
0
|
|
|
my $self = shift; |
61
|
0
|
|
|
|
|
|
my $class = shift; |
62
|
0
|
|
|
|
|
|
my $date = shift; |
63
|
|
|
|
|
|
|
# TODO this needs to be abstracted |
64
|
0
|
|
|
|
|
|
my %what = ( date => $date, calendar => $self->calendar ); |
65
|
0
|
|
|
|
|
|
return $class->new(%what); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _shift { |
69
|
0
|
|
|
0
|
|
|
my $self = shift; |
70
|
0
|
|
|
|
|
|
my $date = shift; |
71
|
0
|
|
|
|
|
|
my $prev = ref($self)->new( date => $date, calendar => $self->calendar ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |