-# $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.
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
name: XML-Feed
-version: 0.06
+version: 0.07
abstract: XML Syndication Feed Support
author: Six Apart <cpan@sixapart.com>
license: perl
-# $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;
use URI::Fetch;
use Carp;
-our $VERSION = '0.06';
+our $VERSION = '0.07';
sub new {
my $class = shift;
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));
$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;
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>).
-# $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;
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;
}
--- /dev/null
+# $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');