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