add links to the POD
[catagits/XML-Feed.git] / lib / XML / Feed / Entry.pm
CommitLineData
3353d70c 1# $Id$
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);
ff32fd51 37 for my $field (qw( title link content summary 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 }
ff32fd51 43 for my $field (qw( category )) {
44 my @val = $entry->$field();
45 next unless @val;
46 $new->$field(@val);
47 }
973e1f9e 48 $new;
49}
50
0d5e38d1 51sub title;
52sub link;
53sub content;
54sub summary;
55sub category;
56sub author;
57sub id;
58sub issued;
59sub modified;
9a36f82c 60sub lat;
61sub long;
3bdbab6f 62sub format;
a0cca2a4 63sub tags { shift->category(@_) }
12a4079f 64sub enclosure;
0d5e38d1 65
661;
67__END__
68
69=head1 NAME
70
71XML::Feed::Entry - Entry/item in a syndication feed
72
73=head1 SYNOPSIS
74
75 ## $feed is an XML::Feed object.
76 for my $entry ($feed->entries) {
77 print $entry->title, "\n", $entry->summary, "\n\n";
78 }
79
80=head1 DESCRIPTION
81
200ce863 82I<XML::Feed::Entry> represents an entry/item in an L<XML::Feed> syndication
0d5e38d1 83feed.
84
85=head1 USAGE
86
973e1f9e 87=head2 XML::Feed::Entry->new($format)
88
89Creates a new I<XML::Feed::Entry> object in the format I<$format>, which
90should be either I<RSS> or I<Atom>.
91
92=head2 $entry->convert($format)
93
94Converts the I<XML::Feed::Entry> object into the I<$format> format, and
95returns the new object.
96
97=head2 $entry->title([ $title ])
0d5e38d1 98
99The title of the entry.
100
5383a560 101=head2 $entry->base([ $base ])
102
103The url base of the entry.
104
973e1f9e 105=head2 $entry->link([ $uri ])
0d5e38d1 106
107The permalink of the entry, in most cases, except in cases where it points
fe71566d 108instead to an offsite URI referenced in the entry.
0d5e38d1 109
973e1f9e 110=head2 $entry->content([ $content ])
0d5e38d1 111
200ce863 112An L<XML::Feed::Content> object representing the full entry body, or as
a749d9b9 113much as is available in the feed.
0d5e38d1 114
115In RSS feeds, this method will look first for
200ce863 116L<http://purl.org/rss/1.0/modules/content/#encoded> and
117L<http://www.w3.org/1999/xhtml#body> elements, then fall back to a
0d5e38d1 118I<E<lt>descriptionE<gt>> element.
119
973e1f9e 120=head2 $entry->summary([ $summary ])
0d5e38d1 121
200ce863 122An L<XML::Feed::Content> object representing a short summary of the entry.
a749d9b9 123Possibly.
0d5e38d1 124
125Since RSS feeds do not have the idea of a summary separate from the entry
a749d9b9 126body, this may not always be what you want. If the entry contains both a
127I<E<lt>descriptionE<gt>> element B<and> another element typically used for
128the full content of the entry--either I<http://www.w3.org/1999/xhtml/body>
200ce863 129or L<http://purl.org/rss/1.0/modules/content/#encoded>--we treat that as
a749d9b9 130the summary. Otherwise, we assume that there isn't a summary, and return
200ce863 131an L<XML::Feed::Content> object with an empty string in the I<body>.
0d5e38d1 132
973e1f9e 133=head2 $entry->category([ $category ])
0d5e38d1 134
135The category in which the entry was posted.
136
a0cca2a4 137Returns a list of categories if called in array context or the first
138category if called in scalar context.
139
a759e13e 140B<WARNING> It's possible this API might change to have an
141I<add_category> instead.
142
a0cca2a4 143=head2 $entry->tags([ $tag ])
144
200ce863 145A synonym (alias) for I<category>;
a0cca2a4 146
973e1f9e 147=head2 $entry->author([ $author ])
0d5e38d1 148
149The name or email address of the person who posted the entry.
150
973e1f9e 151=head2 $entry->id([ $id ])
0d5e38d1 152
153The unique ID of the entry.
154
973e1f9e 155=head2 $entry->issued([ $issued ])
0d5e38d1 156
157A I<DateTime> object representing the date and time at which the entry
158was posted.
159
973e1f9e 160If present, I<$issued> should be a I<DateTime> object.
161
162=head2 $entry->modified([ $modified ])
0d5e38d1 163
164A I<DateTime> object representing the last-modified date of the entry.
165
973e1f9e 166If present, I<$modified> should be a I<DateTime> object.
167
8c30ad3d 168=head2 $entry->wrap
169
170Take an entry in its native format and turn it into an I<XML::Feed::Entry> object.
171
172=head2 $entry->unwrap
173
174Take an I<XML::Feed::Entry> object and turn it into its native format.
175
0d5e38d1 176=head1 AUTHOR & COPYRIGHT
177
178Please see the I<XML::Feed> manpage for author, copyright, and license
179information.
180
181=cut