ICal/FreebusyItem.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 52 CC 7 SCAR 35.1
CC
7
Cov
0%
new
56.0
_create
2.0
BEGIN
2.0
CRAP 33.5
1 #!/usr/bin/perl -w
2 # -*- Mode: perl -*-
3 #======================================================================
4 #
5 # This package is free software and is provided "as is" without
6 # express or implied warranty. It may be used, redistributed and/or
7 # modified under the same terms as perl itself. ( Either the Artistic
8 # License or the GPL. )
9 #
10 # $Id: FreebusyItem.pm,v 1.8 2001/08/04 04:59:36 srl Exp $
11 #
12 # (C) COPYRIGHT 2000-2001, Reefknot developers.
13 #
14 # See the AUTHORS file included in the distribution for a full list.
15 #======================================================================
16  
17 =head1 NAME
18  
19 Net::ICal::FreebusyItem -- represents the FREEBUSY property for
20 VFREEBUSY objects.
21  
22 =cut
23  
24 package Net::ICal::FreebusyItem;
25 use strict;
26  
27 use base qw(Net::ICal::Property);
28  
29 use Net::ICal::Duration;
30 use Net::ICal::Time;
31  
32 =head1 SYNOPSIS
33  
34 use Net::ICal;
35  
36 my $p1 = Net::ICal::Period->new("19970101T120000","19970101T123000");
37 my $p2 = Net::ICal::Period->new("19970101T133000","19970101T140000");
38  
39 my $item1 = Net::ICal::FreebusyItem->new($p1, (fbtype => 'BUSY'));
40 my $item2 = Net::ICal::FreebusyItem->new($p2, (fbtype => 'BUSY'));
41  
42 # TODO: we ought to be able to do things like:
43 my $item3 = Net::ICal::FreebusyItem->new([$p1, $p2], (fbtype => 'BUSY'));
44 # so that both items show up on the same line.
45  
46 =head1 DESCRIPTION
47  
48 FreebusyItems are used to mark sections of time that are free to
49 be scheduled or that are already busy.
50  
51 =head1 CONSTRUCTORS
52  
53 =head2 new ($period, %options)
54  
55 $period is a Net::ICal::Period object. In the future, this
56 will change to be an array of Periods. Valid keys for the options
57 hash are:
58  
59 =over 4
60  
61 =item * fbtype - can be BUSY, FREE, BUSY-UNAVAILABLE, or BUSY-TENTATIVE;
62 defaults to BUSY.
63 BUSY means there's already something scheduled in this time slot. FREE
64 means that this time slot is open. BUSY-UNAVAILABLE means that this
65 time slot can't be scheduled. BUSY-TENTATIVE means that this time slot
66 has something tentatively scheduled for it.
67  
68 =back
69  
70 =begin testing
71  
72 use Net::ICal::FreebusyItem;
73 use Net::ICal::Period;
74  
75 my $p1 = Net::ICal::Period->new("19970101T120000","19970101T123000");
76 my $p2 = Net::ICal::Period->new("19970101T133000","19970101T140000");
77  
78 my $item1 = Net::ICal::FreebusyItem->new(); # should fail
79 ok(!defined($item1), 'new FreebusyItem without args should fail');
80  
81 $item1 = Net::ICal::FreebusyItem->new($p1, (fbtype => 'BUSY'));
82 my $item2 = Net::ICal::FreebusyItem->new($p2, (fbtype => 'BUSY'));
83  
84 ok(defined($item1), "creation of basic freebusyitem works");
85  
86 my $item1_ical = $item1->as_ical;
87  
88 ok(defined ($item1_ical), 'as_ical produces a defined result');
89  
90 $item1a = Net::ICal::FreebusyItem->new_from_ical($item1_ical);
91  
92 ok(defined($item1a),
93 "exporting ical and reading it back in creates a defined object");
94  
95 ok($item1->as_ical eq $item1a->as_ical,
96 "exporting ical and reading it back in creates an identical object");
97
98 TODO: {
99 # TODO: we ought to be able to do things like:
100 my $item3 = Net::ICal::FreebusyItem->new([$p1, $p2], (fbtype => 'BUSY'));
101 # so that both items show up on the same line.
102
103 local $TODO = 'allow freebusy items to be created with arrays of periods';
104 ok(defined($item3), "freebusy items can be created with arrays of periods");
105  
106 };
107  
108 =end testing
109  
110 =cut
111  
112 sub new {
113 my ($class, $content, %args) = @_;
114  
115 my $ref = ref ($content);
116 return undef unless %args;
117  
118 unless ($ref) {
119 if ($content =~ /^[\+-]?P/) {
120 %args = (content => new Net::ICal::Period ($content));
121 } else {
122 # explicitly set everything to default
123 %args = (content => Net::ICal::Period->new ($content));
124 }
125 } elsif ($ref eq 'Net::ICal::Period') {
126 %args = (content => $content);
127 } elsif ($ref eq 'ARRAY') {
128 # FIXME: support arrays of periods so that multiple periods can
129 # be on one FREEBUSY line separated by commas, as required by the RFC.
130 warn "Arrays of Periods aren't yet supported";
131 return undef;
132  
133 } else {
134 warn "Argument $content is not a valid Period";
135 return undef;
136 }
137  
138 # set up the default fbtype
139 $args{fbtype} = 'BUSY' unless $args{fbtype};
140  
141 return &_create ($class, %args);
142 }
143  
144 sub _create {
145 my ($class, %args) = @_;
146  
147 my $map = {
148 fbtype => { # RFC2445 4.2.9
149 type => 'parameter',
150 doc => '',
151 domain => 'enum',
152 options => [qw(FREE BUSY BUSY-UNAVAILABLE BUSY-TENTATIVE)],
153 # "The value FREE indicates that the time interval is free for scheduling.
154 # The value BUSY indicates that the time interval is busy because one
155 # or more events have been scheduled for that interval. The value
156 # BUSY-UNAVAILABLE indicates that the time interval is busy and that
157 # the interval can not be scheduled. The value BUSY-TENTATIVE indicates
158 # that the time interval is busy because one or more events have been
159 # tentatively scheduled for that interval. If not specified on a
160 # property that allows this parameter, the default is BUSY." -- RFC2445
161
162 # FIXME this is actually a property that goes on the same line as a FREEBUSY.
163 },
164 content => {
165 type => 'volatile',
166 doc => 'the value of the trigger',
167 domain => 'reclass',
168 options => {default => 'Net::ICal::Period'},
169 value => undef,
170 },
171 };
172  
173 my $self = $class->SUPER::new ('FREEBUSY', $map, %args);
174 return $self;
175 }
176  
177 1;
178 __END__