'HTML::TokeParser' => 0,
'List::Util' => 0,
'LWP::UserAgent' => 0,
+ 'Module::Pluggable' => 0,
'URI::Fetch' => 0,
'XML::Atom' => 0.23,
'XML::LibXML' => 1.66,
Changes
lib/XML/Feed.pm
-lib/XML/Feed/Atom.pm
lib/XML/Feed/Content.pm
lib/XML/Feed/Entry.pm
-lib/XML/Feed/RSS.pm
+lib/XML/Feed/Format/Atom.pm
+lib/XML/Feed/Format/RSS.pm
Makefile.PL
MANIFEST This list of files
MANIFEST.SKIP
t/samples/rss10.xml
t/samples/rss20-no-summary.xml
t/samples/rss20.xml
+t/pod.t
+t/pod-coverage.t
use URI::Fetch;
use LWP::UserAgent;
use Carp;
-
-our $VERSION = '0.23';
+use Module::Pluggable search_path => "XML::Feed::Format",
+ require => 1,
+ sub_name => 'formatters';
+
+our $VERSION = '0.3';
+our @formatters;
+BEGIN {
+ @formatters = __PACKAGE__->formatters;
+}
sub new {
my $class = shift;
}
sub identify_format {
- my $feed = shift;
- my($xml) = @_;
+ my $feed = shift;
+ my($xml) = @_;
+ foreach my $class (@formatters) {
+ my ($name) = ($class =~ m!([^:]+)$!);
+ # TODO ugly
+ my $tmp = $$xml;
+ return $name if eval { $class->identify(\$tmp) };
+ return $feed->error($@) if $@;
+ }
+ die "$$xml\n";
+ return $feed->error("Cannot detect feed type");
+}
+
+sub _get_first_tag {
+ my $class = shift;
+ my ($xml) = @_;
+
+
## Auto-detect feed type based on first element. This is prone
## to breakage, but then again we don't want to parse the whole
## feed ourselves.
my $first = substr $t, 0, 1;
$tag = $t, last unless $first eq '?' || $first eq '!';
}
- return $feed->error("Cannot find first element") unless $tag;
+ die ("Cannot find first element") unless $tag;
$tag =~ s/^.*://;
- if ($tag eq 'rss' || $tag eq 'RDF') {
- return 'RSS';
- } elsif ($tag eq 'feed') {
- return 'Atom';
- } else {
- return $feed->error("Cannot detect feed type");
- }
+ return $tag;
}
sub find_feeds {
use XML::Atom::Content;
+sub identify {
+ my $class = shift;
+ my $xml = shift;
+ my $tag = $class->_get_first_tag($xml);
+ return ($tag eq 'feed');
+}
+
sub init_empty {
my ($feed, %args) = @_;
$args{'Version'} ||= '1.0';
our $PREFERRED_PARSER = "XML::RSS";
+
+sub identify {
+ my $class = shift;
+ my $xml = shift;
+ my $tag = $class->_get_first_tag($xml);
+ return ($tag eq 'rss' || $tag eq 'RDF');
+}
+
sub init_empty {
my ($feed, %args) = @_;
$args{'version'} ||= '2.0';
use_ok('XML::Feed');
use_ok('XML::Feed::Entry');
-use_ok('XML::Feed::RSS');
-use_ok('XML::Feed::Atom');
+use_ok('XML::Feed::Format::RSS');
+use_ok('XML::Feed::Format::Atom');
my $feed;
my $file = 't/samples/atom.xml';
$feed = XML::Feed->parse($file);
-isa_ok($feed, 'XML::Feed::Atom');
+isa_ok($feed, 'XML::Feed::Format::Atom');
is($feed->title, 'First Weblog');
open my $fh, $file or die "Can't open $file: $!";
$feed = XML::Feed->parse($fh);
-isa_ok($feed, 'XML::Feed::Atom');
+isa_ok($feed, 'XML::Feed::Format::Atom');
is($feed->title, 'First Weblog');
seek $fh, 0, 0;
my $xml = do { local $/; <$fh> };
$feed = XML::Feed->parse(\$xml);
-isa_ok($feed, 'XML::Feed::Atom');
+isa_ok($feed, 'XML::Feed::Format::Atom');
is($feed->title, 'First Weblog');
$feed = XML::Feed->parse(URI->new("file:$file"));
-isa_ok($feed, 'XML::Feed::Atom');
+isa_ok($feed, 'XML::Feed::Format::Atom');
is($feed->title, 'First Weblog');
## Then try calling all of the unified API methods.
for my $file (sort keys %Feeds) {
my $feed = XML::Feed->parse($file) or die XML::Feed->errstr;
my($subclass) = $Feeds{$file} =~ /^(\w+)/;
- isa_ok($feed, 'XML::Feed::' . $subclass);
+ isa_ok($feed, 'XML::Feed::Format::' . $subclass);
is($feed->format, $Feeds{$file});
is($feed->language, 'en-us');
is($feed->title, 'First Weblog');
for my $format (qw( Atom RSS )) {
my $feed = XML::Feed->new($format);
- isa_ok($feed, 'XML::Feed::' . $format);
+ isa_ok($feed, 'XML::Feed::Format::' . $format);
like($feed->format, qr/^$format/, 'Format is correct');
$feed->title('My Feed');
is($feed->title, 'My Feed', 'feed title is correct');
ok($feed->as_xml, 'as_xml returns something');
my $entry = XML::Feed::Entry->new($format);
- isa_ok($entry, 'XML::Feed::Entry::' . $format);
+ isa_ok($entry, 'XML::Feed::Entry::Format::' . $format);
$entry->title('Foo Bar');
is($entry->title, 'Foo Bar', 'entry title is correct');
$entry->link('http://www.example.com/foo/bar.html');