From: Simon Wistow Date: Fri, 22 Aug 2008 19:39:09 +0000 (+0000) Subject: Allow specification of the parsing format. X-Git-Tag: v0.20~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=41e8c13262c0f94a2bddd6e8e7d1a15e8749a5fd;p=catagits%2FXML-Feed.git Allow specification of the parsing format. Fix http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=477394 --- diff --git a/Changes b/Changes index f3114f2..1f12452 100644 --- 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. diff --git a/lib/XML/Feed.pm b/lib/XML/Feed.pm index 359730e..5535593 100644 --- a/lib/XML/Feed.pm +++ b/lib/XML/Feed.pm @@ -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 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