File Coverage

blib/lib/Net/ICal/Event.pm
Criterion Covered Total %
statement 20 26 76.9
branch 3 6 50.0
condition 2 6 33.3
subroutine 5 6 83.3
pod 2 2 100.0
total 32 46 69.5


line stmt bran cond sub pod time code
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: Event.pm,v 1.20 2001/08/04 04:59:36 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::Event -- Event class
21              
22             =cut
23              
24             package Net::ICal::Event;
25 1     1   5 use strict;
  1         1  
  1         39  
26 1     1   6 use Net::ICal::Util qw(:all);
  1         2  
  1         100  
27              
28 1     1   6 use base qw(Net::ICal::ETJ);
  1         1  
  1         317  
29              
30             =head1 SYNOPSIS
31              
32             use Net::ICal::Event;
33              
34             my $e = new Net::ICal::Event (
35             organizer => new Net::ICal::Attendee('alice'),
36             uid => 'fooid',
37             alarms => [Net::ICal::Event objects],
38             dtstart => new Net::ICal::Time("20010207T160000Z"),
39             summary => 'tea with the white rabbit',
40             );
41              
42              
43             =head1 DESCRIPTION
44              
45             Net::ICal::Event represents iCalendar events.
46              
47             =pod
48              
49             =head1 BASIC METHODS
50              
51             =head2 new($args)
52              
53             Construct a new Event. Parameters are in a hash.
54             Meaningful parameters are:
55              
56              
57             =head2 REQUIRED
58              
59             =over 4
60              
61             =item * dtstart - a Net::ICal::Time for when this event starts.
62              
63             =item * dtend - a Net::ICal::Time for the end of this event. Use either
64             this OR a duration (below). Use when the ending time of an event is fixed
65             ("I have to leave at 3pm to pick up my child.")
66              
67             =item * duration - a Net::ICal::Duration; how long this event lasts. Use
68             for things like plane flights - "The trip will take 2 hours, no matter
69             when the plane takes off. If I start late, I end late." Use either
70             this OR a dtend, above.
71              
72             =item * organizer - a Net::ICal::Attendee for who's organizing this meeting.
73              
74             =back
75              
76             =head2 OPTIONAL
77              
78             =over 4
79              
80             =item * attendee - who's going to be at this meeting; an array of
81             Net::ICal::Attendee objects.
82              
83             =item * categories - what categories this event falls into. Make up
84             your own categories. Optional.
85              
86             =item * comment - a hash like that for description (above), comments
87             on this event.
88              
89             =item * contact - a string describing who to contact about this event.
90              
91             =item * request_status - how successful we've been at scheduling this event
92             so far. Values can be integers separated by periods. 1.x.y is a preliminary
93             success, 2.x.y is a complete successful request, 3.x.y is a failed request
94             because of bad iCal format, 4.x.y is a calendar server failure.
95              
96             =item * related_to - an array of other Event, Todo, or Journal objects this
97             Event is related to.
98              
99             =item * resources - resources (such as an overhead projector) required for
100             this event.
101              
102             =item * sequence - an integer that starts at 0 when this object is
103             created and is incremented every time the object is changed.
104              
105             =back
106              
107             =head2 RECURRING EVENTS
108              
109             =over 4
110              
111             =item * recurrence_id - if this event occurs multiple times, which occurrence of
112             it is this particular event?
113              
114             =item * rdate - an array of Net::ICal::Time objects describing repeated occurrences
115             of this event.
116              
117             =item * rrule - an array of Net::ICal::Recurrence objects telling when
118             this event repeats.
119              
120             =item * exdate - a Net::ICal::Time giving a single-date exception to a
121             recurring event.
122              
123             =item * exrule - an array of Net::ICal::Recurrence objects giving a
124             recurring exception to a recurring event.
125              
126             =back
127              
128             =begin testing
129              
130             use Net::ICal::Event;
131              
132             my $e = Net::ICal::Event->new();
133              
134             ok(!(defined($e)), 'new() called with no params should fail');
135              
136             # FIXME: grah, this should work; DWIM.
137             $e = Net::ICal::Event->new(dtstart => '20011031Z');
138              
139             ok(defined($e), 'new() called with only dtstart(string) should succeed');
140              
141             $e = Net::ICal::Event->new(dtstart => Net::ICal::Time->new(
142             ical => '20011031Z')
143             );
144              
145             ok(defined($e), 'new() called with only dtstart(object) should succeed');
146              
147              
148             # output this object as ical, then read it back in from ical and test
149             # to make sure nothing changed. This is the only way I can see to
150             # sanely test creation of complex objects.
151              
152             my $e_ical = $e->as_ical;
153             my $e2 = Net::ICal::Event->new_from_ical($e_ical);
154             ok(defined($e2), "reading in iCal I created succeeds at a basic level");
155              
156             print "e2 dtstart is " . $e2->dtstart()->as_ical . "\n";
157             print "e dtstart is " . $e->dtstart()->as_ical . "\n";
158              
159             ok(($e2->dtstart->as_ical eq $e->dtstart->as_ical), 'iCal output and reimport of simple event works');
160              
161             =end testing
162              
163             =cut
164              
165              
166             sub new {
167 0     0 1 0 my ($class, %args) = @_;
168              
169             #TODO: check for args that are specifically required in Events.
170             #BUG: 424137
171              
172 0         0 my $self = &_create ($class, %args);
173 0         0 $self->_init;
174              
175 0 0 0     0 return undef unless ($self and $self->validate);
176              
177 0         0 return $self;
178             }
179              
180             sub validate {
181 8     8 1 14 my ($self) = @_;
182              
183 8 100       44 unless (defined $self->dtstart) {
184 4         104 add_validation_error ($self, "You must have a dtstart in an Event");
185             }
186              
187 8 50 66     219 if (defined $self->dtend and $self->duration) {
188 0         0 add_validation_error ($self, "Can't have both dtend and duration in one Event");
189             }
190              
191 8         333 return $self->SUPER::validate;
192             }
193              
194             sub _create {
195 8     8   20 my ($class, %args) = @_;
196              
197 8         42 my $self = $class->SUPER::_create ('VEVENT');
198              
199             #TODO: modify the map to include map values that are specific
200             # to Events, if any.
201             #BUG: 424139
202 8         79 my $map = {
203             dtend => { # 4.8.2.2
204             type => 'parameter',
205             doc => 'when this event ends',
206             domain => 'ref',
207             options => 'Net::ICal::Time',
208             value => undef,
209             },
210             transp => { # 4.8.2.7
211             type => 'parameter',
212             doc => 'does this event block out time',
213             domain => 'enum',
214             options => [qw(OPAQUE TRANSPARENT)],
215             value => undef,
216             },
217             };
218              
219 8         43 $self->set_map (%$map);
220 8         119 $self->set (%args);
221              
222 8         52 return $self;
223             }
224              
225             1;
226              
227             =head1 SEE ALSO
228              
229             More documentation pointers can be found in L.
230              
231             =cut