ICal/Alarm.pm

filter: Statementstmt 100% 6 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 100% 8 / 8 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« ICal/Time.pm ↑ Summary ICal/Component.pm »
1 #!/usr/bin/perl -w
2 # vi:sts=4:shiftwidth=4
3 # -*- Mode: perl -*-
4 #======================================================================
5 #
6 # This package is free software and is provided "as is" without
7 # express or implied warranty. It may be used, redistributed and/or
8 # modified under the same terms as perl itself. ( Either the Artistic
9 # License or the GPL. )
10 #
11 # $Id: Alarm.pm,v 1.19 2001/07/19 03:32:32 srl Exp $
12 #
13 # (C) COPYRIGHT 2000-2001, Reefknot developers.
14 #
15 # See the AUTHORS file included in the distribution for a full list.
16 #======================================================================
17  
18 =head1 NAME
19  
20 Net::ICal::Alarm -- represents an alarm (a VALARM object).
21  
22 =cut
23  
24 package Net::ICal::Alarm;
25 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 ▶use base qw(Net::ICal::Component);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 use Net::ICal::Trigger;
29  
30 =head1 SYNOPSIS
31  
32 use Net::ICal;
33  
34 # simple syntax
35 $a = new Net::ICal::Alarm(action => 'DISPLAY',
36 trigger => "20000101T073000",
37 description => "Wake Up!");
38  
39 # elaborate
40 $a = new Net::ICal::Alarm (action => 'EMAIL',
41 trigger => new Net::ICal::Trigger (
42 type => 'DURATION',
43 content => new Net::ICal::Duration ("-PT5M"),
44 related => 'END
45 ),
46 attendee => [new Net::ICal::Attendee('mailto:alice@wonderland.com')],
47 summary => "mail subject",
48 description => "mail contents");
49  
50 =head1 DESCRIPTION
51  
52 This class handles reminders for Net::ICal Events and Todos. You can
53 get a reminder in several different ways (a sound played, a message
54 displayed on your screen, an email or a script/application run
55 for you) at a certain time, either relative to the Event or Todo
56 the Alarm is part of, or at a fixed date/time.
57  
58 =head1 CONSTRUCTOR
59  
60 =head2 new (optionhash)
61  
62 Create a new Alarm. The minimum options are an action, a trigger and
63 either an attach or a description.
64  
65 The action describes what type of Alarm this is going to be. See
66 L<"action"> below for possible actions. The trigger describes when
67 the alarm will be triggered. See L<"trigger"> below for an explanation.
68  
69 =begin testing
70 use Net::ICal::Alarm;
71  
72 my $a = Net::ICal::Alarm->new();
73  
74 ok(!(defined($a)), 'new Alarm with no events should fail');
75  
76  
77 $a = Net::ICal::Alarm->new( action => 'DISPLAY',
78 trigger => '-5M',
79 description => 'time for meeting');
80  
81 ok(defined($a), 'new Alarm with DISPLAY, trigger, and desc is created');
82  
83 $a = Net::ICal::Alarm->new( action => 'EMAIL',
84 trigger => '-5M',
85 description => 'time for meeting');
86  
87 ok(defined($a), 'new Alarm with EMAIL, trigger, and desc is created');
88  
89 # TODO: we need as_ical tests and such. These tests are only
90 # barely adequate.
91  
92 =end testing
93  
94 =cut
95  
96 sub new {
97 my ($class, %args) = @_;
98
99 # this implements the heart of RFC2445 4.6.6, which says what
100 # elements in an Alarm are required to be used.
101 # Anything that's "return undef" is requred.
102
103 # action and trigger are required.
104 return undef unless defined $args{'action'};
105 return undef unless defined $args{'trigger'};
106  
107 # display and email alarms must have descriptions.
108 if ($args{'action'} eq 'DISPLAY' or $args{'action'} eq 'EMAIL') {
109 return undef unless defined $args{'description'};
110 }
111 if (($args{'action'} ne 'EMAIL') and (defined $args{'attendee'})) {
112 return undef;
113 }
114  
115 # procedure alarms must invoke an attachment.
116 # TODO: Attachments? This could be (is) implemented very poorly in some
117 # of MS's software. eek.
118 #BUG: 404132
119 if ($args{'action'} eq 'PROCEDURE') {
120 return undef unless defined $args{'attach'};
121 }
122  
123 # duration and repeat must be used together or not at all.
124 if (defined $args{'duration'} xor defined $args{'repeat'}) {
125 return undef;
126 }
127  
128 #FIXME: it sucks we have to do this in every component. better
129 # try to get this into Component
130 #BUG: 233771
131 my $t = $args{'trigger'};
132 unless (ref ($t)) {
133 $args{'trigger'} = new Net::ICal::Trigger ($t);
134 }
135  
136 return &_create ($class, %args);
137 }
138  
139 #============================================================================
140 # create ($class, %args)
141 #
142 # sets up a map of the properties that N::I::Alarm objects share.
143 # See Net::ICal::Component and Class::MethodMapper if you want to know
144 # how this works. Takes a class name and a hash of arguments, returns a new
145 # Net::ICal::Alarm object.
146 #============================================================================
147 sub _create {
148 my ($class, %args) = @_;
149
150 =head1 METHODS
151  
152 =head2 action
153  
154 What the Alarm does when fired. The default type is EMAIL.
155  
156 =over 4
157  
158 =item * AUDIO - play an audio file. Requires an L<"attach"> property
159 (a soundfile).
160  
161 =item * DISPLAY - pop up a note on the screen. Requires a L<"description">
162 containing the text of the note.
163  
164 =item * EMAIL - send an email. Requires a L<"description"> containing the
165 email body and one or more L<"attendee">s for the email address(es).
166  
167 =item * PROCEDURE - trigger a procedure described by an L<"attach">
168 which is the command to execute (required).
169  
170 =back
171  
172 =head2 trigger
173  
174 The time at which to fire off the reminder. This can either be relative
175 to the Event/Todo (a L<Net::ICal::Duration> or at a fixed date/time
176 (a L<Net::ICal::Time>).
177  
178 =head2 summary
179  
180 If the Alarm has an EMAIL L<"action">, the text of the summary string
181 will be the Subject header of the email.
182  
183 =head2 description
184  
185 If the Alarm has an EMAIL L<"action">, the text of the description string
186 will be the body of the email. If the Alarm has a PROCEDURE L<"action">,
187 this is the argument string to be passed to the program.
188  
189 =head2 attach
190  
191 If the Alarm has an AUDIO L<"action">, this contains the sound to be played,
192 either as an URL or inline. If the Alarm has an EMAIL L<"action">, this
193 will be attached to the email. If the Alarm has a PROCEDURE L<"action">,
194 it contains the application to be executed.
195  
196 =head2 attendee
197  
198 If the Alarm has an EMAIL L<"action">, this contains one or more
199 L<Net::ICal::Attendee> objects that describe the email addresses of the
200 people that need to receive this Alarm.
201  
202 =head2 repeat
203  
204 The number of times the Alarm must be repeated. If you specify this,
205 you must also specify L<"duration">.
206  
207 =head2 duration
208  
209 The time before the Alarm is repeated. This is a L<Net::ICal::Duration>
210 object. If you specify this, you must also specify L<"repeat">.
211  
212 =cut
213  
214 #TODO: validation of the parameters is performed by the new method.
215 # <LotR> actually, validation needs to be consistantly put in
216 # a seperate sub
217  
218 my $map = { # RFC2445 4.6.6
219 action => { # 4.8.6.1
220 type => 'parameter',
221 doc => 'the action type of this alarm',
222 domain => 'enum',
223 options => [qw(AUDIO DISPLAY EMAIL PROCEDURE)],
224 value => 'EMAIL', # default
225 },
226 trigger => { # 4.8.6.3
227 type => 'parameter',
228 doc => 'when the alarm will be triggered',
229 domain => 'ref',
230 options => 'Net::ICal::Trigger',
231 value => undef,
232 },
233 description => { # 4.8.1.5
234 type => 'parameter',
235 doc => 'description of this alarm',
236 domain => 'param',
237 options => [qw(altrep language)],
238 value => undef,
239 },
240 # this might be better off as a class
241 attach => { #4.8.1.1
242 type => 'parameter',
243 doc => 'an attachment',
244 domain => 'param',
245 options => [qw(encoding value fmttype)],
246 value => undef,
247 },
248 summary => { # 4.8.1.12
249 type => 'parameter',
250 doc => 'the summary (subject) if this is an EMAIL alarm',
251 domain => 'param',
252 options => [qw(altrep language)],
253 value => undef,
254 },
255 attendee => { # 4.8.4.1
256 type => 'parameter',
257 doc => 'the attendees (receivers of the email) for this EMAIL alarm',
258 domain => 'ref',
259 options => 'ARRAY',
260 value => undef,
261 },
262 duration => { # 4.8.2.5
263 type => 'parameter',
264 doc => 'the delay period between alarm repetitions',
265 value => 0,
266 },
267 repeat => { # 4.8.6.2
268 type => 'parameter',
269 doc => 'the amount of times the alarm is repeated',
270 value => 0,
271 },
272 };
273 my $self = $class->SUPER::new ('VALARM', $map, %args);
274  
275 return $self;
276 }
277  
278 1;
279  
280 =head1 SEE ALSO
281  
282 More documentation pointers can be found in L<Net::ICal>.
283  
284 =cut
« ICal/Time.pm ↑ Summary ICal/Component.pm »