Allow specification of the parsing format.
Simon Wistow [Fri, 22 Aug 2008 19:39:09 +0000 (19:39 +0000)]
Fix http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=477394

Changes
lib/XML/Feed.pm

diff --git a/Changes b/Changes
index f3114f2..1f12452 100644 (file)
--- a/Changes
+++ b/Changes
@@ -2,6 +2,11 @@
 
 Revision history for XML::Feed
 
+0.20  
+    - Allow specification of the parsing format. Fixes bugs
+      http://rt.cpan.org/Public/Bug/Display.html?id=35580 and
+      http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=477394
+
 0.12  2006.08.13
     - Generate Atom 1.0 feeds by default. Thanks to Tatsuhiko Miyagawa for
       the patch.
index 359730e..5535593 100644 (file)
@@ -26,7 +26,7 @@ sub init_empty { 1 }
 
 sub parse {
     my $class = shift;
-    my($stream) = @_;
+    my($stream, $specified_format) = @_;
     return $class->error("Stream parameter is required") unless $stream;
     my $feed = bless {}, $class;
     my $xml = '';
@@ -52,8 +52,13 @@ sub parse {
     }
     return $class->error("Can't get feed XML content from $stream")
         unless $xml;
-    my $format = $feed->identify_format(\$xml)
-        or return $class->error($feed->errstr);
+    my $format;
+    if ($specified_format) {
+        $format = $specified_format;
+    } else {
+        $feed->identify_format(\$xml) or return $class->error($feed->errstr);
+    }
+
     my $format_class = join '::', __PACKAGE__, $format;
     eval "use $format_class";
     return $class->error("Unsupported format $format: $@") if $@;
@@ -190,6 +195,8 @@ Creates a new empty I<XML::Feed> object using the format I<$format>.
 
 =head2 XML::Feed->parse($stream)
 
+=head2 XML::Feed->parse($stream, $format)
+
 Parses a syndication feed identified by I<$stream>. I<$stream> can be any
 one of the following:
 
@@ -213,6 +220,8 @@ A URI from which the feed XML will be retrieved.
 
 =back
 
+C<$format> allows you to override format guessing.
+
 =head2 XML::Feed->find_feeds($uri)
 
 Given a URI I<$uri>, use auto-discovery to find all of the feeds linked