Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Load XML-Feed-0.07 into trunk.

  • Loading branch information...
commit 23103173b588d98a69b6b3d217dc9c9a47910b02 1 parent 973e1f9
@simonwistow simonwistow authored
View
6 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.
View
1  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
View
2  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
View
22 lib/XML/Feed.pm
@@ -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>).
View
6 lib/XML/Feed/Entry.pm
@@ -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;
}
View
18 t/04-splice.t
@@ -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');
Please sign in to comment.
Something went wrong with that request. Please try again.