| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Google::Calendar::Server::Backend::ICalendar; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1900
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
51
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use base qw(Net::Google::Calendar::Server::Backend); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
602
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use Digest::MD5 qw(md5_hex); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
57
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
967
|
use Data::ICal::DateTime; |
|
|
1
|
|
|
|
|
911464
|
|
|
|
1
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Net::Google::Calendar::Server::Backend::ICalendar - an ICalendar backend for Net::Google::Calendar::Server |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 METHODS |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 fetch |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Fetch entries from a ICalendar file. |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub fetch { |
|
26
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
27
|
0
|
|
|
|
|
|
my %opts = @_; |
|
28
|
|
|
|
|
|
|
# TODO actually filter them |
|
29
|
0
|
|
|
|
|
|
my $cal = $self->from_file; |
|
30
|
0
|
|
|
|
|
|
return $cal->events; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 add |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Add a new entry. |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub add { |
|
40
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
41
|
0
|
|
|
|
|
|
my $event = shift; |
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$event->uid(md5_hex(time().$$.rand())); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# read in whole of file |
|
46
|
0
|
|
|
|
|
|
my $cal = $self->from_file; |
|
47
|
|
|
|
|
|
|
# add event |
|
48
|
0
|
|
|
|
|
|
$cal->add_event($event); |
|
49
|
|
|
|
|
|
|
# write it back out again |
|
50
|
0
|
|
|
|
|
|
$self->_to_file($cal); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 update |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Update an entry |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub update { |
|
60
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
61
|
0
|
|
|
|
|
|
my $event = shift; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# read in whole of file |
|
65
|
0
|
|
|
|
|
|
my $cal = $self->from_file; |
|
66
|
0
|
|
|
|
|
|
my @entries; |
|
67
|
|
|
|
|
|
|
# grep through looking for this id |
|
68
|
0
|
|
|
|
|
|
foreach my $entry ($cal->entries) { |
|
69
|
|
|
|
|
|
|
# update it |
|
70
|
0
|
0
|
|
|
|
|
$entry = $event if ($entry->uid eq $event->uid); |
|
71
|
0
|
|
|
|
|
|
push @entries, $entry; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
0
|
|
|
|
|
|
$cal->{entries} = [ @entries ]; |
|
74
|
|
|
|
|
|
|
# write it back out again |
|
75
|
0
|
|
|
|
|
|
$self->_to_file($cal); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 delete |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Delete an entry |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub delete { |
|
88
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
89
|
0
|
|
|
|
|
|
my $event = shift; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# read in whole of file |
|
92
|
0
|
|
|
|
|
|
my $cal = $self->from_file; |
|
93
|
0
|
|
|
|
|
|
my @entries; |
|
94
|
|
|
|
|
|
|
# grep through looking for this id |
|
95
|
0
|
|
|
|
|
|
foreach my $entry ($cal->entries) { |
|
96
|
|
|
|
|
|
|
# delete it |
|
97
|
0
|
0
|
|
|
|
|
next if $entry->uid eq $event->uid; |
|
98
|
0
|
|
|
|
|
|
push @entries, $entry; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
0
|
|
|
|
|
|
$cal->{entries} = [ @entries ]; |
|
101
|
|
|
|
|
|
|
# write it back out again |
|
102
|
0
|
|
|
|
|
|
$self->_to_file($cal); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _from_file { |
|
107
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
108
|
0
|
|
|
|
|
|
return Data::ICal->new(filename => $self->{filename}); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _to_file { |
|
112
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
113
|
0
|
|
|
|
|
|
my $cal = shift; |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $file = $self->{filename}; |
|
116
|
0
|
0
|
|
|
|
|
open(CAL,">$file")|| die "Couldn't open $file for writing: $!\n"; |
|
117
|
0
|
|
|
|
|
|
print CAL $cal->as_string; |
|
118
|
0
|
|
|
|
|
|
close(CAL); |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |