Switch to different layout
[catagits/XML-Feed.git] / lib / XML / Feed / Entry.pm
CommitLineData
23103173 1# $Id: Entry.pm 1872 2005-08-12 04:28:42Z btrott $
0d5e38d1 2
3package XML::Feed::Entry;
4use strict;
973e1f9e 5use base qw( Class::ErrorHandler );
6
566afdf5 7use Scalar::Util qw( blessed );
8
973e1f9e 9use Carp;
0d5e38d1 10
11sub wrap {
12 my $class = shift;
13 my($item) = @_;
14 bless { entry => $item }, $class;
15}
16
973e1f9e 17sub unwrap { $_[0]->{entry} }
18
19sub new {
20 my $class = shift;
21 my($format) = @_;
22 $format ||= 'Atom';
729cd7a8 23 my $format_class = 'XML::Feed::Format::' . $format;
973e1f9e 24 eval "use $format_class";
25 Carp::croak("Unsupported format $format: $@") if $@;
729cd7a8 26 my $entry = bless {}, join('::', __PACKAGE__, "Format", $format);
973e1f9e 27 $entry->init_empty or return $class->error($entry->errstr);
28 $entry;
29}
30
31sub init_empty { 1 }
32
33sub convert {
34 my $entry = shift;
35 my($format) = @_;
36 my $new = __PACKAGE__->new($format);
9a36f82c 37 for my $field (qw( title link content summary category author id issued modified lat long )) {
23103173 38 my $val = $entry->$field();
39 next unless defined $val;
566afdf5 40 next if blessed $val && $val->isa('XML::Feed::Content') && ! defined $val->body;
23103173 41 $new->$field($val);
973e1f9e 42 }
43 $new;
44}
45
0d5e38d1 46sub title;
47sub link;
48sub content;
49sub summary;
50sub category;
51sub author;
52sub id;
53sub issued;
54sub modified;
9a36f82c 55sub lat;
56sub long;
0d5e38d1 57
581;
59__END__
60
61=head1 NAME
62
63XML::Feed::Entry - Entry/item in a syndication feed
64
65=head1 SYNOPSIS
66
67 ## $feed is an XML::Feed object.
68 for my $entry ($feed->entries) {
69 print $entry->title, "\n", $entry->summary, "\n\n";
70 }
71
72=head1 DESCRIPTION
73
74I<XML::Feed::Entry> represents an entry/item in an I<XML::Feed> syndication
75feed.
76
77=head1 USAGE
78
973e1f9e 79=head2 XML::Feed::Entry->new($format)
80
81Creates a new I<XML::Feed::Entry> object in the format I<$format>, which
82should be either I<RSS> or I<Atom>.
83
84=head2 $entry->convert($format)
85
86Converts the I<XML::Feed::Entry> object into the I<$format> format, and
87returns the new object.
88
89=head2 $entry->title([ $title ])
0d5e38d1 90
91The title of the entry.
92
5383a560 93=head2 $entry->base([ $base ])
94
95The url base of the entry.
96
973e1f9e 97=head2 $entry->link([ $uri ])
0d5e38d1 98
99The permalink of the entry, in most cases, except in cases where it points
fe71566d 100instead to an offsite URI referenced in the entry.
0d5e38d1 101
973e1f9e 102=head2 $entry->content([ $content ])
0d5e38d1 103
a749d9b9 104Bn I<XML::Feed::Content> object representing the full entry body, or as
105much as is available in the feed.
0d5e38d1 106
107In RSS feeds, this method will look first for
108I<http://purl.org/rss/1.0/modules/content/#encoded> and
109I<http://www.w3.org/1999/xhtml#body> elements, then fall back to a
110I<E<lt>descriptionE<gt>> element.
111
973e1f9e 112=head2 $entry->summary([ $summary ])
0d5e38d1 113
a749d9b9 114An I<XML::Feed::Content> object representing a short summary of the entry.
115Possibly.
0d5e38d1 116
117Since RSS feeds do not have the idea of a summary separate from the entry
a749d9b9 118body, this may not always be what you want. If the entry contains both a
119I<E<lt>descriptionE<gt>> element B<and> another element typically used for
120the full content of the entry--either I<http://www.w3.org/1999/xhtml/body>
121or I<http://purl.org/rss/1.0/modules/content/#encoded>--we treat that as
122the summary. Otherwise, we assume that there isn't a summary, and return
123an I<XML::Feed::Content> object with an empty string in the I<body>.
0d5e38d1 124
973e1f9e 125=head2 $entry->category([ $category ])
0d5e38d1 126
127The category in which the entry was posted.
128
973e1f9e 129=head2 $entry->author([ $author ])
0d5e38d1 130
131The name or email address of the person who posted the entry.
132
973e1f9e 133=head2 $entry->id([ $id ])
0d5e38d1 134
135The unique ID of the entry.
136
973e1f9e 137=head2 $entry->issued([ $issued ])
0d5e38d1 138
139A I<DateTime> object representing the date and time at which the entry
140was posted.
141
973e1f9e 142If present, I<$issued> should be a I<DateTime> object.
143
144=head2 $entry->modified([ $modified ])
0d5e38d1 145
146A I<DateTime> object representing the last-modified date of the entry.
147
973e1f9e 148If present, I<$modified> should be a I<DateTime> object.
149
8c30ad3d 150=head2 $entry->wrap
151
152Take an entry in its native format and turn it into an I<XML::Feed::Entry> object.
153
154=head2 $entry->unwrap
155
156Take an I<XML::Feed::Entry> object and turn it into its native format.
157
0d5e38d1 158=head1 AUTHOR & COPYRIGHT
159
160Please see the I<XML::Feed> manpage for author, copyright, and license
161information.
162
163=cut