OurCal.pm

filter: Statementstmt 26.1% 17 / 65 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 27.7% 5 / 18 Podpod 100% 13 / 13 totaltotal 29.4% 35 / 119 CC 11 SCAR 20.9
CC
11
Cov
20%
span_name
20.0
span
20.0
new
6.0
CRAP 8.1
« OurCal/Span.pm ↑ Summary OurCal/View.pm »
1 package OurCal;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use OurCal::Day;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use OurCal::Month;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use OurCal::Provider;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '1.2';
10  
11 =head1 NAME
12  
13 OurCal - a simple yet featureful personal calendaring system
14  
15 =head1 SYNOPSIS
16  
17 This is a example index.cgi
18  
19 my $config = OurCal::Config->new( file => 'ourcal.conf' );
20 my $handler = OurCal::Handler->new( config => $config);
21 my $cal = OurCal->new( date => $handler->date, user => $handler->user, config => $config );
22 my $view = OurCal::View->load_view($handler->view, config => $config->config, calendar => $cal);
23  
24 print $handler->header($view->mime_type);
25 print $view->handle($handler->mode);
26  
27 =head2 DESCRIPTION
28  
29 OurCal was written one hungover Sunday afternoon 5 years ago and hasn't
30 changed that much since. It's not a complicated calendaring system, I've
31 got other code to do that, but it's simple and extendable and it works.
32  
33 Feature wise:
34  
35 =over 4
36  
37 =item simple events
38  
39 OurCal has no concept of start or end times - an event is on a day or it
40 isn't. Surprisingly this suffices 99% of my time and makes things much
41 quicker and easier internally.
42  
43 Events can be marked up using the Chump syntax which is kind of like
44 Markdown but had the virtue of existing at the time. There's no real
45 reason why Chump couldn't be ripped out and replaced with Markdown.
46  
47 Events have a date and a description and that's pretty much it. If you
48 want more feed me beer and choclate covered coffee beans until I get
49 round to finishing EventQueue.
50  
51 =item todos
52  
53 OurCal has simple TODO items as well - these are also marked up in
54 Chump.
55  
56 =item icalendar
57  
58 OurCal can import iCalendar feeds from both local and remote sources and
59 can also export an ICS feed. Since it's all done with plugins (I loves
60 me my plugins) you could write plugins to import and export whatever you
61 want.
62  
63 =item multi user
64  
65 Nominally OurCal is multi user but there's no user management to speak
66 of and I only ever use it for one person so I wouldn't know.
67  
68 =item hCalendar
69  
70 All events use hCalendar semantic markup because I'm nothing if not
71 Buzzword Compatible.
72  
73 =item mod_perl
74  
75 There's no mod_perl or mod_perl handler at the moment but it'd be but a
76 moments work to do.
77  
78 =back
79  
80 =cut
81  
82 =head1 METHODS
83  
84  
85 =head2 new <params>
86  
87 Requires a C<config> param of type C<OurCal::Config> and a C<date> param
88 in the form C<yyyy-mm> or C<yyyy-mm-dd>. Can optionally take a user
89 param. No user validation is done.
90  
91 =cut
92  
93 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
94 0 my $class = shift;
95 0 my %opts = @_;
96 0 ▶ $opts{provider} ||= OurCal::Provider->new(config => $opts{config});
Condition0%0/3
$opts{"provider"} ||= "OurCal::Provider"->new("config", $opts{"config"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"provider"} ||= "OurCal::Provider"->new("config", $opts{"config"})
$opts{"provider"} "OurCal::Provider"->new("config", $opts{"config"})
Truth table0%0/3
A ||= B
A= $opts{"provider"}B= "OurCal::Provider"->new("config", $opts{"config"})
ABresult
1X1
011
000
97 0 return bless \%opts, $class;
98 }
99  
100 =head2 date
101  
102 Return the current date
103  
104 =cut
105  
106 0 ▶sub date {
Subroutine date: not called CC=1 SCAR=6.9
Pod documented
107 0 return $_[0]->{date};
108 }
109  
110 =head2 user
111  
112 Return the current user
113  
114 =cut
115  
116 0 ▶sub user {
Subroutine user: not called CC=1 SCAR=6.9
Pod documented
117 0 return $_[0]->{user};
118 }
119  
120 =head2 span_name
121  
122 Return the current date as a span name (month or day)
123  
124 =cut
125  
126 0 ▶sub span_name {
Subroutine span_name: not called CC=4 SCAR=30.0
Pod documented
127 0 my $self = shift;
128 0 my $date = $self->date;
129 0 ▶ if (10 == length($date)) {
Branch: 3 branches
BranchTrueFalseTotal
if (10 == length $date) { } 0 0 0
elsif (7 == length $date) { } 0 0 0
elsif (4 == length $date) { } 0 0 0
130 0 return 'day';
131 } elsif (7 == length($date)) {
132 0 return 'month';
133 } elsif (4 == length($date)) {
134 0 return 'year';
135 } else {
136 0 die "Unknown date type for $date\n";
137 }
138 }
139  
140 =head2 span
141  
142 Return the current date as an object - either an C<OurCal::Month> or
143 an C<OurCal::Day>).
144  
145 =cut
146  
147 0 ▶sub span {
Subroutine span: not called CC=4 SCAR=30.0
Pod documented
148 0 my $self = shift;
149 0 my $name = $self->span_name;
150 0 my $date = $self->date;
151 0 my %what = ( date => $date, calendar => $self );
152 0 ▶ $what{user} = $self->{user} if defined $self->user;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->user 0 0 0
153 0 ▶ if ('month' eq $name) {
Branch: 2 branches
BranchTrueFalseTotal
if ('month' eq $name) { } 0 0 0
elsif ('day' eq $name) { } 0 0 0
154 0 return OurCal::Month->new(%what);
155 } elsif ('day' eq $name) {
156 0 return OurCal::Day->new(%what);
157 }
158  
159 0 die "Don't have a handler for $name\n";
160 }
161  
162  
163 =head2 events
164  
165 Return the events for a current span as C<OurCal::Event> objects
166  
167 =cut
168  
169 0 ▶sub events {
Subroutine events: not called CC=2 SCAR=17.9
Pod documented
170 0 my $self = shift;
171 0 my %opts = @_;
172 0 ▶ $opts{user} = $self->user if defined $self->user;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->user 0 0 0
173 0 return $self->{provider}->events(%opts);
174 }
175  
176 =head2 has_events
177  
178 Return whether the current span has events
179  
180 =cut
181  
182 0 ▶sub has_events {
Subroutine has_events: not called CC=2 SCAR=17.9
Pod documented
183 0 my $self = shift;
184 0 my %opts = @_;
185 0 ▶ $opts{user} = $self->user if defined $self->user;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->user 0 0 0
186 0 return $self->{provider}->has_events(%opts);
187 }
188  
189  
190 =head2 todos
191  
192 Return all the current todos as C<OurCal::Todo> objects.
193  
194 =cut
195  
196 0 ▶sub todos {
Subroutine todos: not called CC=2 SCAR=17.9
Pod documented
197 0 my $self = shift;
198 0 my %opts = @_;
199 0 ▶ $opts{user} = $self->user if defined $self->user;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->user 0 0 0
200 0 return $self->{provider}->todos(%opts);
201 }
202  
203 =head2 users
204  
205 Returns the names of all the current users
206  
207 =cut
208  
209 0 ▶sub users {
Subroutine users: not called CC=1 SCAR=6.9
Pod documented
210 0 my $self = shift;
211 0 return $self->{provider}->users;
212 }
213  
214 =head2 save_todo C<OurCal::Todo>
215  
216 Save a TODO item
217  
218 =cut
219  
220 0 ▶sub save_todo {
Subroutine save_todo: not called CC=1 SCAR=6.9
Pod documented
221 0 my $self = shift;
222 0 my $todo = shift;
223 0 $self->{provider}->save_todo($todo)
224 }
225  
226  
227 =head2 del_todo C<OurCal::Todo>
228  
229 Delete a TODO item
230  
231 =cut
232  
233 0 ▶sub del_todo {
Subroutine del_todo: not called CC=1 SCAR=6.9
Pod documented
234 0 my $self = shift;
235 0 my $todo = shift;
236 0 $self->{provider}->del_todo($todo);
237 }
238  
239  
240 =head2 save_event C<OurCal::Event>
241  
242 Save an Event
243  
244 =cut
245  
246 0 ▶sub save_event {
Subroutine save_event: not called CC=1 SCAR=6.9
Pod documented
247 0 my $self = shift;
248 0 my $event = shift;
249 0 $self->{provider}->save_event($event);
250 }
251  
252 =head2 del_event C<OurCal::Event>
253  
254 Delete an event
255  
256 =cut
257  
258 0 ▶sub del_event {
Subroutine del_event: not called CC=1 SCAR=6.9
Pod documented
259 0 my $self = shift;
260 0 my $event = shift;
261 0 $self->{provider}->del_event($event);
262 }
263  
264 =head1 AUTHOR
265  
266 Simon Wistow <simon@thegestalt.org>
267  
268 =head1 COPYRIGHT
269  
270 Copyright, 2007 - Simon Wistow
271  
272 Distributed under the same terms as Perl itself
273  
274 =head1 SEE ALSO
275  
276 L<OurCal::Provider>, L<OurCal::View>, L<OurCal::Handler>, L<OurCal::Config>
277  
278 =cut
279  
280 2 1;
« OurCal/Span.pm ↑ Summary OurCal/View.pm »