Load XML-Feed-0.04 into trunk. v0.04
Simon Wistow [Tue, 22 Apr 2008 18:00:22 +0000 (18:00 +0000)]
23 files changed:
Build.PL
Changes
META.yml
Makefile.PL
README
inc/Module/Install.pm
inc/Module/Install/AutoInstall.pm
inc/Module/Install/Base.pm
inc/Module/Install/Build.pm
inc/Module/Install/Can.pm
inc/Module/Install/Fetch.pm
inc/Module/Install/Include.pm
inc/Module/Install/Makefile.pm
inc/Module/Install/Metadata.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
lib/XML/Feed.pm
lib/XML/Feed/Atom.pm
lib/XML/Feed/Content.pm
lib/XML/Feed/Entry.pm
lib/XML/Feed/RSS.pm
t/00-compile.t
t/01-parse.t

index 289c881..9d1877e 100644 (file)
--- a/Build.PL
+++ b/Build.PL
@@ -1,3 +1,3 @@
-# $Id: Build.PL,v 1.1.1.1 2004/05/29 17:29:56 btrott Exp $
+# $Id: Build.PL 918 2004-05-29 17:29:55Z btrott $
 
 require 'Makefile.PL';
diff --git a/Changes b/Changes
index 4966389..894e0ff 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,7 +1,18 @@
-# $Id: Changes,v 1.7 2004/10/09 07:02:01 btrott Exp $
+# $Id: Changes 1750 2005-01-01 00:46:40Z btrott $
 
 Revision history for XML::Feed
 
+0.04  2004.12.31
+    - Use "loose" parsing in DateTime::Format::Mail so that we don't die
+      on invalid RFC-822 dates.
+    - XML::Feed::Entry->link on RSS feeds will now use a <guid> element
+      if a <link> element isn't found.
+    - Switched to using URI::Fetch when fetching feeds. Since we're not
+      storing or caching feeds currently, this basically just buys us
+      GZIP support, but that's something.
+    - Use Class::ErrorHandler instead of XML::Feed::ErrorHandler. Thanks
+      to Tim Appnel for the patch.
+
 0.03  2004.10.09
     - Fixed bug with feed format detection: properly detect format even in
       feeds with <!DOCTYPE> at the top. (Thanks to Alberto Quario for the
index b977b45..661bc6f 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -1,12 +1,13 @@
 name: XML-Feed
-version: 0.03
+version: 0.04
 abstract: XML Syndication Feed Support
-author: Benjamin Trott <cpan@stupidfool.org>
+author: Benjamin Trott <ben+cpan@stupidfool.org>
 license: perl
 distribution_type: module
 requires:
   Class::ErrorHandler: 0
   Feed::Find: 0
+  URI::Fetch: 0
   XML::RSS: 1.01
   XML::Atom: 0.08
   LWP: 0
@@ -20,4 +21,4 @@ no_index:
   directory:
     - t
     - inc
-generated_by: Module::Install version 0.35
+generated_by: Module::Install version 0.36
index d4b38aa..1e684c0 100644 (file)
@@ -1,10 +1,10 @@
-# $Id: Makefile.PL,v 1.2 2004/10/04 03:38:11 btrott Exp $
+# $Id: Makefile.PL 942 2004-12-31 23:01:21Z btrott $
 
 use inc::Module::Install;
 
 name('XML-Feed');
 abstract('XML Syndication Feed Support');
-author('Benjamin Trott <cpan@stupidfool.org>');
+author('Benjamin Trott <ben+cpan@stupidfool.org>');
 version_from('lib/XML/Feed.pm');
 license('perl');
 no_index(directory => 't');
@@ -14,6 +14,7 @@ include('ExtUtils::AutoInstall');
 
 requires('Class::ErrorHandler');
 requires('Feed::Find');
+requires('URI::Fetch');
 requires('XML::RSS' => 1.01);
 requires('XML::Atom' => 0.08);
 requires('LWP');
diff --git a/README b/README
index 2d53c22..f553efc 100644 (file)
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-$Id: README,v 1.2 2004/10/09 07:06:11 btrott Exp $
+$Id: README 942 2004-12-31 23:01:21Z btrott $
 
 This is XML::Feed, an abstraction above the RSS and Atom syndication
 feed formats. It supports both parsing and autodiscovery of feeds.
@@ -16,6 +16,7 @@ PREREQUISITES
     * DateTime::Format::W3CDTF
     * List::Util
     * Feed::Find
+    * URI::Fetch
 
 INSTALLATION
 
@@ -33,4 +34,4 @@ Then install it:
 
     % make install
 
-Benjamin Trott / cpan@stupidfool.org
+Benjamin Trott / ben+cpan@stupidfool.org
index 24649fd..ed08a92 100644 (file)
@@ -1,9 +1,6 @@
 #line 1 "inc/Module/Install.pm - /Library/Perl/5.8.1/Module/Install.pm"
-# $File: //depot/cpan/Module-Install/lib/Module/Install.pm $ $Author: autrijus $
-# $Revision: #69 $ $Change: 2301 $ $DateTime: 2004/07/13 07:16:40 $ vim: expandtab shiftwidth=4
-
 package Module::Install;
-$VERSION = '0.35';
+$VERSION = '0.36';
 
 die << "." unless $INC{join('/', inc => split(/::/, __PACKAGE__)).'.pm'};
 Please invoke ${\__PACKAGE__} with:
@@ -24,7 +21,7 @@ use File::Path ();
 @inc::Module::Install::ISA = 'Module::Install';
 *inc::Module::Install::VERSION = *VERSION;
 
-#line 132
+#line 129
 
 sub import {
     my $class = shift;
@@ -47,7 +44,7 @@ sub import {
     delete $INC{"$self->{path}.pm"};
 }
 
-#line 159
+#line 156
 
 sub autoload {
     my $self = shift;
@@ -67,7 +64,7 @@ sub autoload {
     };
 }
 
-#line 184
+#line 181
 
 sub new {
     my ($class, %args) = @_;
@@ -92,7 +89,7 @@ sub new {
     bless(\%args, $class);
 }
 
-#line 213
+#line 210
 
 sub call {
     my $self   = shift;
@@ -103,7 +100,7 @@ sub call {
     goto &{$obj->can($method)};
 }
 
-#line 228
+#line 225
 
 sub load {
     my ($self, $method) = @_;
@@ -127,7 +124,7 @@ END
     $obj;
 }
 
-#line 258
+#line 255
 
 sub load_extensions {
     my ($self, $path, $top_obj) = @_;
@@ -146,7 +143,7 @@ sub load_extensions {
     }
 }
 
-#line 282
+#line 279
 
 sub find_extensions {
     my ($self, $path) = @_;
@@ -169,4 +166,4 @@ sub find_extensions {
 
 __END__
 
-#line 620
+#line 617
index c22821c..e6633cb 100644 (file)
@@ -1,7 +1,4 @@
 #line 1 "inc/Module/Install/AutoInstall.pm - /Library/Perl/5.8.1/Module/Install/AutoInstall.pm"
-# $File: //depot/cpan/Module-Install/lib/Module/Install/AutoInstall.pm $ $Author: autrijus $
-# $Revision: #13 $ $Change: 1846 $ $DateTime: 2003/12/31 22:57:12 $ vim: expandtab shiftwidth=4
-
 package Module::Install::AutoInstall;
 use Module::Install::Base; @ISA = qw(Module::Install::Base);
 
index ac43208..826be07 100644 (file)
@@ -1,10 +1,7 @@
 #line 1 "inc/Module/Install/Base.pm - /Library/Perl/5.8.1/Module/Install/Base.pm"
-# $File: //depot/cpan/Module-Install/lib/Module/Install/Base.pm $ $Author: autrijus $
-# $Revision: #10 $ $Change: 1847 $ $DateTime: 2003/12/31 23:14:54 $ vim: expandtab shiftwidth=4
-
 package Module::Install::Base;
 
-#line 31
+#line 28
 
 sub new {
     my ($class, %args) = @_;
@@ -18,18 +15,18 @@ sub new {
     bless(\%args, $class);
 }
 
-#line 49
+#line 46
 
 sub AUTOLOAD {
     my $self = shift;
     goto &{$self->_top->autoload};
 }
 
-#line 60
+#line 57
 
 sub _top { $_[0]->{_top} }
 
-#line 71
+#line 68
 
 sub admin {
     my $self = shift;
@@ -54,4 +51,4 @@ sub DESTROY {}
 
 __END__
 
-#line 115
+#line 112
index 6fb595e..184011b 100644 (file)
@@ -1,7 +1,4 @@
 #line 1 "inc/Module/Install/Build.pm - /Library/Perl/5.8.1/Module/Install/Build.pm"
-# $File: //depot/cpan/Module-Install/lib/Module/Install/Build.pm $ $Author: ingy $
-# $Revision: #23 $ $Change: 1255 $ $DateTime: 2003/03/05 13:23:32 $ vim: expandtab shiftwidth=4
-
 package Module::Install::Build;
 $VERSION = '0.01';
 use strict;
@@ -63,4 +60,4 @@ sub ACTION_dist {
 
 __END__
 
-#line 178
+#line 175
index fe6ac24..64202a8 100644 (file)
@@ -1,7 +1,4 @@
 #line 1 "inc/Module/Install/Can.pm - /Library/Perl/5.8.1/Module/Install/Can.pm"
-# $File: //depot/cpan/Module-Install/lib/Module/Install/Can.pm $ $Author: autrijus $
-# $Revision: #6 $ $Change: 1840 $ $DateTime: 2003/12/28 19:42:02 $ vim: expandtab shiftwidth=4
-
 package Module::Install::Can;
 use Module::Install::Base; @ISA = qw(Module::Install::Base);
 $VERSION = '0.01';
index 6c9a1d7..9b76e7e 100644 (file)
@@ -1,7 +1,4 @@
 #line 1 "inc/Module/Install/Fetch.pm - /Library/Perl/5.8.1/Module/Install/Fetch.pm"
-# $File: //depot/cpan/Module-Install/lib/Module/Install/Fetch.pm $ $Author: autrijus $
-# $Revision: #8 $ $Change: 1374 $ $DateTime: 2003/03/18 11:50:15 $ vim: expandtab shiftwidth=4
-
 package Module::Install::Fetch;
 use Module::Install::Base; @ISA = qw(Module::Install::Base);
 
index aba33b0..1329eb7 100644 (file)
@@ -1,7 +1,4 @@
 #line 1 "inc/Module/Install/Include.pm - /Library/Perl/5.8.1/Module/Install/Include.pm"
-# $File: //depot/cpan/Module-Install/lib/Module/Install/Include.pm $ $Author: autrijus $
-# $Revision: #9 $ $Change: 2288 $ $DateTime: 2004/07/01 04:49:12 $ vim: expandtab shiftwidth=4
-
 package Module::Install::Include;
 use Module::Install::Base; @ISA = qw(Module::Install::Base);
 
index 41dff0c..e2f7e39 100644 (file)
@@ -1,7 +1,4 @@
 #line 1 "inc/Module/Install/Makefile.pm - /Library/Perl/5.8.1/Module/Install/Makefile.pm"
-# $File: //depot/cpan/Module-Install/lib/Module/Install/Makefile.pm $ $Author: autrijus $
-# $Revision: #53 $ $Change: 1847 $ $DateTime: 2003/12/31 23:14:54 $ vim: expandtab shiftwidth=4
-
 package Module::Install::Makefile;
 use Module::Install::Base; @ISA = qw(Module::Install::Base);
 
@@ -143,4 +140,4 @@ sub postamble {
 
 __END__
 
-#line 276
+#line 273
index b966264..a839a10 100644 (file)
@@ -1,7 +1,4 @@
 #line 1 "inc/Module/Install/Metadata.pm - /Library/Perl/5.8.1/Module/Install/Metadata.pm"
-# $File: //depot/cpan/Module-Install/lib/Module/Install/Metadata.pm $ $Author: autrijus $
-# $Revision: #32 $ $Change: 1885 $ $DateTime: 2004/03/11 05:55:27 $ vim: expandtab shiftwidth=4
-
 package Module::Install::Metadata;
 use Module::Install::Base; @ISA = qw(Module::Install::Base);
 
index a72d8ed..119ae8c 100644 (file)
@@ -1,7 +1,4 @@
 #line 1 "inc/Module/Install/Win32.pm - /Library/Perl/5.8.1/Module/Install/Win32.pm"
-# $File: //depot/cpan/Module-Install/lib/Module/Install/Win32.pm $ $Author: autrijus $
-# $Revision: #9 $ $Change: 1789 $ $DateTime: 2003/11/11 01:22:54 $ vim: expandtab shiftwidth=4
-
 package Module::Install::Win32;
 use Module::Install::Base; @ISA = qw(Module::Install::Base);
 
index 8418d98..b1ec113 100644 (file)
@@ -1,7 +1,4 @@
 #line 1 "inc/Module/Install/WriteAll.pm - /Library/Perl/5.8.1/Module/Install/WriteAll.pm"
-# $File: //depot/cpan/Module-Install/lib/Module/Install/WriteAll.pm $ $Author: autrijus $
-# $Revision: #3 $ $Change: 1885 $ $DateTime: 2004/03/11 05:55:27 $ vim: expandtab shiftwidth=4
-
 package Module::Install::WriteAll;
 use Module::Install::Base; @ISA = qw(Module::Install::Base);
 
index ea475cb..53faed9 100644 (file)
@@ -1,15 +1,13 @@
-# $Id: Feed.pm,v 1.10 2004/10/09 07:05:08 btrott Exp $
+# $Id: Feed.pm 942 2004-12-31 23:01:21Z btrott $
 
 package XML::Feed;
 use strict;
 
 use base qw( Class::ErrorHandler );
-use LWP::UserAgent;
-use HTML::Parser;
 use Feed::Find;
+use URI::Fetch;
 
-use vars qw( $VERSION );
-$VERSION = '0.03';
+our $VERSION = '0.04';
 
 sub parse {
     my $class = shift;
@@ -18,12 +16,11 @@ sub parse {
     my $feed = bless {}, $class;
     my $xml = '';
     if (UNIVERSAL::isa($stream, 'URI')) {
-        my $ua = LWP::UserAgent->new;
-        my $req = HTTP::Request->new(GET => $stream);
-        my $res = $ua->request($req);
-        if ($res->is_success) {
-            $xml = $res->content;
-        }
+        my $res = URI::Fetch->fetch($stream)
+            or return $class->error(URI::Fetch->errstr);
+        return $class->error("This feed has been permanently removed")
+            if $res->status == URI::Fetch::FEED_GONE();
+        $xml = $res->content;
     } elsif (ref($stream) eq 'SCALAR') {
         $xml = $$stream;
     } elsif (ref($stream)) {
@@ -40,28 +37,37 @@ 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_class = join '::', __PACKAGE__, $format;
+    eval "use $format_class";
+    return $class->error("Unsupported format $format: $@") if $@;
+    bless $feed, $format_class;
+    $feed->init_string(\$xml) or return $class->error($feed->errstr);
+    $feed;
+}
+
+sub identify_format {
+    my $feed = 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 $tag;
-    while ($xml =~ /<(\S+)/sg) {
+    while ($$xml =~ /<(\S+)/sg) {
         (my $t = $1) =~ tr/a-zA-Z0-9:\-\?!//cd;
         my $first = substr $t, 0, 1;
         $tag = $t, last unless $first eq '?' || $first eq '!';
     }
-    return $class->error("Cannot find first element") unless $tag;
+    return $feed->error("Cannot find first element") unless $tag;
     $tag =~ s/^.*://;
     if ($tag eq 'rss' || $tag eq 'RDF') {
-        require XML::Feed::RSS;
-        bless $feed, 'XML::Feed::RSS';
+        return 'RSS';
     } elsif ($tag eq 'feed') {
-        require XML::Feed::Atom;
-        bless $feed, 'XML::Feed::Atom';
+        return 'Atom';
     } else {
-        return $class->error("Cannot detect feed type");
+        return $feed->error("Cannot detect feed type");
     }
-    $feed->init_string($xml) or return;
-    $feed;
 }
 
 sub find_feeds {
@@ -217,6 +223,6 @@ under the same terms as Perl itself.
 =head1 AUTHOR & COPYRIGHT
 
 Except where otherwise noted, I<XML::Feed> is Copyright 2004 Benjamin
-Trott, cpan@stupidfool.org. All rights reserved.
+Trott, ben+cpan@stupidfool.org. All rights reserved.
 
 =cut
index 4cc500d..0ae1ad3 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Atom.pm,v 1.2 2004/06/20 15:20:37 btrott Exp $
+# $Id: Atom.pm 942 2004-12-31 23:01:21Z btrott $
 
 package XML::Feed::Atom;
 use strict;
@@ -11,8 +11,10 @@ use List::Util qw( first );
 sub init_string {
     my $feed = shift;
     my($str) = @_;
-    $feed->{atom} = XML::Atom::Feed->new(Stream => \$str)
-        or return $feed->error(XML::Atom::Feed->errstr);
+    if ($str) {
+        $feed->{atom} = XML::Atom::Feed->new(Stream => $str)
+            or return $feed->error(XML::Atom::Feed->errstr);
+    }
     $feed;
 }
 
index 8b1eb43..c1bf0c2 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Content.pm,v 1.2 2004/10/04 03:38:11 btrott Exp $
+# $Id: Content.pm 937 2004-10-04 03:38:11Z btrott $
 
 package XML::Feed::Content;
 use strict;
index a323cb3..5221e6a 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Entry.pm,v 1.3 2004/07/29 16:42:29 btrott Exp $
+# $Id: Entry.pm 942 2004-12-31 23:01:21Z btrott $
 
 package XML::Feed::Entry;
 use strict;
@@ -47,7 +47,7 @@ The title of the entry.
 =head2 $entry->link
 
 The permalink of the entry, in most cases, except in cases where it points
-instead of an offsite URI referenced in the entry.
+instead to an offsite URI referenced in the entry.
 
 =head2 $entry->content
 
index 473d445..3f992ef 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: RSS.pm,v 1.5 2004/07/29 16:42:29 btrott Exp $
+# $Id: RSS.pm 942 2004-12-31 23:01:21Z btrott $
 
 package XML::Feed::RSS;
 use strict;
@@ -13,7 +13,7 @@ sub init_string {
     my($str) = @_;
     my $rss = $feed->{rss} = XML::RSS->new;
     if ($str) {
-        $rss->parse($str);
+        $rss->parse($$str);
     }
     $feed;
 }
@@ -70,7 +70,7 @@ use XML::Feed::Content;
 use base qw( XML::Feed::Entry );
 
 sub title { $_[0]->{entry}{title} }
-sub link { $_[0]->{entry}{link} }
+sub link { $_[0]->{entry}{link} || $_[0]->{entry}{guid} }
 
 sub summary {
     my $item = $_[0]->{entry};
@@ -113,7 +113,9 @@ sub id {
 
 sub issued {
     if (my $ts = $_[0]->{entry}{pubDate}) {
-        return DateTime::Format::Mail->parse_datetime($ts);
+        my $parser = DateTime::Format::Mail->new;
+        $parser->loose;
+        return $parser->parse_datetime($ts);
     } elsif ($ts = $_[0]->{entry}{dc}{date}) {
         return DateTime::Format::W3CDTF->parse_datetime($ts);
     }
index ec6105d..b555c62 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: 00-compile.t,v 1.1 2004/05/29 18:19:50 btrott Exp $
+# $Id: 00-compile.t 922 2004-05-29 18:19:50Z btrott $
 
 my $loaded;
 BEGIN { print "1..1\n" }
index 24217e7..bce2f91 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: 01-parse.t,v 1.5 2004/07/29 16:43:33 btrott Exp $
+# $Id: 01-parse.t 933 2004-07-29 16:43:33Z btrott $
 
 use strict;
 use Test;