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