3 package XML::Feed::Entry;
5 use base qw( Class::ErrorHandler );
7 use Scalar::Util qw( blessed );
14 bless { entry => $item }, $class;
17 sub unwrap { $_[0]->{entry} }
23 my $format_class = 'XML::Feed::Format::' . $format;
24 eval "use $format_class";
25 Carp::croak("Unsupported format $format: $@") if $@;
26 my $entry = bless {}, join('::', __PACKAGE__, "Format", $format);
27 $entry->init_empty or return $class->error($entry->errstr);
36 my $new = __PACKAGE__->new($format);
37 for my $field (qw( title link content summary category author id issued modified lat long )) {
38 my @values = $entry->$field();
39 next unless @values && defined $values[0];
40 next if blessed $values[0] && $values[0]->isa('XML::Feed::Content') && ! defined $values[0]->body;
41 $new->$field(@values);
58 sub tags { shift->category(@_) }
65 XML::Feed::Entry - Entry/item in a syndication feed
69 ## $feed is an XML::Feed object.
70 for my $entry ($feed->entries) {
71 print $entry->title, "\n", $entry->summary, "\n\n";
76 I<XML::Feed::Entry> represents an entry/item in an I<XML::Feed> syndication
81 =head2 XML::Feed::Entry->new($format)
83 Creates a new I<XML::Feed::Entry> object in the format I<$format>, which
84 should be either I<RSS> or I<Atom>.
86 =head2 $entry->convert($format)
88 Converts the I<XML::Feed::Entry> object into the I<$format> format, and
89 returns the new object.
91 =head2 $entry->title([ $title ])
93 The title of the entry.
95 =head2 $entry->base([ $base ])
97 The url base of the entry.
99 =head2 $entry->link([ $uri ])
101 The permalink of the entry, in most cases, except in cases where it points
102 instead to an offsite URI referenced in the entry.
104 =head2 $entry->content([ $content ])
106 Bn I<XML::Feed::Content> object representing the full entry body, or as
107 much as is available in the feed.
109 In RSS feeds, this method will look first for
110 I<http://purl.org/rss/1.0/modules/content/#encoded> and
111 I<http://www.w3.org/1999/xhtml#body> elements, then fall back to a
112 I<E<lt>descriptionE<gt>> element.
114 =head2 $entry->summary([ $summary ])
116 An I<XML::Feed::Content> object representing a short summary of the entry.
119 Since RSS feeds do not have the idea of a summary separate from the entry
120 body, this may not always be what you want. If the entry contains both a
121 I<E<lt>descriptionE<gt>> element B<and> another element typically used for
122 the full content of the entry--either I<http://www.w3.org/1999/xhtml/body>
123 or I<http://purl.org/rss/1.0/modules/content/#encoded>--we treat that as
124 the summary. Otherwise, we assume that there isn't a summary, and return
125 an I<XML::Feed::Content> object with an empty string in the I<body>.
127 =head2 $entry->category([ $category ])
129 The category in which the entry was posted.
131 Returns a list of categories if called in array context or the first
132 category if called in scalar context.
134 B<WARNING> It's possible this API might change to have an
135 I<add_category> instead.
137 =head2 $entry->tags([ $tag ])
139 A synonym for I<category>;
141 =head2 $entry->author([ $author ])
143 The name or email address of the person who posted the entry.
145 =head2 $entry->id([ $id ])
147 The unique ID of the entry.
149 =head2 $entry->issued([ $issued ])
151 A I<DateTime> object representing the date and time at which the entry
154 If present, I<$issued> should be a I<DateTime> object.
156 =head2 $entry->modified([ $modified ])
158 A I<DateTime> object representing the last-modified date of the entry.
160 If present, I<$modified> should be a I<DateTime> object.
164 Take an entry in its native format and turn it into an I<XML::Feed::Entry> object.
166 =head2 $entry->unwrap
168 Take an I<XML::Feed::Entry> object and turn it into its native format.
170 =head1 AUTHOR & COPYRIGHT
172 Please see the I<XML::Feed> manpage for author, copyright, and license