X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FXML%2FFeed%2FEntry.pm;h=4f183999983f1774d0123f6f33194caa344a072a;hb=8c30ad3d71619bc69bf47f1b229bdbf865da74f8;hp=3e9133229d79b73f4178040a3db079891efb51ca;hpb=ba87bd32e42464e100f90993c2e63e2a6a90afac;p=catagits%2FXML-Feed.git diff --git a/lib/XML/Feed/Entry.pm b/lib/XML/Feed/Entry.pm index 3e91332..4f18399 100644 --- a/lib/XML/Feed/Entry.pm +++ b/lib/XML/Feed/Entry.pm @@ -1,7 +1,12 @@ -# $Id: Entry.pm,v 1.1.1.1 2004/05/29 17:29:56 btrott Exp $ +# $Id: Entry.pm 1872 2005-08-12 04:28:42Z btrott $ package XML::Feed::Entry; use strict; +use base qw( Class::ErrorHandler ); + +use Scalar::Util qw( blessed ); + +use Carp; sub wrap { my $class = shift; @@ -9,6 +14,35 @@ sub wrap { bless { entry => $item }, $class; } +sub unwrap { $_[0]->{entry} } + +sub new { + my $class = shift; + my($format) = @_; + $format ||= 'Atom'; + my $format_class = 'XML::Feed::' . $format; + eval "use $format_class"; + Carp::croak("Unsupported format $format: $@") if $@; + my $entry = bless {}, join('::', __PACKAGE__, $format); + $entry->init_empty or return $class->error($entry->errstr); + $entry; +} + +sub init_empty { 1 } + +sub convert { + my $entry = shift; + my($format) = @_; + my $new = __PACKAGE__->new($format); + for my $field (qw( title link content summary category author id issued modified lat long )) { + my $val = $entry->$field(); + next unless defined $val; + next if blessed $val && $val->isa('XML::Feed::Content') && ! defined $val->body; + $new->$field($val); + } + $new; +} + sub title; sub link; sub content; @@ -18,6 +52,8 @@ sub author; sub id; sub issued; sub modified; +sub lat; +sub long; 1; __END__ @@ -40,56 +76,85 @@ feed. =head1 USAGE -=head2 $entry->title +=head2 XML::Feed::Entry->new($format) + +Creates a new I object in the format I<$format>, which +should be either I or I. + +=head2 $entry->convert($format) + +Converts the I object into the I<$format> format, and +returns the new object. + +=head2 $entry->title([ $title ]) The title of the entry. -=head2 $entry->link +=head2 $entry->base([ $base ]) + +The url base of the entry. + +=head2 $entry->link([ $uri ]) 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 +=head2 $entry->content([ $content ]) -The full entry body, or as much as is available in the feed. +Bn I object representing the full entry body, or as +much as is available in the feed. In RSS feeds, this method will look first for I and I elements, then fall back to a IdescriptionE> element. -=head2 $entry->summary +=head2 $entry->summary([ $summary ]) -A short summary of the entry. Possibly. +An I object representing a short summary of the entry. +Possibly. Since RSS feeds do not have the idea of a summary separate from the entry -body, this may return the same value as the I<$entry-Econtent> method. -But it won't always, even with RSS feeds. For example, a number of RSS feeds -use an element like I -for the entry body and put an excerpt in the IdescriptionE> element; -in those cases, this method will return the excerpt. +body, this may not always be what you want. If the entry contains both a +IdescriptionE> element B another element typically used for +the full content of the entry--either I +or I--we treat that as +the summary. Otherwise, we assume that there isn't a summary, and return +an I object with an empty string in the I. -=head2 $entry->category +=head2 $entry->category([ $category ]) The category in which the entry was posted. -=head2 $entry->author +=head2 $entry->author([ $author ]) The name or email address of the person who posted the entry. -=head2 $entry->id +=head2 $entry->id([ $id ]) The unique ID of the entry. -=head2 $entry->issued +=head2 $entry->issued([ $issued ]) A I object representing the date and time at which the entry was posted. -=head2 $entry->modified +If present, I<$issued> should be a I object. + +=head2 $entry->modified([ $modified ]) A I object representing the last-modified date of the entry. +If present, I<$modified> should be a I object. + +=head2 $entry->wrap + +Take an entry in its native format and turn it into an I object. + +=head2 $entry->unwrap + +Take an I object and turn it into its native format. + =head1 AUTHOR & COPYRIGHT Please see the I manpage for author, copyright, and license