[Rt-commit] r4466 - in Data-ICal: . lib/Data/ICal

glasser at bestpractical.com glasser at bestpractical.com
Fri Feb 3 12:26:13 EST 2006


Author: glasser
Date: Fri Feb  3 12:26:11 2006
New Revision: 4466

Modified:
   Data-ICal/   (props changed)
   Data-ICal/lib/Data/ICal.pm
   Data-ICal/lib/Data/ICal/Entry.pm

Log:
 r53600 at david-glassers-powerbook-g4-15:  glasser | 2006-02-03 11:06:54 -0500
 Create vCal 1.0 flag.


Modified: Data-ICal/lib/Data/ICal.pm
==============================================================================
--- Data-ICal/lib/Data/ICal.pm	(original)
+++ Data-ICal/lib/Data/ICal.pm	Fri Feb  3 12:26:11 2006
@@ -56,14 +56,18 @@
 
 =cut
 
-=head2 new [ data => $data, ] [ filename => $file ]
+=head2 new [ data => $data, ] [ filename => $file ], [ vcal10 => $bool ]
 
 Creates a new L<Data::ICal> object. 
 
 If it is given a filename or data argument is passed, then this parses the
-content of the file or string into the object; otherwise it just sets its
-C<VERSION> and C<PRODID> properties to "2.0" and the value of the C<product_id>
-method respectively.
+content of the file or string into the object.  If the C<vcal10> flag is passed,
+parses it according to vCalendar 1.0, not iCalendar 2.0; this in particular impacts
+the parsing of continuation lines in quoted-printable sections.
+
+If a filename or data argument is not passed, this just sets its C<VERSION> and
+C<PRODID> properties to "2.0" (or "1.0" if the C<vcal10> flag is passed) and
+the value of the C<product_id> method respectively.
 
 Returns undef upon failure to open or parse the file or data.
 
@@ -73,11 +77,20 @@
     my $class = shift;
     my $self  = $class->SUPER::new(@_);
 
-    if (@_) {
-        $self->parse(@_) || return;
+    my %args = (
+        filename => undef,
+        data     => undef,
+        vcal10   => 0,
+        @_
+    );
+
+    $self->vcal10($args{vcal10});
+
+    if (defined $args{filename} or defined $args{data}) {
+        $self->parse(%args) || return;
     } else {
         $self->add_properties(
-            version => '2.0',
+            version => ($self->vcal10 ? '1.0' : '2.0'),
             prodid  => $self->product_id,
         );
     }

Modified: Data-ICal/lib/Data/ICal/Entry.pm
==============================================================================
--- Data-ICal/lib/Data/ICal/Entry.pm	(original)
+++ Data-ICal/lib/Data/ICal/Entry.pm	Fri Feb  3 12:26:11 2006
@@ -2,6 +2,7 @@
 use strict;
 
 package Data::ICal::Entry;
+use base qw/Class::Accessor/;
 use Data::ICal::Property;
 use Carp;
 
@@ -49,11 +50,9 @@
 
 sub new {
     my $class = shift;
-    my $self  = {
-        properties => {},
-        entries    => [],
-    };
-    bless $self, $class;
+    my $self = $class->SUPER::new;
+    $self->set(properties => {});
+    $self->set(entries => []);
     return $self;
 }
 
@@ -113,6 +112,8 @@
     my $entry = shift;
     push @{ $self->{entries} }, $entry;
 
+    $entry->vcal10( $self->vcal10 );
+
     return 1;
 }
 
@@ -122,10 +123,7 @@
 
 =cut
 
-sub entries {
-    my $self = shift;
-    return $self->{'entries'};
-}
+__PACKAGE__->mk_ro_accessors('entries');
 
 =head2 properties
 
@@ -134,10 +132,7 @@
 
 =cut
 
-sub properties {
-    my $self = shift;
-    return $self->{'properties'};
-}
+__PACKAGE__->mk_ro_accessors('properties');
 
 =head2 property
 
@@ -345,6 +340,17 @@
 
 sub ical_entry_type {'UNDEFINED'}
 
+=head2 vcal10 [$bool]
+
+Gets or sets a boolean saying whether this entry should be interpreted as vCalendar
+1.0 (as opposed to iCalendar 2.0).  Generally, you can just set this on your
+main L<Data::ICal> object when you construct it; C<add_entry> automatically makes
+sure that sub-entries end up with the same value as their parents.
+
+=cut
+
+__PACKAGE__->mk_accessors('vcal10');
+
 =head2 header
 
 Returns the header line for the entry (including trailing newline).


More information about the Rt-commit mailing list