Load XML-Feed-0.07 into trunk. v0.07
Simon Wistow [Tue, 22 Apr 2008 18:00:37 +0000 (18:00 +0000)]
Changes
MANIFEST
META.yml
lib/XML/Feed.pm
lib/XML/Feed/Entry.pm
t/04-splice.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 732bc33..aa75576 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,7 +1,11 @@
-# $Id: Changes 1868 2005-08-09 20:42:29Z btrott $
+# $Id: Changes 1872 2005-08-12 04:28:42Z btrott $
 
 Revision history for XML::Feed
 
+0.07  2005.08.11
+    - Added XML::Feed::splice method, to make feed splicing easier.
+    - Fixed some unitialized value warnings.
+
 0.06  2005.08.09
     - Added Feed->convert and Entry->convert methods to allow conversion
       between formats.
index 3ca848a..33fd6ed 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -24,6 +24,7 @@ README
 t/00-compile.t
 t/01-parse.t
 t/02-create.t
+t/04-splice.t
 t/samples/atom.xml
 t/samples/rss10.xml
 t/samples/rss20-no-summary.xml
index 21b4070..4f750e3 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -1,5 +1,5 @@
 name: XML-Feed
-version: 0.06
+version: 0.07
 abstract: XML Syndication Feed Support
 author: Six Apart <cpan@sixapart.com>
 license: perl
index 6bb8bad..fcd30c4 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Feed.pm 1869 2005-08-10 00:02:25Z btrott $
+# $Id: Feed.pm 1872 2005-08-12 04:28:42Z btrott $
 
 package XML::Feed;
 use strict;
@@ -8,7 +8,7 @@ use Feed::Find;
 use URI::Fetch;
 use Carp;
 
-our $VERSION = '0.06';
+our $VERSION = '0.07';
 
 sub new {
     my $class = shift;
@@ -98,7 +98,9 @@ sub convert {
     my($format) = @_;
     my $new = __PACKAGE__->new($format);
     for my $field (qw( title link description language copyright modified generator )) {
-        $new->$field($feed->$field());
+        my $val = $feed->$field();
+        next unless defined $val;
+        $new->$field($val);
     }
     for my $entry ($feed->entries) {
         $new->add_entry($entry->convert($format));
@@ -106,6 +108,15 @@ sub convert {
     $new;
 }
 
+sub splice {
+    my $feed = shift;
+    my($other) = @_;
+    my %ids = map { $_->id => 1 } $feed->entries;
+    for my $entry ($other->entries) {
+        $feed->add_entry($entry) unless $ids{$entry->id}++;
+    }
+}
+
 sub format;
 sub title;
 sub link;
@@ -214,6 +225,11 @@ Returns a list of feed URIs.
 Converts the I<XML::Feed> object into the I<$format> format, and returns
 the new object.
 
+=head2 $feed->splice($other_feed)
+
+Splices in all of the entries from the feed I<$other_feed> into I<$feed>,
+skipping posts that are already in I<$feed>.
+
 =head2 $feed->format
 
 Returns the format of the feed (C<Atom>, or some version of C<RSS>).
index d64a30d..68c377c 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Entry.pm 1865 2005-08-09 20:15:31Z btrott $
+# $Id: Entry.pm 1872 2005-08-12 04:28:42Z btrott $
 
 package XML::Feed::Entry;
 use strict;
@@ -33,7 +33,9 @@ sub convert {
     my($format) = @_;
     my $new = __PACKAGE__->new($format);
     for my $field (qw( title link content summary category author id issued modified )) {
-        $new->$field($entry->$field());
+        my $val = $entry->$field();
+        next unless defined $val;
+        $new->$field($val);
     }
     $new;
 }
diff --git a/t/04-splice.t b/t/04-splice.t
new file mode 100644 (file)
index 0000000..f980d57
--- /dev/null
@@ -0,0 +1,18 @@
+# $Id: 04-splice.t 1872 2005-08-12 04:28:42Z btrott $
+
+use strict;
+use Test::More tests => 3;
+use XML::Feed;
+
+my $feed = XML::Feed->new('Atom');
+
+my $other = XML::Feed->parse('t/samples/atom.xml');
+$feed->splice($other);
+is(scalar $feed->entries, 2, '2 entries in the feed after splicing');
+
+$feed->splice($other);
+is(scalar $feed->entries, 2, 'Still 2 entries after splicing again');
+
+$other = XML::Feed->parse('t/samples/rss10.xml')->convert('Atom');
+$feed->splice($other);
+is(scalar $feed->entries, 4, 'Now 4 entries after splicing in RSS 1.0 feed');