| 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 | use strict; | ||
| 26 | use Net::ICal::Util qw(:all); | ||
| 27 | |||
| 28 | use base qw(Net::ICal::ETJ); | ||
| 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 | my ($class, %args) = @_; | ||
| 168 | |||
| 169 | #TODO: check for args that are specifically required in Events. | ||
| 170 | #BUG: 424137 | ||
| 171 | |||
| 172 | my $self = &_create ($class, %args); | ||
| 173 | $self->_init; | ||
| 174 | |||
| 175 | return undef unless ($self and $self->validate); | ||
| 176 | |||
| 177 | return $self; | ||
| 178 | } | ||
| 179 | |||
| 180 | sub validate { | ||
| 181 | my ($self) = @_; | ||
| 182 | |||
| 183 | unless (defined $self->dtstart) { | ||
| 184 | add_validation_error ($self, "You must have a dtstart in an Event"); | ||
| 185 | } | ||
| 186 | |||
| 187 | if (defined $self->dtend and $self->duration) { | ||
| 188 | add_validation_error ($self, "Can't have both dtend and duration in one Event"); | ||
| 189 | } | ||
| 190 | |||
| 191 | return $self->SUPER::validate; | ||
| 192 | } | ||
| 193 | |||
| 194 | sub _create { | ||
| 195 | my ($class, %args) = @_; | ||
| 196 | |||
| 197 | 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 | 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 | $self->set_map (%$map); | ||
| 220 | $self->set (%args); | ||
| 221 | |||
| 222 | return $self; | ||
| 223 | } | ||
| 224 | |||
| 225 | 1; | ||
| 226 | |||
| 227 | =head1 SEE ALSO | ||
| 228 | |||
| 229 | More documentation pointers can be found in L<Net::ICal>. | ||
| 230 | |||
| 231 | =cut |