X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FXML%2FFeed.pm;h=db800ff8c9db587565b40805a1b0460821b3dbce;hb=9b6bc91217ad927947ab0928b240c3bc0ba599b8;hp=cd1f1e4e57d4531115690843e2bd30e9aa287da2;hpb=4e7b539fe6627cd40cbb1ef36065e13c82fc3224;p=catagits%2FXML-Feed.git diff --git a/lib/XML/Feed.pm b/lib/XML/Feed.pm index cd1f1e4..db800ff 100644 --- a/lib/XML/Feed.pm +++ b/lib/XML/Feed.pm @@ -8,8 +8,15 @@ use Feed::Find; 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; @@ -70,8 +77,23 @@ sub parse { } 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 $@; + } + 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. @@ -81,15 +103,9 @@ sub identify_format { 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 {