Server/Backend/ICalendar.pm

filter: Statementstmt 26.5% 13 / 49 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 4 / 10 Podpod 100% 4 / 4 totaltotal 30.4% 21 / 69 CC 6 SCAR 18.4
CC
6
Cov
24%
update
12.0
delete
12.0
_to_file
6.0
CRAP 6.3
« Server/Handler/Apache2.pm ↑ Summary Server/Auth.pm »
1 package Net::Google::Calendar::Server::Backend::ICalendar;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base qw(Net::Google::Calendar::Server::Backend);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Data::ICal::DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 0 ▶sub fetch {
Subroutine fetch: not called CC=1 SCAR=6.9
Pod documented
26 0 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 0 ▶sub add {
Subroutine add: not called CC=1 SCAR=6.9
Pod documented
40 0 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 0 ▶sub update {
Subroutine update: not called CC=3 SCAR=24.8
Pod documented
60 0 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 ▶ $entry = $event if ($entry->uid eq $event->uid);
Branch: 1 branch
BranchTrueFalseTotal
if $entry->uid eq $event->uid 0 0 0
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 0 ▶sub delete {
Subroutine delete: not called CC=3 SCAR=24.8
Pod documented
88 0 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 ▶ next if $entry->uid eq $event->uid;
Branch: 1 branch
BranchTrueFalseTotal
if $entry->uid eq $event->uid 0 0 0
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 0 ▶sub _from_file {
Subroutine _from_file: not called CC=1 SCAR=6.9
107 0 my $self = shift;
108 0 return Data::ICal->new(filename => $self->{filename});
109 }
110  
111 0 ▶sub _to_file {
Subroutine _to_file: not called CC=2 SCAR=17.9
112 0 my $self = shift;
113 0 my $cal = shift;
114  
115 0 my $file = $self->{filename};
116 0 ▶ open(CAL,">$file")|| die "Couldn't open $file for writing: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open CAL, ">$file" or die "Couldn't open $file for writing: $!\n" 0 0 0
117 0 print CAL $cal->as_string;
118 0 close(CAL);
119 }
120  
121 1 1;
« Server/Handler/Apache2.pm ↑ Summary Server/Auth.pm »