Up version
[catagits/XML-Feed.git] / lib / XML / Feed.pm
index 864d2b5..59c25b6 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Feed.pm 1927 2006-03-07 02:29:25Z btrott $
+# $Id: Feed.pm 1958 2006-08-14 05:31:27Z btrott $
 
 package XML::Feed;
 use strict;
@@ -6,19 +6,19 @@ use strict;
 use base qw( Class::ErrorHandler );
 use Feed::Find;
 use URI::Fetch;
+use LWP::UserAgent;
 use Carp;
 
-our $VERSION = '0.09';
+our $VERSION = '0.22';
 
 sub new {
     my $class = shift;
-    my($format) = @_;
-    $format ||= 'Atom';
+    my $format = shift || 'Atom';
     my $format_class = 'XML::Feed::' . $format;
     eval "use $format_class";
     Carp::croak("Unsupported format $format: $@") if $@;
     my $feed = bless {}, join('::', __PACKAGE__, $format);
-    $feed->init_empty or return $class->error($feed->errstr);
+    $feed->init_empty(@_) or return $class->error($feed->errstr);
     $feed;
 }
 
@@ -26,12 +26,14 @@ 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 = '';
     if (UNIVERSAL::isa($stream, 'URI')) {
-        my $res = URI::Fetch->fetch($stream)
+        my $ua  = LWP::UserAgent->new;
+        $ua->env_proxy; # force allowing of proxies
+        my $res = URI::Fetch->fetch($stream, UserAgent => $ua)
             or return $class->error(URI::Fetch->errstr);
         return $class->error("This feed has been permanently removed")
             if $res->status == URI::Fetch::URI_GONE();
@@ -52,8 +54,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 {
+        $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 $@;
@@ -120,6 +127,7 @@ sub splice {
 sub format;
 sub title;
 sub link;
+sub self_link;
 sub description;
 sub language;
 sub author;
@@ -129,6 +137,7 @@ sub generator;
 sub add_entry;
 sub entries;
 sub as_xml;
+sub id;
 
 sub tagline { shift->description(@_) }
 sub items   { $_[0]->entries     }
@@ -188,8 +197,14 @@ I<DateTime> objects, which it then returns to the caller.
 
 Creates a new empty I<XML::Feed> object using the format I<$format>.
 
+    $feed = XML::Feed->new('Atom');
+    $feed = XML::Feed->new('RSS');
+    $feed = XML::Feed->new('RSS', version => '0.91');
+
 =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 +228,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
@@ -272,6 +289,14 @@ If present, I<$modified> should be a I<DateTime> object.
 
 The generator of the feed.
 
+=head2 $feed->self_link ([ $uri ])
+
+The Atom Self-link of the feed:
+
+L<http://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html>
+
+A string.
+
 =head2 $feed->entries
 
 A list of the entries/items in the feed. Returns an array containing
@@ -310,7 +335,13 @@ under the same terms as Perl itself.
 
 =head1 AUTHOR & COPYRIGHT
 
-Except where otherwise noted, I<XML::Feed> is Copyright 2004-2005
+Except where otherwise noted, I<XML::Feed> is Copyright 2004-2008
 Six Apart, cpan@sixapart.com. All rights reserved.
 
+=head1 SUBVERSION 
+
+The latest version of I<XML::Feed> can be found at
+
+    http://code.sixapart.com/svn/XML-Feed/trunk/
+
 =cut