[Bps-public-commit] Data-ICal branch, master, updated. 0.16-2-g03bae00

Jesse Vincent jesse at bestpractical.com
Sun Nov 27 16:35:47 EST 2011


The branch, master has been updated
       via  03bae00f66cbda668c02caa281df585bd0698e86 (commit)
       via  215d2d3785b7c9c371537cd8ae2dacd8d1af6655 (commit)
      from  74792f7dd9024dbb647ff374c28d28907a79b015 (commit)

Summary of changes:
 .shipit                   |    3 +--
 Changes                   |    4 ++++
 lib/Data/ICal.pm          |    2 +-
 lib/Data/ICal/Entry.pm    |   33 +++++++++++++++++++++++++++++----
 lib/Data/ICal/Property.pm |    6 +++---
 t/05.prop-params.t        |   21 +++++++++++++++++----
 6 files changed, 55 insertions(+), 14 deletions(-)

- Log -----------------------------------------------------------------
commit 215d2d3785b7c9c371537cd8ae2dacd8d1af6655
Author: H.Merijn Brand <h.m.brand at xs4all.nl>
Date:   Sun Nov 27 16:31:32 2011 -0500

    0.17
        * Allow chaining of methods (H.Merijn Brand)
        * Allow properties and entries in constructor (H.Merijn Brand)

diff --git a/Changes b/Changes
index ab4918c..c345674 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for Data-ICal
 
+0.17
+    * Allow chaining of methods (H.Merijn Brand)
+    * Allow properties and entries in constructor (H.Merijn Brand)
+
 0.16
     * Use \r\n as the newline character, per RFC 3445
     * Escaping of \ was being done incorrectly, and tested incorrectly
diff --git a/lib/Data/ICal.pm b/lib/Data/ICal.pm
index 722a58f..f75a07f 100644
--- a/lib/Data/ICal.pm
+++ b/lib/Data/ICal.pm
@@ -7,7 +7,7 @@ use base qw/Data::ICal::Entry/;
 use Class::ReturnValue;
 use Text::vFile::asData;
 
-our $VERSION = '0.16';
+our $VERSION = '0.17';
 
 use Carp;
 
diff --git a/lib/Data/ICal/Entry.pm b/lib/Data/ICal/Entry.pm
index 8f3f306..3482a35 100644
--- a/lib/Data/ICal/Entry.pm
+++ b/lib/Data/ICal/Entry.pm
@@ -15,13 +15,18 @@ Data::ICal::Entry - Represents an entry in an iCalendar file
 =head1 SYNOPSIS
 
     my $vtodo = Data::ICal::Entry::Todo->new();
-    $vtodo->add_properties(
+    $vtodo->add_property(
     # ... see Data::ICal::Entry::Todo documentation
     );
+    $vtodo->add_properties( ... );
 
     $calendar->add_entry($vtodo);
 
     $event->add_entry($alarm); 
+    $event->add_entries($alarm1, ...); 
+
+    # or all in one go
+    my $vtodo = Data::ICal::Entry::Todo->new( \%props, \@entries );
 
 =head1 DESCRIPTION
 
@@ -52,9 +57,14 @@ Creates a new entry object with no properties or sub-entries.
 
 sub new {
     my $class = shift;
-    my $self  = $class->SUPER::new;
+    my $self  = $class->SUPER::new();
+    # ALLOW passing arguments here!
     $self->set( properties => {} );
     $self->set( entries    => [] );
+    for (@_) {
+	ref $_ eq "HASH"  and $self->add_properties( %$_ );
+	ref $_ eq "ARRAY" and $self->add_entries( @$_ );
+    }
     return $self;
 }
 
@@ -127,7 +137,20 @@ sub add_entry {
 
     $entry->vcal10( $self->vcal10 );
 
-    return 1;
+    return $self;
+}
+
+=head2 add_entries $entry1, [$entry2, ...]
+
+Convenience function to call C<add_entry> several times with a list
+of entries.
+
+=cut
+
+sub add_entries {
+    my $self  = shift;
+    $self->add_entry( $_ ) for @_;
+    return $self;
 }
 
 =head2 entries
@@ -210,6 +233,7 @@ sub add_property {
     $p->vcal10( $self->vcal10 );
 
     push @{ $self->properties->{$prop} }, $p;
+    return $self;
 }
 
 =head2 add_properties $propname1 => $propval1, [$propname2 => $propname2, ...]
@@ -240,6 +264,7 @@ sub add_properties {
         my $val  = shift;
         $self->add_property( $prop => $val );
     }
+    return $self;
 }
 
 =head2 mandatory_unique_properties 
@@ -461,6 +486,7 @@ sub parse_object {
         $new_self->parse_object($sub_object);
     }
 
+    return $self;
 }
 
 # special because we want to use ourselves as the parent
@@ -496,7 +522,6 @@ sub _parse_valarm {
     $parent->_parse_generic_event( $alarm, $object );
     $parent->add_entry($alarm);
     return $alarm;
-
 }
 
 # generic event handler
diff --git a/lib/Data/ICal/Property.pm b/lib/Data/ICal/Property.pm
index 642e608..cf31e4c 100644
--- a/lib/Data/ICal/Property.pm
+++ b/lib/Data/ICal/Property.pm
@@ -161,6 +161,7 @@ sub encode {
         $self->value( $ENCODINGS{$encoding}{'encode'}->($decoded_value) );
         $self->parameters->{'ENCODING'} = $encoding;
     }
+    return $self;
 }
 
 =head2 as_string ARGS
@@ -204,9 +205,9 @@ sub as_string {
   # lines
     if ( $args{'fold'} ) {
         return $self->_fold( $string, $args{crlf} );
-    } else {
-        return $string;
     }
+
+    return $string;
 }
 
 =begin private
@@ -236,7 +237,6 @@ sub _value_as_string {
     }
 
     return $value;
-
 }
 
 =begin private
diff --git a/t/05.prop-params.t b/t/05.prop-params.t
index 4476f6c..426b244 100644
--- a/t/05.prop-params.t
+++ b/t/05.prop-params.t
@@ -3,7 +3,7 @@
 use warnings;
 use strict;
 
-use Test::More tests => 4;
+use Test::More tests => 8;
 use Test::LongString;
 use Test::NoWarnings;
 
@@ -12,15 +12,28 @@ BEGIN { use_ok('Data::ICal::Entry::Todo') }
 my $todo = Data::ICal::Entry::Todo->new();
 isa_ok($todo, 'Data::ICal::Entry::Todo');
 
-$todo->add_property( summary => [ 'Sum it up.', { language => "en-US", value => "TEXT" } ] ); 
+my $todo_prop = $todo->add_property( summary => [ 'Sum it up.', { language => "en-US", value => "TEXT" } ] ); 
+isa_ok($todo_prop, 'Data::ICal::Entry::Todo', "Check if chaining is possible");
+
 # example from RFC 2445 4.2.11
-$todo->add_properties( attendee => [ 'MAILTO:janedoe at host.com', 
+my $todo_props = $todo->add_properties( attendee => [ 'MAILTO:janedoe at host.com', 
     { member => [ 'MAILTO:projectA at host.com', 'MAILTO:projectB at host.com' ] } ]);
+isa_ok($todo_props, 'Data::ICal::Entry::Todo', "Check if chaining is possible");
 
-is_string($todo->as_string( crlf => "\n"), <<'END_VCAL', "Got the right output");
+my $expect = <<'END_VCAL';
 BEGIN:VTODO
 ATTENDEE;MEMBER="MAILTO:projectA at host.com","MAILTO:projectB at host.com":MAILT
  O:janedoe at host.com
 SUMMARY;LANGUAGE=en-US;VALUE=TEXT:Sum it up.
 END:VTODO
 END_VCAL
+
+is_string($todo->as_string( crlf => "\n"), $expect, "Got the right output");
+
+$todo = Data::ICal::Entry::Todo->new({
+    summary  => [ 'Sum it up.', { language => "en-US", value => "TEXT" } ],
+    attendee => [ 'MAILTO:janedoe at host.com', {
+	member => [ 'MAILTO:projectA at host.com', 'MAILTO:projectB at host.com' ] } ],
+});
+isa_ok($todo, 'Data::ICal::Entry::Todo');
+is_string($todo->as_string( crlf => "\n"), $expect, "Got the right output at once");

commit 03bae00f66cbda668c02caa281df585bd0698e86
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sun Nov 27 16:34:17 2011 -0500

    no need to tweet

diff --git a/.shipit b/.shipit
index 44c02c1..0d9261c 100644
--- a/.shipit
+++ b/.shipit
@@ -1,8 +1,7 @@
 # auto-generated shipit config file.
-steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN, Twitter
+steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN
 
 git.tagpattern = %v
-twitter.config = ~/.twitterrc
 
 # svn.tagpattern = MyProj-%v
 # svn.tagpattern = http://code.example.com/svn/tags/MyProj-%v

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list