| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
XML::FeedPP -- Parse/write/merge/edit RSS/RDF/Atom syndication feeds |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Get an RSS file and parse it: |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use XML::FeedPP (); |
|
10
|
|
|
|
|
|
|
my $source = 'http://use.perl.org/index.rss'; |
|
11
|
|
|
|
|
|
|
my $feed = XML::FeedPP->new( $source ); |
|
12
|
|
|
|
|
|
|
print "Title: ", $feed->title(), "\n"; |
|
13
|
|
|
|
|
|
|
print "Date: ", $feed->pubDate(), "\n"; |
|
14
|
|
|
|
|
|
|
foreach my $item ( $feed->get_item() ) { |
|
15
|
|
|
|
|
|
|
print "URL: ", $item->link(), "\n"; |
|
16
|
|
|
|
|
|
|
print "Title: ", $item->title(), "\n"; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Generate an RDF file and save it: |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use XML::FeedPP (); |
|
22
|
|
|
|
|
|
|
my $feed = XML::FeedPP::RDF->new(); |
|
23
|
|
|
|
|
|
|
$feed->title( "use Perl" ); |
|
24
|
|
|
|
|
|
|
$feed->link( "http://use.perl.org/" ); |
|
25
|
|
|
|
|
|
|
$feed->pubDate( "Thu, 23 Feb 2006 14:43:43 +0900" ); |
|
26
|
|
|
|
|
|
|
my $item = $feed->add_item( "http://search.cpan.org/~kawasaki/XML-TreePP-0.02" ); |
|
27
|
|
|
|
|
|
|
$item->title( "Pure Perl implementation for parsing/writing xml file" ); |
|
28
|
|
|
|
|
|
|
$item->pubDate( "2006-02-23T14:43:43+09:00" ); |
|
29
|
|
|
|
|
|
|
$feed->to_file( "index.rdf" ); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Convert some RSS/RDF files to Atom format: |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use XML::FeedPP (); |
|
34
|
|
|
|
|
|
|
my $feed = XML::FeedPP::Atom::Atom10->new(); # create empty atom file |
|
35
|
|
|
|
|
|
|
$feed->merge( "rss.xml" ); # load local RSS file |
|
36
|
|
|
|
|
|
|
$feed->merge( "http://www.kawa.net/index.rdf" ); # load remote RDF file |
|
37
|
|
|
|
|
|
|
my $now = time(); |
|
38
|
|
|
|
|
|
|
$feed->pubDate( $now ); # touch date |
|
39
|
|
|
|
|
|
|
my $atom = $feed->to_string(); # get Atom source code |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
C is an all-purpose syndication utility that parses and |
|
44
|
|
|
|
|
|
|
publishes RSS 2.0, RSS 1.0 (RDF), Atom 0.3 and 1.0 feeds. |
|
45
|
|
|
|
|
|
|
It allows you to add new content, merge feeds, and convert among |
|
46
|
|
|
|
|
|
|
these various formats. |
|
47
|
|
|
|
|
|
|
It is a pure Perl implementation and does not require any other |
|
48
|
|
|
|
|
|
|
module except for XML::TreePP. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 METHODS FOR FEED |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 $feed = XML::FeedPP->new( "index.rss" ); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This constructor method creates an C feed instance. The only |
|
55
|
|
|
|
|
|
|
argument is the local filename. The format of $source must be one of |
|
56
|
|
|
|
|
|
|
the supported feed formats -- RSS, RDF or Atom -- or execution is |
|
57
|
|
|
|
|
|
|
halted. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 $feed = XML::FeedPP->new( "http://use.perl.org/index.rss" ); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
The URL on the remote web server is also available as the first argument. |
|
62
|
|
|
|
|
|
|
L is required to download it. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 $feed = XML::FeedPP->new( '...' ); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
The XML source code is also available as the first argument. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 $feed = XML::FeedPP->new( $source, -type => $type ); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The C<-type> argument allows you to specify type of $source |
|
71
|
|
|
|
|
|
|
from choice of C<'file'>, C<'url'> or C<'string'>. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 $feed = XML::FeedPP->new( $source, utf8_flag => 1 ); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This makes utf8 flag on for all feed elements. |
|
76
|
|
|
|
|
|
|
Perl 5.8.1 or later is required to use this. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Note that any other options for C constructor are also |
|
79
|
|
|
|
|
|
|
allowed like this. See more detail on L. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 $feed = XML::FeedPP::RSS->new( $source ); |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This constructor method creates an instance for an RSS 2.0 feed. |
|
84
|
|
|
|
|
|
|
The first argument is optional, but must be valid an RSS source if specified. |
|
85
|
|
|
|
|
|
|
This method returns an empty instance when $source is undefined. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 $feed = XML::FeedPP::RDF->new( $source ); |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This constructor method creates an instance for RSS 1.0 (RDF) feed. |
|
90
|
|
|
|
|
|
|
The first argument is optional, but must be an RDF source if specified. |
|
91
|
|
|
|
|
|
|
This method returns an empty instance when $source is undefined. |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 $feed = XML::FeedPP::Atom->new( $source ); |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This constructor method creates an instance for an Atom 0.3/1.0 feed. |
|
96
|
|
|
|
|
|
|
The first argument is optional, but must be an Atom source if specified. |
|
97
|
|
|
|
|
|
|
This method returns an empty instance when $source is undefined. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Atom 1.0 feed is also supported since C version 0.30. |
|
100
|
|
|
|
|
|
|
Atom 0.3 is still default, however, future version of this module |
|
101
|
|
|
|
|
|
|
would create Atom 1.0 as default. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 $feed = XML::FeedPP::Atom::Atom03->new(); |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This creates an empty Atom 0.3 instance obviously. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 $feed = XML::FeedPP::Atom::Atom10->new(); |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This creates an empty Atom 1.0 instance intended. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 $feed = XML::FeedPP::RSS->new( link => $link, title => $tile, ... ); |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This creates a RSS instance which has C, C elements etc. |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 $feed->load( $source ); |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This method loads an RSS/RDF/Atom file, |
|
118
|
|
|
|
|
|
|
much like C method does. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 $feed->merge( $source ); |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This method merges an RSS/RDF/Atom file into the existing $feed |
|
123
|
|
|
|
|
|
|
instance. Top-level metadata from the imported feed is incorporated |
|
124
|
|
|
|
|
|
|
only if missing from the present feed. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 $string = $feed->to_string( $encoding ); |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This method generates XML source as string and returns it. The output |
|
129
|
|
|
|
|
|
|
$encoding is optional, and the default encoding is 'UTF-8'. On Perl |
|
130
|
|
|
|
|
|
|
5.8 and later, any encodings supported by the Encode module are |
|
131
|
|
|
|
|
|
|
available. On Perl 5.005 and 5.6.1, only four encodings supported by |
|
132
|
|
|
|
|
|
|
the Jcode module are available: 'UTF-8', 'Shift_JIS', 'EUC-JP' and |
|
133
|
|
|
|
|
|
|
'ISO-2022-JP'. 'UTF-8' is recommended for overall compatibility. |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 $string = $feed->to_string( indent => 4 ); |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This makes the output more human readable by indenting appropriately. |
|
138
|
|
|
|
|
|
|
This does not strictly follow the XML specification but does looks nice. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Note that any other options for C constructor are also |
|
141
|
|
|
|
|
|
|
allowed like this. See more detail on L. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 $feed->to_file( $filename, $encoding ); |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This method generate an XML file. The output $encoding is optional, |
|
146
|
|
|
|
|
|
|
and the default is 'UTF-8'. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 $item = $feed->add_item( $link ); |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This method creates a new item/entry and returns its instance. |
|
151
|
|
|
|
|
|
|
A mandatory $link argument is the URL of the new item/entry. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 $item = $feed->add_item( $srcitem ); |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This method duplicates an item/entry and adds it to $feed. |
|
156
|
|
|
|
|
|
|
$srcitem is a C class's instance |
|
157
|
|
|
|
|
|
|
which is returned by C method, as described above. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 $item = $feed->add_item( link => $link, title => $tile, ... ); |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This method creates an new item/entry |
|
162
|
|
|
|
|
|
|
which has C, C elements etc. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 $item = $feed->get_item( $index ); |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This method returns item(s) in a $feed. |
|
167
|
|
|
|
|
|
|
A valid zero-based array $index returns the corresponding item in the feed. |
|
168
|
|
|
|
|
|
|
An invalid $index yields undef. |
|
169
|
|
|
|
|
|
|
If $index is undefined in array context, it returns an array of all items. |
|
170
|
|
|
|
|
|
|
If $index is undefined in scalar context, it returns the number of items. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 @items = $feed->match_item( link => qr/.../, title => qr/.../, ... ); |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This method finds item(s) which match all regular expressions given. |
|
175
|
|
|
|
|
|
|
This method returns an array of all matched items in array context. |
|
176
|
|
|
|
|
|
|
This method returns the first matched item in scalar context. |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 $feed->remove_item( $index or $link ); |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This method removes an item/entry specified by zero-based array index or |
|
181
|
|
|
|
|
|
|
link URL. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 $feed->clear_item(); |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This method removes all items/entries from the $feed. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 $feed->sort_item(); |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This method sorts the order of items in $feed by C. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 $feed->uniq_item(); |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Reduces the list of items, not to include duplicates. RDF and Atoms |
|
194
|
|
|
|
|
|
|
have a guid attribute to defined uniqueness, for RSS we use the link. |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 $feed->normalize(); |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This method calls both the C and C methods. |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 $feed->limit_item( $num ); |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Removes items in excess of the specified numeric limit. Items at the |
|
203
|
|
|
|
|
|
|
end of the list are removed. When preceded by C or |
|
204
|
|
|
|
|
|
|
C, this deletes more recent items. |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 $feed->xmlns( "xmlns:media" => "http://search.yahoo.com/mrss" ); |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Adds an XML namespace at the document root of the feed. |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head2 $url = $feed->xmlns( "xmlns:media" ); |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Returns the URL of the specified XML namespace. |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 @list = $feed->xmlns(); |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Returns the list of all XML namespaces used in $feed. |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 METHODS FOR CHANNEL |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 $feed->title( $text ); |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
This method sets/gets the feed's C element, |
|
223
|
|
|
|
|
|
|
returning its current value when $title is undefined. |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head2 $feed->description( $html ); |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This method sets/gets the feed's C element in plain text or HTML, |
|
228
|
|
|
|
|
|
|
returning its current value when $html is undefined. |
|
229
|
|
|
|
|
|
|
It is mapped to C element for Atom 0.3/1.0. |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 $feed->pubDate( $date ); |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
This method sets/gets the feed's C element for RSS, |
|
234
|
|
|
|
|
|
|
returning its current value when $date is undefined. |
|
235
|
|
|
|
|
|
|
It is mapped to C element for RDF, |
|
236
|
|
|
|
|
|
|
C for Atom 0.3, and C for Atom 1.0. |
|
237
|
|
|
|
|
|
|
See also L section below. |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head2 $feed->copyright( $text ); |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
This method sets/gets the feed's C element for RSS, |
|
242
|
|
|
|
|
|
|
returning its current value when $text is undefined. |
|
243
|
|
|
|
|
|
|
It is mapped to C element for RDF, |
|
244
|
|
|
|
|
|
|
C for Atom 0.3, and C for Atom 1.0. |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head2 $feed->link( $url ); |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
This method sets/gets the URL of the web site as the feed's C element, |
|
249
|
|
|
|
|
|
|
returning its current value when the $url is undefined. |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head2 $feed->language( $lang ); |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
This method sets/gets the feed's C element for RSS, |
|
254
|
|
|
|
|
|
|
returning its current value when the $lang is undefined. |
|
255
|
|
|
|
|
|
|
It is mapped to C element for RDF, |
|
256
|
|
|
|
|
|
|
C for Atom 0.3/1.0. |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head2 $feed->image( $url, $title, $link, $description, $width, $height ) |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
This method sets/gets the feed's C element and its child nodes, |
|
261
|
|
|
|
|
|
|
returning a list of current values when any arguments are undefined. |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head1 METHODS FOR ITEM |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head2 $item->title( $text ); |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
This method sets/gets the item's C element, |
|
268
|
|
|
|
|
|
|
returning its current value when the $text is undefined. |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head2 $item->description( $html ); |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
This method sets/gets the item's C element in HTML or plain text, |
|
273
|
|
|
|
|
|
|
returning its current value when $text is undefined. |
|
274
|
|
|
|
|
|
|
It is mapped to C element for Atom 0.3/1.0. |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=head2 $item->pubDate( $date ); |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
This method sets/gets the item's C element, |
|
279
|
|
|
|
|
|
|
returning its current value when $date is undefined. |
|
280
|
|
|
|
|
|
|
It is mapped to C element for RDF, |
|
281
|
|
|
|
|
|
|
C for Atom 0.3, and C for Atom 1.0. |
|
282
|
|
|
|
|
|
|
See also L section below. |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head2 $item->category( $text ); |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
This method sets/gets the item's C element. |
|
287
|
|
|
|
|
|
|
returning its current value when $text is undefined. |
|
288
|
|
|
|
|
|
|
It is mapped to C element for RDF, and ignored for Atom 0.3. |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=head2 $item->author( $name ); |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
This method sets/gets the item's C element, |
|
293
|
|
|
|
|
|
|
returning its current value when $name is undefined. |
|
294
|
|
|
|
|
|
|
It is mapped to C element for RDF, |
|
295
|
|
|
|
|
|
|
C for Atom 0.3/1.0. |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=head2 $item->guid( $guid, isPermaLink => $bool ); |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
This method sets/gets the item's C element, |
|
300
|
|
|
|
|
|
|
returning its current value when $guid is undefined. |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
It is mapped to C element for Atom, and ignored for RDF. In case of |
|
303
|
|
|
|
|
|
|
RSS, it will return a HASH. The C is supported by RSS only, |
|
304
|
|
|
|
|
|
|
and optional. |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=head2 $item->set( $key => $value, ... ); |
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
This method sets customized node values or attributes. |
|
309
|
|
|
|
|
|
|
See also L section below. |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=head2 $value = $item->get( $key ); |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
This method returns the node value or attribute. |
|
314
|
|
|
|
|
|
|
See also L section below. |
|
315
|
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=head2 $link = $item->link(); |
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
This method returns the item's C element. |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=head1 ACCESSOR AND MUTATORS |
|
321
|
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
This module understands only subset of C, C modules |
|
323
|
|
|
|
|
|
|
and RSS/RDF/Atom's default namespaces by itself. |
|
324
|
|
|
|
|
|
|
There are NO native methods for any other external modules, such as C. |
|
325
|
|
|
|
|
|
|
But C and C methods are available to get/set |
|
326
|
|
|
|
|
|
|
the value of any elements or attributes for these modules. |
|
327
|
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
=head2 $item->set( "module:name" => $value ); |
|
329
|
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
This sets the value of the child node: |
|
331
|
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
- $value...
|
|
333
|
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
=head2 $item->set( "module:name@attr" => $value ); |
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
This sets the value of the child node's attribute: |
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
- ...
|
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=head2 $item->set( "@attr" => $value ); |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
This sets the value of the item's attribute: |
|
343
|
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
- ...
|
|
345
|
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
=head2 $item->set( "hoge/pomu@hare" => $value ); |
|
347
|
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
This code sets the value of the child node's child node's attribute: |
|
349
|
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
- ...
|
|
351
|
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
=head1 DATE AND TIME FORMATS |
|
353
|
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
C allows you to describe date/time using any of the three |
|
355
|
|
|
|
|
|
|
following formats: |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
=head2 $date = "Thu, 23 Feb 2006 14:43:43 +0900"; |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
This is the HTTP protocol's preferred format and RSS 2.0's native |
|
360
|
|
|
|
|
|
|
format, as defined by RFC 1123. |
|
361
|
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
=head2 $date = "2006-02-23T14:43:43+09:00"; |
|
363
|
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
W3CDTF is the native format of RDF, as defined by ISO 8601. |
|
365
|
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
=head2 $date = 1140705823; |
|
367
|
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
The last format is the number of seconds since the epoch, |
|
369
|
|
|
|
|
|
|
C<1970-01-01T00:00:00Z>. |
|
370
|
|
|
|
|
|
|
You know, this is the native format of Perl's C |
|
371
|
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
=head1 USING MEDIA RSS |
|
373
|
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
To publish Media RSS, add the C namespace then use C |
|
375
|
|
|
|
|
|
|
setter method to manipulate C element, etc. |
|
376
|
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
my $feed = XML::FeedPP::RSS->new(); |
|
378
|
|
|
|
|
|
|
$feed->xmlns('xmlns:media' => 'http://search.yahoo.com/mrss/'); |
|
379
|
|
|
|
|
|
|
my $item = $feed->add_item('http://www.example.com/index.html'); |
|
380
|
|
|
|
|
|
|
$item->set('media:content@url' => 'http://www.example.com/image.jpg'); |
|
381
|
|
|
|
|
|
|
$item->set('media:content@type' => 'image/jpeg'); |
|
382
|
|
|
|
|
|
|
$item->set('media:content@width' => 640); |
|
383
|
|
|
|
|
|
|
$item->set('media:content@height' => 480); |
|
384
|
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
=head1 MODULE DEPENDENCIES |
|
386
|
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
C requires only L |
|
388
|
|
|
|
|
|
|
which likewise is a pure Perl implementation. |
|
389
|
|
|
|
|
|
|
The standard L is required |
|
390
|
|
|
|
|
|
|
to download feeds from remote web servers. |
|
391
|
|
|
|
|
|
|
C is required to convert Japanese encodings on Perl 5.005 |
|
392
|
|
|
|
|
|
|
and 5.6.1, but is NOT required on Perl 5.8.x and later. |
|
393
|
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
=head1 AUTHOR |
|
395
|
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
Yusuke Kawasaki, http://www.kawa.net/ |
|
397
|
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
399
|
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
The following copyright notice applies to all the files provided in |
|
401
|
|
|
|
|
|
|
this distribution, including binary files, unless explicitly noted |
|
402
|
|
|
|
|
|
|
otherwise. |
|
403
|
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
Copyright 2006-2011 Yusuke Kawasaki |
|
405
|
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
=head1 LICENSE |
|
407
|
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
409
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
410
|
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
=cut |
|
412
|
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
414
|
|
|
|
|
|
|
package XML::FeedPP; |
|
415
|
44
|
|
|
44
|
|
2281001
|
use strict; |
|
|
44
|
|
|
|
|
365
|
|
|
|
44
|
|
|
|
|
1057
|
|
|
416
|
44
|
|
|
44
|
|
178
|
use Carp; |
|
|
44
|
|
|
|
|
74
|
|
|
|
44
|
|
|
|
|
2245
|
|
|
417
|
44
|
|
|
44
|
|
18072
|
use Time::Local; |
|
|
44
|
|
|
|
|
81048
|
|
|
|
44
|
|
|
|
|
2061
|
|
|
418
|
44
|
|
|
44
|
|
21087
|
use XML::TreePP; |
|
|
44
|
|
|
|
|
277620
|
|
|
|
44
|
|
|
|
|
1927
|
|
|
419
|
|
|
|
|
|
|
|
|
420
|
44
|
|
|
|
|
113790
|
use vars qw( |
|
421
|
|
|
|
|
|
|
$VERSION $RSS20_VERSION $ATOM03_VERSION |
|
422
|
|
|
|
|
|
|
$XMLNS_RDF $XMLNS_RSS $XMLNS_DC $XMLNS_ATOM03 |
|
423
|
|
|
|
|
|
|
$XMLNS_NOCOPY $TREEPP_OPTIONS $MIME_TYPES |
|
424
|
|
|
|
|
|
|
$FEED_METHODS $ITEM_METHODS |
|
425
|
|
|
|
|
|
|
$XMLNS_ATOM10 |
|
426
|
44
|
|
|
44
|
|
273
|
); |
|
|
44
|
|
|
|
|
76
|
|
|
427
|
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
$VERSION = "0.95"; |
|
429
|
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
$RSS20_VERSION = '2.0'; |
|
431
|
|
|
|
|
|
|
$ATOM03_VERSION = '0.3'; |
|
432
|
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
$XMLNS_RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; |
|
434
|
|
|
|
|
|
|
$XMLNS_RSS = 'http://purl.org/rss/1.0/'; |
|
435
|
|
|
|
|
|
|
$XMLNS_DC = 'http://purl.org/dc/elements/1.1/'; |
|
436
|
|
|
|
|
|
|
$XMLNS_ATOM03 = 'http://purl.org/atom/ns#'; |
|
437
|
|
|
|
|
|
|
$XMLNS_ATOM10 = 'http://www.w3.org/2005/Atom'; |
|
438
|
|
|
|
|
|
|
$XMLNS_NOCOPY = [qw( xmlns xmlns:rdf xmlns:dc xmlns:atom )]; |
|
439
|
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
$TREEPP_OPTIONS = { |
|
441
|
|
|
|
|
|
|
force_array => [qw( item rdf:li entry )], |
|
442
|
|
|
|
|
|
|
first_out => [qw( -xmlns:rdf -xmlns -rel -type url title link )], |
|
443
|
|
|
|
|
|
|
last_out => [qw( description image item items entry -width -height )], |
|
444
|
|
|
|
|
|
|
user_agent => "XML-FeedPP/$VERSION ", |
|
445
|
|
|
|
|
|
|
}; |
|
446
|
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
$MIME_TYPES = { reverse qw( |
|
448
|
|
|
|
|
|
|
image/bmp bmp |
|
449
|
|
|
|
|
|
|
image/gif gif |
|
450
|
|
|
|
|
|
|
image/jpeg jpeg |
|
451
|
|
|
|
|
|
|
image/jpeg jpg |
|
452
|
|
|
|
|
|
|
image/png png |
|
453
|
|
|
|
|
|
|
image/svg+xml svg |
|
454
|
|
|
|
|
|
|
image/x-icon ico |
|
455
|
|
|
|
|
|
|
image/x-xbitmap xbm |
|
456
|
|
|
|
|
|
|
image/x-xpixmap xpm |
|
457
|
|
|
|
|
|
|
)}; |
|
458
|
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
$FEED_METHODS = [qw( |
|
460
|
|
|
|
|
|
|
title |
|
461
|
|
|
|
|
|
|
description |
|
462
|
|
|
|
|
|
|
language |
|
463
|
|
|
|
|
|
|
copyright |
|
464
|
|
|
|
|
|
|
link |
|
465
|
|
|
|
|
|
|
pubDate |
|
466
|
|
|
|
|
|
|
image |
|
467
|
|
|
|
|
|
|
set |
|
468
|
|
|
|
|
|
|
)]; |
|
469
|
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
$ITEM_METHODS = [qw( |
|
471
|
|
|
|
|
|
|
title |
|
472
|
|
|
|
|
|
|
description |
|
473
|
|
|
|
|
|
|
category |
|
474
|
|
|
|
|
|
|
author |
|
475
|
|
|
|
|
|
|
link |
|
476
|
|
|
|
|
|
|
guid |
|
477
|
|
|
|
|
|
|
pubDate |
|
478
|
|
|
|
|
|
|
image |
|
479
|
|
|
|
|
|
|
set |
|
480
|
|
|
|
|
|
|
)]; |
|
481
|
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
sub new { |
|
483
|
179
|
|
|
179
|
1
|
232155
|
my $package = shift; |
|
484
|
179
|
|
|
|
|
457
|
my( $init, $source, @rest ) = &XML::FeedPP::Util::param_even_odd(@_); |
|
485
|
179
|
|
|
|
|
351
|
my $do_autodetect = $package eq __PACKAGE__; |
|
486
|
|
|
|
|
|
|
|
|
487
|
179
|
50
|
66
|
|
|
595
|
Carp::croak "No feed source" |
|
488
|
|
|
|
|
|
|
if $do_autodetect && !$source; |
|
489
|
|
|
|
|
|
|
|
|
490
|
179
|
|
|
|
|
330
|
my $self = bless {}, $package; |
|
491
|
179
|
100
|
|
|
|
549
|
$self->load($source, @rest) if $source; |
|
492
|
|
|
|
|
|
|
|
|
493
|
175
|
100
|
|
|
|
431
|
if($do_autodetect) { |
|
494
|
71
|
|
|
|
|
177
|
my $class = $self->detect_format; |
|
495
|
71
|
100
|
|
|
|
157
|
unless ( $class ) { |
|
496
|
1
|
50
|
|
|
|
6
|
my $root = ref $self ? join( " ", sort keys %$self ) : $self; |
|
497
|
1
|
50
|
|
|
|
3
|
my $class = ref $self ? ref $self : $self; |
|
498
|
1
|
|
|
|
|
97
|
Carp::croak "Invalid $class feed format: $root"; |
|
499
|
|
|
|
|
|
|
} |
|
500
|
70
|
|
|
|
|
139
|
bless $self, $class; |
|
501
|
|
|
|
|
|
|
} |
|
502
|
|
|
|
|
|
|
|
|
503
|
174
|
100
|
|
|
|
624
|
$self->validate_feed() if $source; |
|
504
|
174
|
|
|
|
|
555
|
$self->init_feed(); |
|
505
|
174
|
100
|
|
|
|
738
|
$self->elements(@$init) if ref $init; |
|
506
|
174
|
|
|
|
|
631
|
$self; |
|
507
|
|
|
|
|
|
|
} |
|
508
|
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
sub validate_feed { |
|
510
|
75
|
|
|
75
|
0
|
117
|
my $self = shift; |
|
511
|
75
|
50
|
|
|
|
202
|
return if $self->test_feed(@_); |
|
512
|
0
|
0
|
|
|
|
0
|
my $root = ref $self ? join( " ", sort keys %$self ) : $self; |
|
513
|
0
|
0
|
|
|
|
0
|
my $class = ref $self ? ref $self : $self; |
|
514
|
0
|
|
|
|
|
0
|
Carp::croak "Invalid $class feed format: $root"; |
|
515
|
|
|
|
|
|
|
} |
|
516
|
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
sub detect_format { |
|
518
|
71
|
|
|
71
|
0
|
112
|
my $self = shift; |
|
519
|
71
|
|
|
|
|
147
|
my $list = $self->available_format; |
|
520
|
71
|
|
|
|
|
139
|
foreach my $class ( @$list ) { |
|
521
|
154
|
|
|
|
|
511
|
my $hit = $class->test_feed($self); |
|
522
|
154
|
100
|
|
|
|
370
|
return $class if $hit; |
|
523
|
|
|
|
|
|
|
} |
|
524
|
1
|
|
|
|
|
2
|
undef; |
|
525
|
|
|
|
|
|
|
} |
|
526
|
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
sub available_format { |
|
528
|
71
|
|
|
71
|
0
|
171
|
[ 'XML::FeedPP::RSS', |
|
529
|
|
|
|
|
|
|
'XML::FeedPP::RDF', |
|
530
|
|
|
|
|
|
|
'XML::FeedPP::Atom::Atom10', |
|
531
|
|
|
|
|
|
|
'XML::FeedPP::Atom::Atom03', |
|
532
|
|
|
|
|
|
|
'XML::FeedPP::Atom' ]; |
|
533
|
|
|
|
|
|
|
} |
|
534
|
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
sub load { |
|
536
|
80
|
|
|
80
|
1
|
123
|
my $self = shift; |
|
537
|
80
|
|
|
|
|
119
|
my $source = shift; |
|
538
|
80
|
|
|
|
|
129
|
my $args = { @_ }; |
|
539
|
80
|
|
|
|
|
138
|
my $method = $args->{'-type'}; |
|
540
|
80
|
50
|
|
|
|
218
|
Carp::croak "No feed source" unless defined $source; |
|
541
|
|
|
|
|
|
|
|
|
542
|
80
|
100
|
|
|
|
159
|
if ( ! $method ) { |
|
543
|
77
|
50
|
33
|
|
|
648
|
if ( $source =~ m#^https?://#s ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
544
|
0
|
|
|
|
|
0
|
$method = 'url'; |
|
545
|
|
|
|
|
|
|
} |
|
546
|
|
|
|
|
|
|
elsif ( $source =~ m#(?:\s*\xEF\xBB\xBF)?\s* |
|
547
|
|
|
|
|
|
|
(<(\?xml|!DOCTYPE|rdf:RDF|rss|feed)\W)#xis ) { |
|
548
|
75
|
|
|
|
|
134
|
$method = 'string'; |
|
549
|
|
|
|
|
|
|
} |
|
550
|
|
|
|
|
|
|
elsif ( $source !~ /[\r\n]/ && -f $source ) { |
|
551
|
0
|
|
|
|
|
0
|
$method = 'file'; |
|
552
|
|
|
|
|
|
|
} |
|
553
|
|
|
|
|
|
|
else { |
|
554
|
2
|
|
|
|
|
240
|
Carp::croak "Invalid feed source: $source"; |
|
555
|
|
|
|
|
|
|
} |
|
556
|
|
|
|
|
|
|
} |
|
557
|
|
|
|
|
|
|
|
|
558
|
78
|
|
|
|
|
258
|
my $opts = { map { $_ => $args->{$_} } grep { ! /^-/ } keys %$args }; |
|
|
6
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
36
|
|
|
559
|
78
|
|
|
|
|
471
|
my $tpp = XML::TreePP->new(%$TREEPP_OPTIONS, %$opts); |
|
560
|
|
|
|
|
|
|
|
|
561
|
78
|
|
|
|
|
689
|
my $tree; |
|
562
|
78
|
50
|
|
|
|
219
|
if ( $method eq 'url' ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
563
|
0
|
|
|
|
|
0
|
$tree = $tpp->parsehttp( GET => $source ); |
|
564
|
|
|
|
|
|
|
} |
|
565
|
|
|
|
|
|
|
elsif ( $method eq 'string' ) { |
|
566
|
77
|
|
|
|
|
221
|
$tree = $tpp->parse($source); |
|
567
|
|
|
|
|
|
|
} |
|
568
|
|
|
|
|
|
|
elsif ( $method eq 'file' ) { |
|
569
|
1
|
|
|
|
|
4
|
$tree = $tpp->parsefile($source); |
|
570
|
|
|
|
|
|
|
} |
|
571
|
|
|
|
|
|
|
else { |
|
572
|
0
|
|
|
|
|
0
|
Carp::croak "Invalid load type: $method"; |
|
573
|
|
|
|
|
|
|
} |
|
574
|
|
|
|
|
|
|
|
|
575
|
77
|
100
|
|
|
|
232342
|
Carp::croak "Loading failed: $source" unless ref $tree; |
|
576
|
76
|
|
|
|
|
305
|
%$self = %$tree; # override myself |
|
577
|
76
|
|
|
|
|
321
|
$self; |
|
578
|
|
|
|
|
|
|
} |
|
579
|
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
sub to_string { |
|
581
|
91
|
|
|
91
|
1
|
21418
|
my $self = shift; |
|
582
|
91
|
|
|
|
|
205
|
my( $args, $encode, @rest ) = XML::FeedPP::Util::param_even_odd(@_); |
|
583
|
91
|
|
100
|
|
|
250
|
$args ||= \@rest; |
|
584
|
91
|
100
|
|
|
|
199
|
my @opts = ( output_encoding => $encode ) if $encode; |
|
585
|
91
|
|
|
|
|
505
|
my $tpp = XML::TreePP->new( %$TREEPP_OPTIONS, @opts, @$args ); |
|
586
|
91
|
|
|
|
|
891
|
$tpp->write( $self, $encode ); |
|
587
|
|
|
|
|
|
|
} |
|
588
|
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
sub to_file { |
|
590
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
591
|
0
|
|
|
|
|
0
|
my $file = shift; |
|
592
|
0
|
|
|
|
|
0
|
my( $args, $encode, @rest ) = XML::FeedPP::Util::param_even_odd(@_); |
|
593
|
0
|
|
0
|
|
|
0
|
$args ||= \@rest; |
|
594
|
0
|
0
|
|
|
|
0
|
my @opts = ( output_encoding => $encode ) if $encode; |
|
595
|
0
|
|
|
|
|
0
|
my $tpp = XML::TreePP->new( %$TREEPP_OPTIONS, @opts, @$args ); |
|
596
|
0
|
|
|
|
|
0
|
$tpp->writefile( $file, $self, $encode ); |
|
597
|
|
|
|
|
|
|
} |
|
598
|
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
sub merge { |
|
600
|
31
|
|
|
31
|
1
|
22797
|
my $self = shift; |
|
601
|
31
|
|
|
|
|
48
|
my $source = shift; |
|
602
|
31
|
50
|
|
|
|
106
|
my $target = ref $source ? $source : XML::FeedPP->new($source, @_); |
|
603
|
31
|
|
|
|
|
144
|
$self->merge_channel($target); |
|
604
|
31
|
|
|
|
|
116
|
$self->merge_item($target); |
|
605
|
31
|
|
|
|
|
133
|
$self->normalize(); |
|
606
|
31
|
|
|
|
|
343
|
$self; |
|
607
|
|
|
|
|
|
|
} |
|
608
|
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
sub merge_channel { |
|
610
|
31
|
|
|
31
|
0
|
57
|
my $self = shift; |
|
611
|
31
|
50
|
|
|
|
78
|
my $target = shift or return; |
|
612
|
31
|
50
|
|
|
|
76
|
if ( ref $self eq ref $target ) { |
|
613
|
0
|
|
|
|
|
0
|
$self->merge_native_channel($target); |
|
614
|
|
|
|
|
|
|
} |
|
615
|
|
|
|
|
|
|
else { |
|
616
|
31
|
|
|
|
|
122
|
$self->merge_common_channel($target); |
|
617
|
|
|
|
|
|
|
} |
|
618
|
|
|
|
|
|
|
} |
|
619
|
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
sub merge_item { |
|
621
|
31
|
|
|
31
|
0
|
47
|
my $self = shift; |
|
622
|
31
|
50
|
|
|
|
63
|
my $target = shift or return; |
|
623
|
31
|
|
|
|
|
80
|
foreach my $item ( $target->get_item() ) { |
|
624
|
59
|
|
|
|
|
133
|
$self->add_item( $item ); |
|
625
|
|
|
|
|
|
|
} |
|
626
|
|
|
|
|
|
|
} |
|
627
|
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
sub merge_common_channel { |
|
629
|
31
|
|
|
31
|
0
|
60
|
my $self = shift; |
|
630
|
31
|
50
|
|
|
|
105
|
my $target = shift or return; |
|
631
|
|
|
|
|
|
|
|
|
632
|
31
|
|
|
|
|
80
|
my $title1 = $self->title(); |
|
633
|
31
|
|
|
|
|
91
|
my $title2 = $target->title(); |
|
634
|
31
|
100
|
100
|
|
|
169
|
$self->title($title2) if ( !defined $title1 && defined $title2 ); |
|
635
|
|
|
|
|
|
|
|
|
636
|
31
|
|
|
|
|
80
|
my $desc1 = $self->description(); |
|
637
|
31
|
|
|
|
|
94
|
my $desc2 = $target->description(); |
|
638
|
31
|
100
|
66
|
|
|
141
|
$self->description($desc2) if ( !defined $desc1 && defined $desc2 ); |
|
639
|
|
|
|
|
|
|
|
|
640
|
31
|
|
|
|
|
79
|
my $link1 = $self->link(); |
|
641
|
31
|
|
|
|
|
75
|
my $link2 = $target->link(); |
|
642
|
31
|
100
|
66
|
|
|
170
|
$self->link($link2) if ( !defined $link1 && defined $link2 ); |
|
643
|
|
|
|
|
|
|
|
|
644
|
31
|
|
|
|
|
95
|
my $lang1 = $self->language(); |
|
645
|
31
|
|
|
|
|
79
|
my $lang2 = $target->language(); |
|
646
|
31
|
100
|
66
|
|
|
141
|
$self->language($lang2) if ( !defined $lang1 && defined $lang2 ); |
|
647
|
|
|
|
|
|
|
|
|
648
|
31
|
|
|
|
|
70
|
my $right1 = $self->copyright(); |
|
649
|
31
|
|
|
|
|
72
|
my $right2 = $target->copyright(); |
|
650
|
31
|
100
|
66
|
|
|
144
|
$self->copyright($right2) if ( !defined $right1 && defined $right2 ); |
|
651
|
|
|
|
|
|
|
|
|
652
|
31
|
|
|
|
|
105
|
my $pubDate1 = $self->pubDate(); |
|
653
|
31
|
|
|
|
|
76
|
my $pubDate2 = $target->pubDate(); |
|
654
|
31
|
100
|
66
|
|
|
126
|
$self->pubDate($pubDate2) if ( !defined $pubDate1 && defined $pubDate2 ); |
|
655
|
|
|
|
|
|
|
|
|
656
|
31
|
|
|
|
|
117
|
my @image1 = $self->image(); |
|
657
|
31
|
|
|
|
|
86
|
my @image2 = $target->image(); |
|
658
|
31
|
100
|
66
|
|
|
171
|
$self->image(@image2) if ( !defined $image1[0] && defined $image2[0] ); |
|
659
|
|
|
|
|
|
|
|
|
660
|
31
|
|
|
|
|
75
|
my @xmlns1 = $self->xmlns(); |
|
661
|
31
|
|
|
|
|
86
|
my @xmlns2 = $target->xmlns(); |
|
662
|
31
|
|
|
|
|
77
|
my $xmlchk = { map { $_ => 1 } @xmlns1, @$XML::FeedPP::XMLNS_NOCOPY }; |
|
|
177
|
|
|
|
|
311
|
|
|
663
|
31
|
|
|
|
|
89
|
foreach my $ns (@xmlns2) { |
|
664
|
48
|
100
|
|
|
|
121
|
next if exists $xmlchk->{$ns}; |
|
665
|
11
|
|
|
|
|
15
|
$self->xmlns( $ns, $target->xmlns($ns) ); |
|
666
|
|
|
|
|
|
|
} |
|
667
|
|
|
|
|
|
|
|
|
668
|
31
|
|
|
|
|
98
|
$self->merge_module_nodes( $self->docroot, $target->docroot ); |
|
669
|
|
|
|
|
|
|
|
|
670
|
31
|
|
|
|
|
112
|
$self; |
|
671
|
|
|
|
|
|
|
} |
|
672
|
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
sub add_clone_item { |
|
674
|
65
|
|
|
65
|
0
|
104
|
my $self = shift; |
|
675
|
65
|
50
|
|
|
|
131
|
my $srcitem = shift or return; |
|
676
|
65
|
50
|
|
|
|
125
|
my $link = $srcitem->link() or return; |
|
677
|
65
|
|
|
|
|
211
|
my $dstitem = $self->add_item( $link ); |
|
678
|
|
|
|
|
|
|
|
|
679
|
65
|
100
|
|
|
|
149
|
if ( ref $dstitem eq ref $srcitem ) { |
|
680
|
3
|
|
|
|
|
12
|
XML::FeedPP::Util::merge_hash( $dstitem, $srcitem ); |
|
681
|
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
# A new item starts with a link, and then a merge. Setting the |
|
683
|
|
|
|
|
|
|
# link often affects the guid. The merge will not set the guid |
|
684
|
|
|
|
|
|
|
# anymore. So, let's overrule that. |
|
685
|
3
|
100
|
|
|
|
13
|
if(my $guid = $srcitem->{guid}) { |
|
686
|
1
|
|
|
|
|
4
|
$dstitem->{guid} = $guid; |
|
687
|
|
|
|
|
|
|
} |
|
688
|
|
|
|
|
|
|
} |
|
689
|
|
|
|
|
|
|
else { |
|
690
|
62
|
|
|
|
|
131
|
my $title = $srcitem->title(); |
|
691
|
62
|
100
|
|
|
|
175
|
$dstitem->title($title) if defined $title; |
|
692
|
|
|
|
|
|
|
|
|
693
|
62
|
|
|
|
|
129
|
my $description = $srcitem->description(); |
|
694
|
62
|
100
|
|
|
|
143
|
$dstitem->description($description) if defined $description; |
|
695
|
|
|
|
|
|
|
|
|
696
|
62
|
|
|
|
|
116
|
my $category = $srcitem->category(); |
|
697
|
62
|
100
|
|
|
|
151
|
$dstitem->category($category) if defined $category; |
|
698
|
|
|
|
|
|
|
|
|
699
|
62
|
|
|
|
|
158
|
my $author = $srcitem->author(); |
|
700
|
62
|
100
|
|
|
|
140
|
$dstitem->author($author) if defined $author; |
|
701
|
|
|
|
|
|
|
|
|
702
|
62
|
|
|
|
|
123
|
my $guid = $srcitem->guid(); |
|
703
|
62
|
100
|
|
|
|
146
|
$dstitem->guid($guid) if defined $guid; |
|
704
|
|
|
|
|
|
|
|
|
705
|
62
|
|
|
|
|
108
|
my $pubDate = $srcitem->pubDate(); |
|
706
|
62
|
100
|
|
|
|
145
|
$dstitem->pubDate($pubDate) if defined $pubDate; |
|
707
|
|
|
|
|
|
|
|
|
708
|
62
|
|
|
|
|
136
|
$self->merge_module_nodes( $dstitem, $srcitem ); |
|
709
|
|
|
|
|
|
|
} |
|
710
|
|
|
|
|
|
|
|
|
711
|
65
|
|
|
|
|
170
|
$dstitem; |
|
712
|
|
|
|
|
|
|
} |
|
713
|
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
sub merge_module_nodes { |
|
715
|
93
|
|
|
93
|
0
|
124
|
my $self = shift; |
|
716
|
93
|
|
|
|
|
127
|
my $item1 = shift; |
|
717
|
93
|
|
|
|
|
117
|
my $item2 = shift; |
|
718
|
93
|
|
|
|
|
186
|
foreach my $key ( grep { /:/ } keys %$item2 ) { |
|
|
377
|
|
|
|
|
713
|
|
|
719
|
90
|
100
|
|
|
|
302
|
next if ( $key =~ /^-?(dc|rdf|xmlns):/ ); |
|
720
|
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
# deep copy would be better |
|
722
|
23
|
|
|
|
|
99
|
$item1->{$key} = $item2->{$key}; |
|
723
|
|
|
|
|
|
|
} |
|
724
|
|
|
|
|
|
|
} |
|
725
|
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
sub normalize { |
|
727
|
37
|
|
|
37
|
1
|
126
|
my $self = shift; |
|
728
|
37
|
|
|
|
|
162
|
$self->normalize_pubDate(); |
|
729
|
37
|
|
|
|
|
126
|
$self->sort_item(); |
|
730
|
37
|
|
|
|
|
113
|
$self->uniq_item(); |
|
731
|
|
|
|
|
|
|
} |
|
732
|
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
sub normalize_pubDate { |
|
734
|
37
|
|
|
37
|
0
|
50
|
my $self = shift; |
|
735
|
37
|
|
|
|
|
116
|
foreach my $item ( $self->get_item() ) { |
|
736
|
77
|
100
|
|
|
|
170
|
my $date = $item->get_pubDate_native() or next; |
|
737
|
45
|
|
|
|
|
86
|
$item->pubDate( $date ); |
|
738
|
|
|
|
|
|
|
} |
|
739
|
37
|
|
|
|
|
104
|
my $date = $self->get_pubDate_native(); |
|
740
|
37
|
100
|
|
|
|
116
|
$self->pubDate( $date ) if $date; |
|
741
|
|
|
|
|
|
|
} |
|
742
|
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
sub xmlns { |
|
744
|
312
|
|
|
312
|
1
|
426
|
my $self = shift; |
|
745
|
312
|
|
|
|
|
367
|
my $ns = shift; |
|
746
|
312
|
|
|
|
|
424
|
my $url = shift; |
|
747
|
312
|
|
|
|
|
595
|
my $root = $self->docroot; |
|
748
|
312
|
100
|
|
|
|
711
|
if ( !defined $ns ) { |
|
|
|
100
|
|
|
|
|
|
|
749
|
74
|
|
|
|
|
182
|
my $list = [ grep { /^-xmlns(:\S|$)/ } keys %$root ]; |
|
|
339
|
|
|
|
|
681
|
|
|
750
|
74
|
|
|
|
|
143
|
return map { (/^-(.*)$/)[0] } @$list; |
|
|
129
|
|
|
|
|
392
|
|
|
751
|
|
|
|
|
|
|
} |
|
752
|
|
|
|
|
|
|
elsif ( !defined $url ) { |
|
753
|
20
|
50
|
|
|
|
58
|
return unless exists $root->{ '-' . $ns }; |
|
754
|
20
|
|
|
|
|
59
|
return $root->{ '-' . $ns }; |
|
755
|
|
|
|
|
|
|
} |
|
756
|
|
|
|
|
|
|
else { |
|
757
|
218
|
|
|
|
|
576
|
$root->{ '-' . $ns } = $url; |
|
758
|
|
|
|
|
|
|
} |
|
759
|
|
|
|
|
|
|
} |
|
760
|
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
sub get_pubDate_w3cdtf { |
|
762
|
82
|
|
|
82
|
0
|
141
|
my $self = shift; |
|
763
|
82
|
|
|
|
|
187
|
my $date = $self->get_pubDate_native(); |
|
764
|
82
|
|
|
|
|
208
|
XML::FeedPP::Util::get_w3cdtf($date); |
|
765
|
|
|
|
|
|
|
} |
|
766
|
|
|
|
|
|
|
|
|
767
|
|
|
|
|
|
|
sub get_pubDate_rfc1123 { |
|
768
|
21
|
|
|
21
|
0
|
902
|
my $self = shift; |
|
769
|
21
|
|
|
|
|
40
|
my $date = $self->get_pubDate_native(); |
|
770
|
21
|
|
|
|
|
39
|
XML::FeedPP::Util::get_rfc1123($date); |
|
771
|
|
|
|
|
|
|
} |
|
772
|
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
sub get_pubDate_epoch { |
|
774
|
113
|
|
|
113
|
0
|
155
|
my $self = shift; |
|
775
|
113
|
|
|
|
|
175
|
my $date = $self->get_pubDate_native(); |
|
776
|
113
|
|
|
|
|
195
|
XML::FeedPP::Util::get_epoch($date); |
|
777
|
|
|
|
|
|
|
} |
|
778
|
|
|
|
|
|
|
|
|
779
|
|
|
|
|
|
|
sub call { |
|
780
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
781
|
0
|
|
|
|
|
0
|
my $name = shift; |
|
782
|
0
|
|
|
|
|
0
|
my $class = __PACKAGE__."::Plugin::".$name; |
|
783
|
0
|
|
|
|
|
0
|
my $pmfile = $class; |
|
784
|
0
|
|
|
|
|
0
|
$pmfile =~ s#::#/#g; |
|
785
|
0
|
|
|
|
|
0
|
$pmfile .= ".pm"; |
|
786
|
0
|
|
|
|
|
0
|
local $@; |
|
787
|
0
|
0
|
|
|
|
0
|
eval { |
|
788
|
0
|
|
|
|
|
0
|
require $pmfile; |
|
789
|
|
|
|
|
|
|
} unless defined $class->VERSION; |
|
790
|
0
|
0
|
|
|
|
0
|
Carp::croak "$class failed: $@" if $@; |
|
791
|
0
|
|
|
|
|
0
|
return $class->run( $self, @_ ); |
|
792
|
|
|
|
|
|
|
} |
|
793
|
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
sub elements { |
|
795
|
99
|
|
|
99
|
0
|
147
|
my $self = shift; |
|
796
|
99
|
|
|
|
|
177
|
my $args = [ @_ ]; |
|
797
|
99
|
|
|
|
|
218
|
my $methods = { map {$_=>1} @$FEED_METHODS }; |
|
|
792
|
|
|
|
|
1360
|
|
|
798
|
99
|
|
|
|
|
451
|
while ( my $key = shift @$args ) { |
|
799
|
27
|
|
|
|
|
31
|
my $val = shift @$args; |
|
800
|
27
|
100
|
|
|
|
39
|
if ( $methods->{$key} ) { |
|
801
|
24
|
|
|
|
|
69
|
$self->$key( $val ); |
|
802
|
|
|
|
|
|
|
} else { |
|
803
|
3
|
|
|
|
|
7
|
$self->set( $key, $val ); |
|
804
|
|
|
|
|
|
|
} |
|
805
|
|
|
|
|
|
|
} |
|
806
|
|
|
|
|
|
|
} |
|
807
|
|
|
|
|
|
|
|
|
808
|
|
|
|
|
|
|
sub match_item { |
|
809
|
12
|
|
|
12
|
1
|
4065
|
my $self = shift; |
|
810
|
12
|
|
|
|
|
23
|
my @list = $self->get_item(); |
|
811
|
12
|
50
|
|
|
|
23
|
return unless scalar @list; |
|
812
|
12
|
|
|
|
|
21
|
my $methods = { map {$_=>1} @$ITEM_METHODS }; |
|
|
108
|
|
|
|
|
155
|
|
|
813
|
12
|
|
|
|
|
25
|
my $args = [ @_ ]; |
|
814
|
12
|
|
|
|
|
18
|
my $out = []; |
|
815
|
12
|
|
|
|
|
19
|
foreach my $item ( @list ) { |
|
816
|
36
|
|
|
|
|
35
|
my $unmatch = 0; |
|
817
|
36
|
|
|
|
|
34
|
my $i = 0; |
|
818
|
36
|
|
|
|
|
34
|
while( 1 ) { |
|
819
|
63
|
100
|
|
|
|
107
|
my $key = $args->[$i++] or last; |
|
820
|
42
|
|
|
|
|
41
|
my $test = $args->[$i++]; |
|
821
|
42
|
100
|
|
|
|
90
|
my $got = $methods->{$key} ? $item->$key() : $item->get( $key ); |
|
822
|
42
|
100
|
|
|
|
213
|
unless ( $got =~ $test ) { |
|
823
|
15
|
|
|
|
|
17
|
$unmatch ++; |
|
824
|
15
|
|
|
|
|
21
|
last; |
|
825
|
|
|
|
|
|
|
} |
|
826
|
|
|
|
|
|
|
} |
|
827
|
36
|
100
|
|
|
|
56
|
unless ( $unmatch ) { |
|
828
|
21
|
50
|
|
|
|
29
|
return $item unless wantarray; |
|
829
|
21
|
|
|
|
|
35
|
push( @$out, $item ); |
|
830
|
|
|
|
|
|
|
} |
|
831
|
|
|
|
|
|
|
} |
|
832
|
12
|
|
|
|
|
47
|
@$out; |
|
833
|
|
|
|
|
|
|
} |
|
834
|
|
|
|
|
|
|
|
|
835
|
0
|
|
|
0
|
0
|
0
|
sub channel_class { Carp::croak((ref $_[0])."->channel_class() is not implemented"); } |
|
836
|
0
|
|
|
0
|
0
|
0
|
sub item_class { Carp::croak((ref $_[0])."->item_class() is not implemented"); } |
|
837
|
0
|
|
|
0
|
0
|
0
|
sub test_feed { Carp::croak((ref $_[0])."->test_feed() is not implemented"); } |
|
838
|
0
|
|
|
0
|
0
|
0
|
sub init_feed { Carp::croak((ref $_[0])."->init_feed() is not implemented"); } |
|
839
|
0
|
|
|
0
|
1
|
0
|
sub add_item { Carp::croak((ref $_[0])."->add_item() is not implemented"); } |
|
840
|
0
|
|
|
0
|
1
|
0
|
sub clear_item { Carp::croak((ref $_[0])."->clear_item() is not implemented"); } |
|
841
|
0
|
|
|
0
|
1
|
0
|
sub remove_item { Carp::croak((ref $_[0])."->remove_item() is not implemented"); } |
|
842
|
0
|
|
|
0
|
1
|
0
|
sub get_item { Carp::croak((ref $_[0])."->get_item() is not implemented"); } |
|
843
|
0
|
|
|
0
|
1
|
0
|
sub sort_item { Carp::croak((ref $_[0])."->sort_item() is not implemented"); } |
|
844
|
0
|
|
|
0
|
1
|
0
|
sub uniq_item { Carp::croak((ref $_[0])."->uniq_item() is not implemented"); } |
|
845
|
0
|
|
|
0
|
1
|
0
|
sub limit_item { Carp::croak((ref $_[0])."->limit_item() is not implemented"); } |
|
846
|
0
|
|
|
0
|
0
|
0
|
sub docroot { Carp::croak((ref $_[0])."->docroot() is not implemented"); } |
|
847
|
0
|
|
|
0
|
0
|
0
|
sub channel { Carp::croak((ref $_[0])."->channel() is not implemented"); } |
|
848
|
0
|
|
|
0
|
1
|
0
|
sub set { Carp::croak((ref $_[0])."->set() is not implemented"); } |
|
849
|
0
|
|
|
0
|
1
|
0
|
sub get { Carp::croak((ref $_[0])."->get() is not implemented"); } |
|
850
|
0
|
|
|
0
|
1
|
0
|
sub title { Carp::croak((ref $_[0])."->title() is not implemented"); } |
|
851
|
0
|
|
|
0
|
1
|
0
|
sub description { Carp::croak((ref $_[0])."->description() is not implemented"); } |
|
852
|
0
|
|
|
0
|
1
|
0
|
sub link { Carp::croak((ref $_[0])."->link() is not implemented"); } |
|
853
|
0
|
|
|
0
|
1
|
0
|
sub language { Carp::croak((ref $_[0])."->language() is not implemented"); } |
|
854
|
0
|
|
|
0
|
1
|
0
|
sub copyright { Carp::croak((ref $_[0])."->copyright() is not implemented"); } |
|
855
|
0
|
|
|
0
|
1
|
0
|
sub pubDate { Carp::croak((ref $_[0])."->pubDate() is not implemented"); } |
|
856
|
0
|
|
|
0
|
1
|
0
|
sub image { Carp::croak((ref $_[0])."->image() is not implemented"); } |
|
857
|
|
|
|
|
|
|
|
|
858
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
859
|
|
|
|
|
|
|
package XML::FeedPP::Plugin; |
|
860
|
44
|
|
|
44
|
|
323
|
use strict; |
|
|
44
|
|
|
|
|
114
|
|
|
|
44
|
|
|
|
|
3085
|
|
|
861
|
|
|
|
|
|
|
|
|
862
|
|
|
|
|
|
|
sub run { |
|
863
|
0
|
|
|
0
|
|
0
|
my $class = shift; |
|
864
|
0
|
|
|
|
|
0
|
my $feed = shift; |
|
865
|
0
|
0
|
|
|
|
0
|
my $ref = ref $class ? ref $class : $class; |
|
866
|
0
|
|
|
|
|
0
|
Carp::croak $ref."->run() is not implemented"; |
|
867
|
|
|
|
|
|
|
} |
|
868
|
|
|
|
|
|
|
|
|
869
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
870
|
|
|
|
|
|
|
package XML::FeedPP::Item; |
|
871
|
44
|
|
|
44
|
|
241
|
use strict; |
|
|
44
|
|
|
|
|
78
|
|
|
|
44
|
|
|
|
|
1020
|
|
|
872
|
44
|
|
|
44
|
|
202
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
61
|
|
|
|
44
|
|
|
|
|
6607
|
|
|
873
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Element ); |
|
874
|
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
*get_pubDate_w3cdtf = \&XML::FeedPP::get_pubDate_w3cdtf; # import |
|
876
|
|
|
|
|
|
|
*get_pubDate_rfc1123 = \&XML::FeedPP::get_pubDate_rfc1123; |
|
877
|
|
|
|
|
|
|
*get_pubDate_epoch = \&XML::FeedPP::get_pubDate_epoch; |
|
878
|
|
|
|
|
|
|
|
|
879
|
|
|
|
|
|
|
sub elements { |
|
880
|
33
|
|
|
33
|
|
37
|
my $self = shift; |
|
881
|
33
|
|
|
|
|
58
|
my $args = [ @_ ]; |
|
882
|
33
|
|
|
|
|
54
|
my $methods = { map {$_=>1} @$XML::FeedPP::ITEM_METHODS }; |
|
|
297
|
|
|
|
|
441
|
|
|
883
|
33
|
|
|
|
|
81
|
while ( my $key = shift @$args ) { |
|
884
|
99
|
|
|
|
|
105
|
my $val = shift @$args; |
|
885
|
99
|
100
|
|
|
|
137
|
if ( $methods->{$key} ) { |
|
886
|
87
|
|
|
|
|
159
|
$self->$key( $val ); |
|
887
|
|
|
|
|
|
|
} else { |
|
888
|
12
|
|
|
|
|
28
|
$self->set( $key, $val ); |
|
889
|
|
|
|
|
|
|
} |
|
890
|
|
|
|
|
|
|
} |
|
891
|
|
|
|
|
|
|
} |
|
892
|
|
|
|
|
|
|
|
|
893
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
894
|
|
|
|
|
|
|
package XML::FeedPP::RSS; |
|
895
|
44
|
|
|
44
|
|
273
|
use strict; |
|
|
44
|
|
|
|
|
84
|
|
|
|
44
|
|
|
|
|
1063
|
|
|
896
|
44
|
|
|
44
|
|
203
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
85
|
|
|
|
44
|
|
|
|
|
56117
|
|
|
897
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP ); |
|
898
|
|
|
|
|
|
|
|
|
899
|
|
|
|
|
|
|
sub channel_class { |
|
900
|
106
|
|
|
106
|
|
603
|
'XML::FeedPP::RSS::Channel'; |
|
901
|
|
|
|
|
|
|
} |
|
902
|
|
|
|
|
|
|
|
|
903
|
|
|
|
|
|
|
sub item_class { |
|
904
|
67
|
|
|
67
|
|
242
|
'XML::FeedPP::RSS::Item'; |
|
905
|
|
|
|
|
|
|
} |
|
906
|
|
|
|
|
|
|
|
|
907
|
|
|
|
|
|
|
sub test_feed { |
|
908
|
101
|
|
|
101
|
|
141
|
my $self = shift; |
|
909
|
101
|
|
66
|
|
|
320
|
my $source = shift || $self; |
|
910
|
101
|
50
|
|
|
|
258
|
return unless ref $source; |
|
911
|
101
|
100
|
|
|
|
259
|
return unless ref $source->{rss}; |
|
912
|
59
|
|
|
|
|
135
|
__PACKAGE__; |
|
913
|
|
|
|
|
|
|
} |
|
914
|
|
|
|
|
|
|
|
|
915
|
|
|
|
|
|
|
sub init_feed { |
|
916
|
68
|
50
|
|
68
|
|
230
|
my $self = shift or return; |
|
917
|
|
|
|
|
|
|
|
|
918
|
68
|
|
100
|
|
|
370
|
$self->{rss} ||= {}; |
|
919
|
68
|
50
|
|
|
|
239
|
if ( ! UNIVERSAL::isa( $self->{rss}, 'HASH' ) ) { |
|
920
|
0
|
|
|
|
|
0
|
Carp::croak "Invalid RSS 2.0 feed format: $self->{rss}"; |
|
921
|
|
|
|
|
|
|
} |
|
922
|
68
|
|
66
|
|
|
273
|
$self->{rss}->{'-version'} ||= $XML::FeedPP::RSS20_VERSION; |
|
923
|
|
|
|
|
|
|
|
|
924
|
68
|
|
66
|
|
|
270
|
my $channel = $self->{rss}{channel} ||= $self->channel_class->new(); |
|
925
|
68
|
|
|
|
|
171
|
$self->channel_class->ref_bless($channel); |
|
926
|
|
|
|
|
|
|
|
|
927
|
68
|
|
100
|
|
|
248
|
my $items = $channel->{item} || []; |
|
928
|
68
|
50
|
|
|
|
351
|
my @items = grep ref $_, # skip empty items |
|
929
|
|
|
|
|
|
|
UNIVERSAL::isa($items, 'HASH') ? $items : @$items; |
|
930
|
|
|
|
|
|
|
|
|
931
|
68
|
|
|
|
|
199
|
$self->item_class->ref_bless($_) for @items; |
|
932
|
68
|
|
|
|
|
147
|
$channel->{item} = \@items; |
|
933
|
|
|
|
|
|
|
|
|
934
|
68
|
|
|
|
|
155
|
$self; |
|
935
|
|
|
|
|
|
|
} |
|
936
|
|
|
|
|
|
|
|
|
937
|
|
|
|
|
|
|
sub merge_native_channel { |
|
938
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
939
|
0
|
0
|
|
|
|
0
|
my $tree = shift or next; |
|
940
|
|
|
|
|
|
|
|
|
941
|
0
|
|
|
|
|
0
|
XML::FeedPP::Util::merge_hash( $self->{rss}, $tree->{rss}, qw( channel ) ); |
|
942
|
|
|
|
|
|
|
XML::FeedPP::Util::merge_hash( |
|
943
|
|
|
|
|
|
|
$self->{rss}->{channel}, |
|
944
|
|
|
|
|
|
|
$tree->{rss}->{channel}, |
|
945
|
0
|
|
|
|
|
0
|
qw( item ) |
|
946
|
|
|
|
|
|
|
); |
|
947
|
|
|
|
|
|
|
} |
|
948
|
|
|
|
|
|
|
|
|
949
|
|
|
|
|
|
|
sub add_item { |
|
950
|
108
|
|
|
108
|
|
1499
|
my $self = shift; |
|
951
|
108
|
|
|
|
|
225
|
my( $init, $link, @rest ) = &XML::FeedPP::Util::param_even_odd(@_); |
|
952
|
|
|
|
|
|
|
|
|
953
|
108
|
50
|
66
|
|
|
392
|
Carp::croak "add_item needs an argument" if ( ! ref $init && ! $link ); |
|
954
|
108
|
100
|
|
|
|
229
|
if ( ref $link ) { |
|
955
|
23
|
|
|
|
|
77
|
return $self->add_clone_item( $link ); |
|
956
|
|
|
|
|
|
|
} |
|
957
|
|
|
|
|
|
|
|
|
958
|
85
|
|
|
|
|
366
|
my $item = XML::FeedPP::RSS::Item->new(@rest); |
|
959
|
85
|
100
|
|
|
|
267
|
$item->link($link) if $link; |
|
960
|
85
|
100
|
|
|
|
164
|
$item->elements(@$init) if ref $init; |
|
961
|
85
|
|
|
|
|
106
|
push( @{ $self->{rss}->{channel}->{item} }, $item ); |
|
|
85
|
|
|
|
|
202
|
|
|
962
|
85
|
|
|
|
|
188
|
$item; |
|
963
|
|
|
|
|
|
|
} |
|
964
|
|
|
|
|
|
|
|
|
965
|
|
|
|
|
|
|
sub clear_item { |
|
966
|
1
|
|
|
1
|
|
11063
|
my $self = shift; |
|
967
|
1
|
|
|
|
|
6
|
$self->{rss}->{channel}->{item} = []; |
|
968
|
|
|
|
|
|
|
} |
|
969
|
|
|
|
|
|
|
|
|
970
|
|
|
|
|
|
|
sub remove_item { |
|
971
|
7
|
|
|
7
|
|
15
|
my $self = shift; |
|
972
|
7
|
|
|
|
|
9
|
my $remove = shift; |
|
973
|
7
|
50
|
|
|
|
19
|
my $list = $self->{rss}->{channel}->{item} or return; |
|
974
|
7
|
|
|
|
|
9
|
my @deleted; |
|
975
|
|
|
|
|
|
|
|
|
976
|
7
|
100
|
|
|
|
29
|
if ( $remove =~ /^-?\d+/ ) { |
|
977
|
6
|
|
|
|
|
13
|
@deleted = splice( @$list, $remove, 1 ); |
|
978
|
|
|
|
|
|
|
} |
|
979
|
|
|
|
|
|
|
else { |
|
980
|
1
|
|
|
|
|
3
|
@deleted = grep { $_->link() eq $remove } @$list; |
|
|
3
|
|
|
|
|
5
|
|
|
981
|
1
|
|
|
|
|
2
|
@$list = grep { $_->link() ne $remove } @$list; |
|
|
3
|
|
|
|
|
5
|
|
|
982
|
|
|
|
|
|
|
} |
|
983
|
|
|
|
|
|
|
|
|
984
|
7
|
50
|
|
|
|
27
|
wantarray ? @deleted : shift @deleted; |
|
985
|
|
|
|
|
|
|
} |
|
986
|
|
|
|
|
|
|
|
|
987
|
|
|
|
|
|
|
sub get_item { |
|
988
|
131
|
|
|
131
|
|
34167
|
my $self = shift; |
|
989
|
131
|
|
|
|
|
175
|
my $num = shift; |
|
990
|
131
|
|
50
|
|
|
364
|
$self->{rss}->{channel}->{item} ||= []; |
|
991
|
131
|
100
|
|
|
|
317
|
if ( defined $num ) { |
|
|
|
100
|
|
|
|
|
|
|
992
|
57
|
|
|
|
|
177
|
return $self->{rss}->{channel}->{item}->[$num]; |
|
993
|
|
|
|
|
|
|
} |
|
994
|
|
|
|
|
|
|
elsif (wantarray) { |
|
995
|
40
|
|
|
|
|
51
|
return @{ $self->{rss}->{channel}->{item} }; |
|
|
40
|
|
|
|
|
119
|
|
|
996
|
|
|
|
|
|
|
} |
|
997
|
|
|
|
|
|
|
else { |
|
998
|
34
|
|
|
|
|
44
|
return scalar @{ $self->{rss}->{channel}->{item} }; |
|
|
34
|
|
|
|
|
189
|
|
|
999
|
|
|
|
|
|
|
} |
|
1000
|
|
|
|
|
|
|
} |
|
1001
|
|
|
|
|
|
|
|
|
1002
|
|
|
|
|
|
|
sub sort_item { |
|
1003
|
15
|
|
|
15
|
|
29
|
my $self = shift; |
|
1004
|
15
|
50
|
|
|
|
62
|
my $list = $self->{rss}->{channel}->{item} or return; |
|
1005
|
15
|
100
|
|
|
|
44
|
my $epoch = [ map { $_->get_pubDate_epoch() || 0 } @$list ]; |
|
|
37
|
|
|
|
|
96
|
|
|
1006
|
37
|
|
|
|
|
76
|
my $sorted = [ map { $list->[$_] } sort { |
|
1007
|
15
|
|
|
|
|
72
|
$epoch->[$b] <=> $epoch->[$a] |
|
|
46
|
|
|
|
|
67
|
|
|
1008
|
|
|
|
|
|
|
} 0 .. $#$list ]; |
|
1009
|
15
|
|
|
|
|
40
|
@$list = @$sorted; |
|
1010
|
15
|
|
|
|
|
47
|
scalar @$list; |
|
1011
|
|
|
|
|
|
|
} |
|
1012
|
|
|
|
|
|
|
|
|
1013
|
|
|
|
|
|
|
sub uniq_item { |
|
1014
|
13
|
|
|
13
|
|
28
|
my $self = shift; |
|
1015
|
13
|
50
|
|
|
|
54
|
my $list = $self->{rss}->{channel}->{item} or return; |
|
1016
|
13
|
|
|
|
|
32
|
my (%check, @uniq); |
|
1017
|
13
|
|
|
|
|
42
|
foreach my $item (@$list) { |
|
1018
|
27
|
|
66
|
|
|
53
|
my $key = $item->guid() || $item->link(); |
|
1019
|
27
|
100
|
|
|
|
128
|
push( @uniq, $item ) unless $check{$key}++; |
|
1020
|
|
|
|
|
|
|
} |
|
1021
|
13
|
|
|
|
|
47
|
@$list = @uniq; |
|
1022
|
13
|
|
|
|
|
42
|
scalar @$list; |
|
1023
|
|
|
|
|
|
|
} |
|
1024
|
|
|
|
|
|
|
|
|
1025
|
|
|
|
|
|
|
sub limit_item { |
|
1026
|
7
|
|
|
7
|
|
15
|
my $self = shift; |
|
1027
|
7
|
|
|
|
|
9
|
my $limit = shift; |
|
1028
|
7
|
50
|
|
|
|
20
|
my $list = $self->{rss}->{channel}->{item} or return; |
|
1029
|
7
|
100
|
100
|
|
|
44
|
if ( $limit > 0 && $limit < scalar @$list ) { |
|
|
|
100
|
100
|
|
|
|
|
|
1030
|
3
|
|
|
|
|
21
|
@$list = splice( @$list, 0, $limit ); # remove from end |
|
1031
|
|
|
|
|
|
|
} |
|
1032
|
|
|
|
|
|
|
elsif ( $limit < 0 && -$limit < scalar @$list ) { |
|
1033
|
2
|
|
|
|
|
7
|
@$list = splice( @$list, $limit ); # remove from start |
|
1034
|
|
|
|
|
|
|
} |
|
1035
|
7
|
|
|
|
|
13
|
scalar @$list; |
|
1036
|
|
|
|
|
|
|
} |
|
1037
|
|
|
|
|
|
|
|
|
1038
|
72
|
|
|
72
|
|
146
|
sub docroot { shift->{rss}; } |
|
1039
|
0
|
|
|
0
|
|
0
|
sub channel { shift->{rss}->{channel}; } |
|
1040
|
2
|
|
|
2
|
|
14
|
sub set { shift->{rss}->{channel}->set(@_); } |
|
1041
|
25
|
|
|
25
|
|
10177
|
sub get { shift->{rss}->{channel}->get(@_); } |
|
1042
|
|
|
|
|
|
|
|
|
1043
|
54
|
|
|
54
|
|
4812
|
sub title { shift->{rss}->{channel}->get_or_set( "title", @_ ); } |
|
1044
|
38
|
|
|
38
|
|
116
|
sub description { shift->{rss}->{channel}->get_or_set( "description", @_ ); } |
|
1045
|
56
|
|
|
56
|
|
3270
|
sub link { shift->{rss}->{channel}->get_or_set( "link", @_ ); } |
|
1046
|
36
|
|
|
36
|
|
100
|
sub language { shift->{rss}->{channel}->get_or_set( "language", @_ ); } |
|
1047
|
35
|
|
|
35
|
|
110
|
sub copyright { shift->{rss}->{channel}->get_or_set( "copyright", @_ ); } |
|
1048
|
|
|
|
|
|
|
|
|
1049
|
|
|
|
|
|
|
sub pubDate { |
|
1050
|
51
|
|
|
51
|
|
100
|
my $self = shift; |
|
1051
|
51
|
|
|
|
|
97
|
my $date = shift; |
|
1052
|
51
|
100
|
|
|
|
182
|
return $self->get_pubDate_w3cdtf() unless defined $date; |
|
1053
|
18
|
|
|
|
|
47
|
$date = XML::FeedPP::Util::get_rfc1123($date); |
|
1054
|
18
|
|
|
|
|
79
|
$self->{rss}->{channel}->set_value( "pubDate", $date ); |
|
1055
|
|
|
|
|
|
|
} |
|
1056
|
|
|
|
|
|
|
|
|
1057
|
|
|
|
|
|
|
sub get_pubDate_native { |
|
1058
|
52
|
|
|
52
|
|
99
|
my $self = shift; |
|
1059
|
|
|
|
|
|
|
$self->{rss}->{channel}->get_value("pubDate") # normal RSS 2.0 |
|
1060
|
52
|
100
|
|
|
|
190
|
|| $self->{rss}->{channel}->get_value("dc:date"); # strange |
|
1061
|
|
|
|
|
|
|
} |
|
1062
|
|
|
|
|
|
|
|
|
1063
|
|
|
|
|
|
|
sub image { |
|
1064
|
32
|
|
|
32
|
|
11422
|
my $self = shift; |
|
1065
|
32
|
|
|
|
|
77
|
my $url = shift; |
|
1066
|
32
|
100
|
|
|
|
133
|
if ( defined $url ) { |
|
|
|
100
|
|
|
|
|
|
|
1067
|
4
|
|
|
|
|
13
|
my ( $title, $link, $desc, $width, $height ) = @_; |
|
1068
|
4
|
|
100
|
|
|
25
|
$self->{rss}->{channel}->{image} ||= {}; |
|
1069
|
4
|
|
|
|
|
7
|
my $image = $self->{rss}->{channel}->{image}; |
|
1070
|
4
|
|
|
|
|
17
|
$image->{url} = $url; |
|
1071
|
4
|
100
|
|
|
|
13
|
$image->{title} = $title if defined $title; |
|
1072
|
4
|
100
|
|
|
|
11
|
$image->{link} = $link if defined $link; |
|
1073
|
4
|
100
|
|
|
|
10
|
$image->{description} = $desc if defined $desc; |
|
1074
|
4
|
100
|
|
|
|
9
|
$image->{width} = $width if defined $width; |
|
1075
|
4
|
100
|
|
|
|
18
|
$image->{height} = $height if defined $height; |
|
1076
|
|
|
|
|
|
|
} |
|
1077
|
|
|
|
|
|
|
elsif ( exists $self->{rss}->{channel}->{image} ) { |
|
1078
|
5
|
|
|
|
|
9
|
my $image = $self->{rss}->{channel}->{image}; |
|
1079
|
5
|
|
|
|
|
14
|
my $array = []; |
|
1080
|
5
|
|
|
|
|
11
|
foreach my $key (qw( url title link description width height )) { |
|
1081
|
30
|
100
|
|
|
|
56
|
push( @$array, exists $image->{$key} ? $image->{$key} : undef ); |
|
1082
|
|
|
|
|
|
|
} |
|
1083
|
5
|
100
|
|
|
|
27
|
return wantarray ? @$array : shift @$array; |
|
1084
|
|
|
|
|
|
|
} |
|
1085
|
27
|
|
|
|
|
67
|
undef; |
|
1086
|
|
|
|
|
|
|
} |
|
1087
|
|
|
|
|
|
|
|
|
1088
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1089
|
|
|
|
|
|
|
package XML::FeedPP::RSS::Channel; |
|
1090
|
44
|
|
|
44
|
|
290
|
use strict; |
|
|
44
|
|
|
|
|
91
|
|
|
|
44
|
|
|
|
|
1013
|
|
|
1091
|
44
|
|
|
44
|
|
193
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
72
|
|
|
|
44
|
|
|
|
|
2397
|
|
|
1092
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Element ); |
|
1093
|
|
|
|
|
|
|
|
|
1094
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1095
|
|
|
|
|
|
|
package XML::FeedPP::RSS::Item; |
|
1096
|
44
|
|
|
44
|
|
283
|
use strict; |
|
|
44
|
|
|
|
|
113
|
|
|
|
44
|
|
|
|
|
977
|
|
|
1097
|
44
|
|
|
44
|
|
218
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
104
|
|
|
|
44
|
|
|
|
|
21270
|
|
|
1098
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Item ); |
|
1099
|
|
|
|
|
|
|
|
|
1100
|
104
|
|
|
104
|
|
16827
|
sub title { shift->get_or_set( "title", @_ ); } |
|
1101
|
56
|
|
|
56
|
|
150
|
sub description { shift->get_or_set( "description", @_ ); } |
|
1102
|
99
|
|
|
99
|
|
9491
|
sub category { shift->get_set_array( "category", @_ ); } |
|
1103
|
|
|
|
|
|
|
|
|
1104
|
|
|
|
|
|
|
sub author { |
|
1105
|
45
|
|
|
45
|
|
100
|
my $self = shift; |
|
1106
|
45
|
100
|
|
|
|
95
|
if ( scalar @_ ) { |
|
1107
|
7
|
|
|
|
|
17
|
$self->set_value( 'author', @_ ); |
|
1108
|
|
|
|
|
|
|
} else { |
|
1109
|
38
|
100
|
|
|
|
81
|
$self->get_value('author') || $self->get_value('dc:creator'); |
|
1110
|
|
|
|
|
|
|
} |
|
1111
|
|
|
|
|
|
|
} |
|
1112
|
|
|
|
|
|
|
|
|
1113
|
|
|
|
|
|
|
sub link { |
|
1114
|
167
|
|
|
167
|
|
1576
|
my $self = shift; |
|
1115
|
167
|
|
|
|
|
199
|
my $link = shift; |
|
1116
|
167
|
100
|
|
|
|
358
|
return $self->get_value("link") unless defined $link; |
|
1117
|
86
|
100
|
|
|
|
160
|
$self->guid($link) unless defined $self->guid(); |
|
1118
|
86
|
|
|
|
|
183
|
$self->set_value( link => $link ); |
|
1119
|
|
|
|
|
|
|
} |
|
1120
|
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
sub guid { |
|
1122
|
252
|
|
|
252
|
|
845
|
my $self = shift; |
|
1123
|
252
|
|
|
|
|
310
|
my $guid = shift; |
|
1124
|
252
|
100
|
|
|
|
538
|
return $self->get_value("guid") unless defined $guid; |
|
1125
|
100
|
|
|
|
|
198
|
my @args = @_; |
|
1126
|
100
|
100
|
|
|
|
212
|
if ( ! scalar @args ) { |
|
|
|
100
|
|
|
|
|
|
|
1127
|
|
|
|
|
|
|
# default |
|
1128
|
98
|
|
|
|
|
163
|
@args = ( 'isPermaLink' => 'true' ); |
|
1129
|
|
|
|
|
|
|
} elsif ( scalar @args == 1 ) { |
|
1130
|
|
|
|
|
|
|
# XML::FeedPP 0.36's behavior |
|
1131
|
1
|
|
|
|
|
3
|
unshift( @args, 'isPermaLink' ); |
|
1132
|
|
|
|
|
|
|
} |
|
1133
|
100
|
|
|
|
|
250
|
$self->set_value( guid => $guid, @args ); |
|
1134
|
|
|
|
|
|
|
} |
|
1135
|
|
|
|
|
|
|
|
|
1136
|
|
|
|
|
|
|
sub pubDate { |
|
1137
|
95
|
|
|
95
|
|
215
|
my $self = shift; |
|
1138
|
95
|
|
|
|
|
118
|
my $date = shift; |
|
1139
|
95
|
100
|
|
|
|
253
|
return $self->get_pubDate_w3cdtf() unless defined $date; |
|
1140
|
53
|
|
|
|
|
87
|
$date = XML::FeedPP::Util::get_rfc1123($date); |
|
1141
|
53
|
|
|
|
|
120
|
$self->set_value( "pubDate", $date ); |
|
1142
|
|
|
|
|
|
|
} |
|
1143
|
|
|
|
|
|
|
|
|
1144
|
|
|
|
|
|
|
sub get_pubDate_native { |
|
1145
|
119
|
|
|
119
|
|
150
|
my $self = shift; |
|
1146
|
119
|
100
|
|
|
|
190
|
$self->get_value("pubDate") # normal RSS 2.0 |
|
1147
|
|
|
|
|
|
|
|| $self->get_value("dc:date"); # strange |
|
1148
|
|
|
|
|
|
|
} |
|
1149
|
|
|
|
|
|
|
|
|
1150
|
|
|
|
|
|
|
sub image { |
|
1151
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
1152
|
0
|
|
|
|
|
0
|
my $url = shift; |
|
1153
|
0
|
0
|
|
|
|
0
|
if ( defined $url ) { |
|
|
|
0
|
|
|
|
|
|
|
1154
|
0
|
|
|
|
|
0
|
my ( $title, $link, $desc, $width, $height ) = @_; |
|
1155
|
0
|
|
0
|
|
|
0
|
$self->{image} ||= {}; |
|
1156
|
0
|
|
|
|
|
0
|
my $image = $self->{image}; |
|
1157
|
0
|
|
|
|
|
0
|
$image->{url} = $url; |
|
1158
|
0
|
0
|
|
|
|
0
|
$image->{title} = $title if defined $title; |
|
1159
|
0
|
0
|
|
|
|
0
|
$image->{link} = $link if defined $link; |
|
1160
|
0
|
0
|
|
|
|
0
|
$image->{description} = $desc if defined $desc; |
|
1161
|
0
|
0
|
|
|
|
0
|
$image->{width} = $width if defined $width; |
|
1162
|
0
|
0
|
|
|
|
0
|
$image->{height} = $height if defined $height; |
|
1163
|
|
|
|
|
|
|
} |
|
1164
|
|
|
|
|
|
|
elsif ( exists $self->{image} ) { |
|
1165
|
0
|
|
|
|
|
0
|
my $image = $self->{image}; |
|
1166
|
0
|
|
|
|
|
0
|
my $array = []; |
|
1167
|
0
|
|
|
|
|
0
|
foreach my $key (qw( url title link description width height )) { |
|
1168
|
0
|
0
|
|
|
|
0
|
push( @$array, exists $image->{$key} ? $image->{$key} : undef ); |
|
1169
|
|
|
|
|
|
|
} |
|
1170
|
0
|
0
|
|
|
|
0
|
return wantarray ? @$array : shift @$array; |
|
1171
|
|
|
|
|
|
|
} |
|
1172
|
0
|
|
|
|
|
0
|
undef; |
|
1173
|
|
|
|
|
|
|
} |
|
1174
|
|
|
|
|
|
|
|
|
1175
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1176
|
|
|
|
|
|
|
package XML::FeedPP::RDF; |
|
1177
|
44
|
|
|
44
|
|
291
|
use strict; |
|
|
44
|
|
|
|
|
88
|
|
|
|
44
|
|
|
|
|
1249
|
|
|
1178
|
44
|
|
|
44
|
|
209
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
96
|
|
|
|
44
|
|
|
|
|
73580
|
|
|
1179
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP ); |
|
1180
|
|
|
|
|
|
|
|
|
1181
|
|
|
|
|
|
|
sub channel_class { |
|
1182
|
77
|
|
|
77
|
|
429
|
'XML::FeedPP::RDF::Channel'; |
|
1183
|
|
|
|
|
|
|
} |
|
1184
|
|
|
|
|
|
|
|
|
1185
|
|
|
|
|
|
|
sub item_class { |
|
1186
|
97
|
|
|
97
|
|
415
|
'XML::FeedPP::RDF::Item'; |
|
1187
|
|
|
|
|
|
|
} |
|
1188
|
|
|
|
|
|
|
|
|
1189
|
|
|
|
|
|
|
sub test_feed { |
|
1190
|
61
|
|
|
61
|
|
92
|
my $self = shift; |
|
1191
|
61
|
|
66
|
|
|
183
|
my $source = shift || $self; |
|
1192
|
61
|
50
|
|
|
|
124
|
return unless ref $source; |
|
1193
|
61
|
100
|
|
|
|
157
|
return unless ref $source->{'rdf:RDF'}; |
|
1194
|
37
|
|
|
|
|
90
|
__PACKAGE__; |
|
1195
|
|
|
|
|
|
|
} |
|
1196
|
|
|
|
|
|
|
|
|
1197
|
|
|
|
|
|
|
sub init_feed { |
|
1198
|
48
|
50
|
|
48
|
|
193
|
my $self = shift or return; |
|
1199
|
|
|
|
|
|
|
|
|
1200
|
48
|
|
100
|
|
|
251
|
$self->{'rdf:RDF'} ||= {}; |
|
1201
|
48
|
50
|
|
|
|
191
|
if ( ! UNIVERSAL::isa( $self->{'rdf:RDF'}, 'HASH' ) ) { |
|
1202
|
0
|
|
|
|
|
0
|
Carp::croak "Invalid RDF 1.0 feed format: $self->{'rdf:RDF'}"; |
|
1203
|
|
|
|
|
|
|
} |
|
1204
|
48
|
|
|
|
|
228
|
$self->xmlns( 'xmlns' => $XML::FeedPP::XMLNS_RSS ); |
|
1205
|
48
|
|
|
|
|
151
|
$self->xmlns( 'xmlns:rdf' => $XML::FeedPP::XMLNS_RDF ); |
|
1206
|
48
|
|
|
|
|
119
|
$self->xmlns( 'xmlns:dc' => $XML::FeedPP::XMLNS_DC ); |
|
1207
|
|
|
|
|
|
|
|
|
1208
|
48
|
|
66
|
|
|
210
|
$self->{'rdf:RDF'}->{channel} ||= $self->channel_class->new(); |
|
1209
|
48
|
|
|
|
|
114
|
$self->channel_class->ref_bless( $self->{'rdf:RDF'}->{channel} ); |
|
1210
|
|
|
|
|
|
|
|
|
1211
|
48
|
|
100
|
|
|
266
|
$self->{'rdf:RDF'}->{channel}->{items} ||= {}; |
|
1212
|
48
|
|
100
|
|
|
220
|
$self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'} ||= {}; |
|
1213
|
|
|
|
|
|
|
|
|
1214
|
48
|
|
|
|
|
86
|
my $rdfseq = $self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'}; |
|
1215
|
|
|
|
|
|
|
|
|
1216
|
|
|
|
|
|
|
# http://www.kawa.net/works/perl/feedpp/feedpp.html#com-2008-05-17T13:13:33Z |
|
1217
|
48
|
100
|
|
|
|
178
|
if ( UNIVERSAL::isa( $rdfseq, 'ARRAY' ) ) { |
|
1218
|
1
|
|
|
|
|
3
|
my $num1 = scalar @$rdfseq; |
|
1219
|
1
|
50
|
33
|
|
|
3
|
my $num2 = scalar grep { ref $_ && exists $_->{'rdf:li'} && ref $_->{'rdf:li'} } @$rdfseq; |
|
|
3
|
|
|
|
|
14
|
|
|
1220
|
1
|
50
|
|
|
|
3
|
my $num3 = scalar grep { ref $_ && keys %$_ == 1 } @$rdfseq; |
|
|
3
|
|
|
|
|
11
|
|
|
1221
|
1
|
50
|
33
|
|
|
7
|
if ( $num1 && $num1 == $num2 && $num1 == $num3 ) { |
|
|
|
|
33
|
|
|
|
|
|
1222
|
1
|
|
|
|
|
3
|
my $newli = [ map { @{$_->{'rdf:li'}} } @$rdfseq ]; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
5
|
|
|
1223
|
1
|
|
|
|
|
2
|
$rdfseq = { 'rdf:li' => $newli }; |
|
1224
|
1
|
|
|
|
|
4
|
$self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'} = $rdfseq; |
|
1225
|
|
|
|
|
|
|
} |
|
1226
|
|
|
|
|
|
|
} |
|
1227
|
|
|
|
|
|
|
|
|
1228
|
48
|
|
100
|
|
|
211
|
$rdfseq->{'rdf:li'} ||= []; |
|
1229
|
48
|
50
|
|
|
|
150
|
if ( UNIVERSAL::isa( $rdfseq->{'rdf:li'}, 'HASH' ) ) { |
|
1230
|
0
|
|
|
|
|
0
|
$rdfseq->{'rdf:li'} = [ $rdfseq->{'rdf:li'} ]; |
|
1231
|
|
|
|
|
|
|
} |
|
1232
|
48
|
|
100
|
|
|
218
|
$self->{'rdf:RDF'}->{item} ||= []; |
|
1233
|
48
|
50
|
|
|
|
141
|
if ( UNIVERSAL::isa( $self->{'rdf:RDF'}->{item}, 'HASH' ) ) { |
|
1234
|
|
|
|
|
|
|
|
|
1235
|
|
|
|
|
|
|
# force array when only one item exist |
|
1236
|
0
|
|
|
|
|
0
|
$self->{'rdf:RDF'}->{item} = [ $self->{'rdf:RDF'}->{item} ]; |
|
1237
|
|
|
|
|
|
|
} |
|
1238
|
48
|
|
|
|
|
72
|
foreach my $item ( @{ $self->{'rdf:RDF'}->{item} } ) { |
|
|
48
|
|
|
|
|
133
|
|
|
1239
|
27
|
|
|
|
|
59
|
$self->item_class->ref_bless($item); |
|
1240
|
|
|
|
|
|
|
} |
|
1241
|
|
|
|
|
|
|
|
|
1242
|
48
|
|
|
|
|
86
|
$self; |
|
1243
|
|
|
|
|
|
|
} |
|
1244
|
|
|
|
|
|
|
|
|
1245
|
|
|
|
|
|
|
sub merge_native_channel { |
|
1246
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
1247
|
0
|
0
|
|
|
|
0
|
my $tree = shift or next; |
|
1248
|
|
|
|
|
|
|
|
|
1249
|
0
|
|
|
|
|
0
|
XML::FeedPP::Util::merge_hash( $self->{'rdf:RDF'}, $tree->{'rdf:RDF'}, |
|
1250
|
|
|
|
|
|
|
qw( channel item ) ); |
|
1251
|
|
|
|
|
|
|
|
|
1252
|
|
|
|
|
|
|
XML::FeedPP::Util::merge_hash( |
|
1253
|
|
|
|
|
|
|
$self->{'rdf:RDF'}->{channel}, |
|
1254
|
|
|
|
|
|
|
$tree->{'rdf:RDF'}->{channel}, |
|
1255
|
0
|
|
|
|
|
0
|
qw( items ) |
|
1256
|
|
|
|
|
|
|
); |
|
1257
|
|
|
|
|
|
|
} |
|
1258
|
|
|
|
|
|
|
|
|
1259
|
|
|
|
|
|
|
sub add_item { |
|
1260
|
98
|
|
|
98
|
|
3318
|
my $self = shift; |
|
1261
|
98
|
|
|
|
|
210
|
my( $init, $link, @rest ) = &XML::FeedPP::Util::param_even_odd(@_); |
|
1262
|
|
|
|
|
|
|
|
|
1263
|
98
|
50
|
66
|
|
|
335
|
Carp::croak "add_item needs an argument" if ( ! ref $init && ! $link ); |
|
1264
|
98
|
100
|
|
|
|
183
|
if ( ref $link ) { |
|
1265
|
28
|
|
|
|
|
81
|
return $self->add_clone_item( $link ); |
|
1266
|
|
|
|
|
|
|
} |
|
1267
|
|
|
|
|
|
|
|
|
1268
|
70
|
|
|
|
|
147
|
my $rdfli = $self->item_class->new(); |
|
1269
|
70
|
|
|
|
|
218
|
$rdfli->{'-rdf:resource'} = $link; |
|
1270
|
70
|
|
50
|
|
|
205
|
$self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'}->{'rdf:li'} ||= []; |
|
1271
|
|
|
|
|
|
|
push( |
|
1272
|
70
|
|
|
|
|
116
|
@{ $self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'}->{'rdf:li'} }, |
|
|
70
|
|
|
|
|
165
|
|
|
1273
|
|
|
|
|
|
|
$rdfli |
|
1274
|
|
|
|
|
|
|
); |
|
1275
|
|
|
|
|
|
|
|
|
1276
|
70
|
|
|
|
|
170
|
my $item = XML::FeedPP::RDF::Item->new(@rest); |
|
1277
|
70
|
100
|
|
|
|
221
|
$item->link($link) if $link; |
|
1278
|
70
|
100
|
|
|
|
166
|
$item->elements(@$init) if ref $init; |
|
1279
|
70
|
|
|
|
|
109
|
push( @{ $self->{'rdf:RDF'}->{item} }, $item ); |
|
|
70
|
|
|
|
|
136
|
|
|
1280
|
|
|
|
|
|
|
|
|
1281
|
70
|
|
|
|
|
163
|
$item; |
|
1282
|
|
|
|
|
|
|
} |
|
1283
|
|
|
|
|
|
|
|
|
1284
|
|
|
|
|
|
|
sub clear_item { |
|
1285
|
1
|
|
|
1
|
|
2104
|
my $self = shift; |
|
1286
|
1
|
|
|
|
|
3
|
$self->{'rdf:RDF'}->{item} = []; |
|
1287
|
1
|
|
|
|
|
4
|
$self->__refresh_items(); |
|
1288
|
|
|
|
|
|
|
} |
|
1289
|
|
|
|
|
|
|
|
|
1290
|
|
|
|
|
|
|
sub remove_item { |
|
1291
|
7
|
|
|
7
|
|
16
|
my $self = shift; |
|
1292
|
7
|
|
|
|
|
8
|
my $remove = shift; |
|
1293
|
7
|
50
|
|
|
|
17
|
my $list = $self->{'rdf:RDF'}->{item} or return; |
|
1294
|
7
|
|
|
|
|
10
|
my @deleted; |
|
1295
|
|
|
|
|
|
|
|
|
1296
|
7
|
100
|
|
|
|
34
|
if ( $remove =~ /^-?\d+/ ) { |
|
1297
|
6
|
|
|
|
|
16
|
@deleted = splice( @$list, $remove, 1 ); |
|
1298
|
|
|
|
|
|
|
} |
|
1299
|
|
|
|
|
|
|
else { |
|
1300
|
1
|
|
|
|
|
2
|
@deleted = grep { $_->link() eq $remove } @$list; |
|
|
3
|
|
|
|
|
5
|
|
|
1301
|
1
|
|
|
|
|
2
|
@$list = grep { $_->link() ne $remove } @$list; |
|
|
3
|
|
|
|
|
5
|
|
|
1302
|
|
|
|
|
|
|
} |
|
1303
|
|
|
|
|
|
|
|
|
1304
|
7
|
|
|
|
|
16
|
$self->__refresh_items(); |
|
1305
|
|
|
|
|
|
|
|
|
1306
|
7
|
50
|
|
|
|
18
|
wantarray ? @deleted : shift @deleted; |
|
1307
|
|
|
|
|
|
|
} |
|
1308
|
|
|
|
|
|
|
|
|
1309
|
|
|
|
|
|
|
sub get_item { |
|
1310
|
101
|
|
|
101
|
|
10569
|
my $self = shift; |
|
1311
|
101
|
|
|
|
|
144
|
my $num = shift; |
|
1312
|
101
|
|
50
|
|
|
318
|
$self->{'rdf:RDF'}->{item} ||= []; |
|
1313
|
101
|
100
|
|
|
|
295
|
if ( defined $num ) { |
|
|
|
100
|
|
|
|
|
|
|
1314
|
36
|
|
|
|
|
97
|
return $self->{'rdf:RDF'}->{item}->[$num]; |
|
1315
|
|
|
|
|
|
|
} |
|
1316
|
|
|
|
|
|
|
elsif (wantarray) { |
|
1317
|
32
|
|
|
|
|
88
|
return @{ $self->{'rdf:RDF'}->{item} }; |
|
|
32
|
|
|
|
|
116
|
|
|
1318
|
|
|
|
|
|
|
} |
|
1319
|
|
|
|
|
|
|
else { |
|
1320
|
33
|
|
|
|
|
40
|
return scalar @{ $self->{'rdf:RDF'}->{item} }; |
|
|
33
|
|
|
|
|
158
|
|
|
1321
|
|
|
|
|
|
|
} |
|
1322
|
|
|
|
|
|
|
} |
|
1323
|
|
|
|
|
|
|
|
|
1324
|
|
|
|
|
|
|
sub sort_item { |
|
1325
|
16
|
|
|
16
|
|
40
|
my $self = shift; |
|
1326
|
16
|
50
|
|
|
|
72
|
my $list = $self->{'rdf:RDF'}->{item} or return; |
|
1327
|
16
|
100
|
|
|
|
41
|
my $epoch = [ map { $_->get_pubDate_epoch() || 0 } @$list ]; |
|
|
42
|
|
|
|
|
124
|
|
|
1328
|
42
|
|
|
|
|
68
|
my $sorted = [ map { $list->[$_] } sort { |
|
1329
|
16
|
|
|
|
|
68
|
$epoch->[$b] <=> $epoch->[$a] |
|
|
50
|
|
|
|
|
68
|
|
|
1330
|
|
|
|
|
|
|
} 0 .. $#$list ]; |
|
1331
|
16
|
|
|
|
|
52
|
@$list = @$sorted; |
|
1332
|
16
|
|
|
|
|
58
|
$self->__refresh_items(); |
|
1333
|
|
|
|
|
|
|
} |
|
1334
|
|
|
|
|
|
|
|
|
1335
|
|
|
|
|
|
|
sub uniq_item { |
|
1336
|
14
|
|
|
14
|
|
24
|
my $self = shift; |
|
1337
|
14
|
50
|
|
|
|
49
|
my $list = $self->{'rdf:RDF'}->{item} or return; |
|
1338
|
14
|
|
|
|
|
38
|
my (%check, @uniq); |
|
1339
|
14
|
|
|
|
|
29
|
foreach my $item (@$list) { |
|
1340
|
32
|
|
|
|
|
60
|
my $link = $item->link(); |
|
1341
|
32
|
100
|
|
|
|
109
|
push( @uniq, $item ) unless $check{$link}++; |
|
1342
|
|
|
|
|
|
|
} |
|
1343
|
14
|
|
|
|
|
46
|
$self->{'rdf:RDF'}->{item} = \@uniq; |
|
1344
|
14
|
|
|
|
|
49
|
$self->__refresh_items(); |
|
1345
|
|
|
|
|
|
|
} |
|
1346
|
|
|
|
|
|
|
|
|
1347
|
|
|
|
|
|
|
sub limit_item { |
|
1348
|
7
|
|
|
7
|
|
16
|
my $self = shift; |
|
1349
|
7
|
|
|
|
|
8
|
my $limit = shift; |
|
1350
|
7
|
50
|
|
|
|
17
|
my $list = $self->{'rdf:RDF'}->{item} or return; |
|
1351
|
7
|
100
|
100
|
|
|
41
|
if ( $limit > 0 && $limit < scalar @$list ) { |
|
|
|
100
|
100
|
|
|
|
|
|
1352
|
3
|
|
|
|
|
14
|
@$list = splice( @$list, 0, $limit ); # remove from end |
|
1353
|
|
|
|
|
|
|
} |
|
1354
|
|
|
|
|
|
|
elsif ( $limit < 0 && -$limit < scalar @$list ) { |
|
1355
|
2
|
|
|
|
|
7
|
@$list = splice( @$list, $limit ); # remove from start |
|
1356
|
|
|
|
|
|
|
} |
|
1357
|
7
|
|
|
|
|
16
|
$self->__refresh_items(); |
|
1358
|
|
|
|
|
|
|
} |
|
1359
|
|
|
|
|
|
|
|
|
1360
|
|
|
|
|
|
|
sub __refresh_items { |
|
1361
|
45
|
|
|
45
|
|
68
|
my $self = shift; |
|
1362
|
45
|
50
|
|
|
|
115
|
my $list = $self->{'rdf:RDF'}->{item} or return; |
|
1363
|
45
|
|
|
|
|
257
|
$self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'}->{'rdf:li'} = []; |
|
1364
|
45
|
|
|
|
|
92
|
my $dest = $self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'}->{'rdf:li'}; |
|
1365
|
45
|
|
|
|
|
83
|
foreach my $item (@$list) { |
|
1366
|
101
|
|
|
|
|
161
|
my $rdfli = XML::FeedPP::Element->new(); |
|
1367
|
101
|
|
|
|
|
144
|
$rdfli->{'-rdf:resource'} = $item->link(); |
|
1368
|
101
|
|
|
|
|
194
|
push( @$dest, $rdfli ); |
|
1369
|
|
|
|
|
|
|
} |
|
1370
|
45
|
|
|
|
|
108
|
scalar @$dest; |
|
1371
|
|
|
|
|
|
|
} |
|
1372
|
|
|
|
|
|
|
|
|
1373
|
204
|
|
|
204
|
|
364
|
sub docroot { shift->{'rdf:RDF'}; } |
|
1374
|
0
|
|
|
0
|
|
0
|
sub channel { shift->{'rdf:RDF'}->{channel}; } |
|
1375
|
3
|
|
|
3
|
|
26
|
sub set { shift->{'rdf:RDF'}->{channel}->set(@_); } |
|
1376
|
49
|
|
|
49
|
|
20041
|
sub get { shift->{'rdf:RDF'}->{channel}->get(@_); } |
|
1377
|
43
|
|
|
43
|
|
1828
|
sub title { shift->{'rdf:RDF'}->{channel}->get_or_set( "title", @_ ); } |
|
1378
|
32
|
|
|
32
|
|
99
|
sub description { shift->{'rdf:RDF'}->{channel}->get_or_set( "description", @_ ); } |
|
1379
|
30
|
|
|
30
|
|
84
|
sub language { shift->{'rdf:RDF'}->{channel}->get_or_set( "dc:language", @_ ); } |
|
1380
|
29
|
|
|
29
|
|
83
|
sub copyright { shift->{'rdf:RDF'}->{channel}->get_or_set( "dc:rights", @_ ); } |
|
1381
|
|
|
|
|
|
|
|
|
1382
|
|
|
|
|
|
|
sub link { |
|
1383
|
45
|
|
|
45
|
|
11811
|
my $self = shift; |
|
1384
|
45
|
|
|
|
|
104
|
my $link = shift; |
|
1385
|
45
|
100
|
|
|
|
156
|
return $self->{'rdf:RDF'}->{channel}->get_value("link") |
|
1386
|
|
|
|
|
|
|
unless defined $link; |
|
1387
|
16
|
|
|
|
|
51
|
$self->{'rdf:RDF'}->{channel}->{'-rdf:about'} = $link; |
|
1388
|
16
|
|
|
|
|
90
|
$self->{'rdf:RDF'}->{channel}->set_value( "link", $link, @_ ); |
|
1389
|
|
|
|
|
|
|
} |
|
1390
|
|
|
|
|
|
|
|
|
1391
|
|
|
|
|
|
|
sub pubDate { |
|
1392
|
48
|
|
|
48
|
|
86
|
my $self = shift; |
|
1393
|
48
|
|
|
|
|
69
|
my $date = shift; |
|
1394
|
48
|
100
|
|
|
|
153
|
return $self->get_pubDate_w3cdtf() unless defined $date; |
|
1395
|
16
|
|
|
|
|
29
|
$date = XML::FeedPP::Util::get_w3cdtf($date); |
|
1396
|
16
|
|
|
|
|
61
|
$self->{'rdf:RDF'}->{channel}->set_value( "dc:date", $date ); |
|
1397
|
|
|
|
|
|
|
} |
|
1398
|
|
|
|
|
|
|
|
|
1399
|
|
|
|
|
|
|
sub get_pubDate_native { |
|
1400
|
52
|
|
|
52
|
|
140
|
shift->{'rdf:RDF'}->{channel}->get_value("dc:date"); |
|
1401
|
|
|
|
|
|
|
} |
|
1402
|
|
|
|
|
|
|
|
|
1403
|
|
|
|
|
|
|
*get_pubDate_w3cdtf = \&get_pubDate_native; |
|
1404
|
|
|
|
|
|
|
|
|
1405
|
|
|
|
|
|
|
sub image { |
|
1406
|
25
|
|
|
25
|
|
37
|
my $self = shift; |
|
1407
|
25
|
|
|
|
|
37
|
my $url = shift; |
|
1408
|
25
|
100
|
|
|
|
131
|
if ( defined $url ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1409
|
2
|
|
|
|
|
5
|
my ( $title, $link ) = @_; |
|
1410
|
2
|
|
50
|
|
|
16
|
$self->{'rdf:RDF'}->{channel}->{image} ||= {}; |
|
1411
|
2
|
|
|
|
|
6
|
$self->{'rdf:RDF'}->{channel}->{image}->{'-rdf:resource'} = $url; |
|
1412
|
2
|
|
50
|
|
|
16
|
$self->{'rdf:RDF'}->{image} ||= {}; |
|
1413
|
2
|
|
|
|
|
4
|
$self->{'rdf:RDF'}->{image}->{'-rdf:about'} = $url; # fix |
|
1414
|
2
|
|
|
|
|
3
|
my $image = $self->{'rdf:RDF'}->{image}; |
|
1415
|
2
|
|
|
|
|
8
|
$image->{url} = $url; |
|
1416
|
2
|
100
|
|
|
|
6
|
$image->{title} = $title if defined $title; |
|
1417
|
2
|
100
|
|
|
|
6
|
$image->{link} = $link if defined $link; |
|
1418
|
|
|
|
|
|
|
} |
|
1419
|
|
|
|
|
|
|
elsif ( exists $self->{'rdf:RDF'}->{image} ) { |
|
1420
|
3
|
|
|
|
|
7
|
my $image = $self->{'rdf:RDF'}->{image}; |
|
1421
|
3
|
|
|
|
|
6
|
my $array = []; |
|
1422
|
3
|
|
|
|
|
7
|
foreach my $key (qw( url title link )) { |
|
1423
|
9
|
100
|
|
|
|
39
|
push( @$array, exists $image->{$key} ? $image->{$key} : undef ); |
|
1424
|
|
|
|
|
|
|
} |
|
1425
|
3
|
100
|
|
|
|
31
|
return wantarray ? @$array : shift @$array; |
|
1426
|
|
|
|
|
|
|
} |
|
1427
|
|
|
|
|
|
|
elsif ( exists $self->{'rdf:RDF'}->{channel}->{image} ) { |
|
1428
|
0
|
|
|
|
|
0
|
return $self->{'rdf:RDF'}->{channel}->{image}->{'-rdf:resource'}; |
|
1429
|
|
|
|
|
|
|
} |
|
1430
|
22
|
|
|
|
|
52
|
undef; |
|
1431
|
|
|
|
|
|
|
} |
|
1432
|
|
|
|
|
|
|
|
|
1433
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1434
|
|
|
|
|
|
|
package XML::FeedPP::RDF::Channel; |
|
1435
|
44
|
|
|
44
|
|
308
|
use strict; |
|
|
44
|
|
|
|
|
102
|
|
|
|
44
|
|
|
|
|
1407
|
|
|
1436
|
44
|
|
|
44
|
|
229
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
88
|
|
|
|
44
|
|
|
|
|
2332
|
|
|
1437
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Element ); |
|
1438
|
|
|
|
|
|
|
|
|
1439
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1440
|
|
|
|
|
|
|
package XML::FeedPP::RDF::Item; |
|
1441
|
44
|
|
|
44
|
|
248
|
use strict; |
|
|
44
|
|
|
|
|
79
|
|
|
|
44
|
|
|
|
|
1146
|
|
|
1442
|
44
|
|
|
44
|
|
233
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
68
|
|
|
|
44
|
|
|
|
|
11486
|
|
|
1443
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Item ); |
|
1444
|
|
|
|
|
|
|
|
|
1445
|
56
|
|
|
56
|
|
173
|
sub title { shift->get_or_set( "title", @_ ); } |
|
1446
|
29
|
|
|
29
|
|
86
|
sub description { shift->get_or_set( "description", @_ ); } |
|
1447
|
54
|
|
|
54
|
|
6132
|
sub category { shift->get_set_array( "dc:subject", @_ ); } |
|
1448
|
43
|
|
|
43
|
|
57
|
sub guid { undef; } # this element is NOT supported for RDF |
|
1449
|
|
|
|
|
|
|
|
|
1450
|
|
|
|
|
|
|
sub author { |
|
1451
|
26
|
|
|
26
|
|
60
|
my $self = shift; |
|
1452
|
26
|
|
|
|
|
47
|
my $author = shift; |
|
1453
|
26
|
100
|
66
|
|
|
93
|
return $self->get_value('dc:creator') |
|
1454
|
|
|
|
|
|
|
|| $self->get_value('creator') unless defined $author; |
|
1455
|
5
|
|
|
|
|
12
|
$self->set_value( 'dc:creator' => $author ); |
|
1456
|
|
|
|
|
|
|
} |
|
1457
|
|
|
|
|
|
|
|
|
1458
|
|
|
|
|
|
|
sub link { |
|
1459
|
273
|
|
|
273
|
|
6134
|
my $self = shift; |
|
1460
|
273
|
|
|
|
|
305
|
my $link = shift; |
|
1461
|
273
|
100
|
|
|
|
548
|
return $self->get_value("link") unless defined $link; |
|
1462
|
73
|
|
|
|
|
148
|
$self->{'-rdf:about'} = $link; |
|
1463
|
73
|
|
|
|
|
217
|
$self->set_value( "link", $link, @_ ); |
|
1464
|
|
|
|
|
|
|
} |
|
1465
|
|
|
|
|
|
|
|
|
1466
|
|
|
|
|
|
|
sub pubDate { |
|
1467
|
95
|
|
|
95
|
|
205
|
my $self = shift; |
|
1468
|
95
|
|
|
|
|
108
|
my $date = shift; |
|
1469
|
95
|
100
|
|
|
|
218
|
return $self->get_pubDate_w3cdtf() unless defined $date; |
|
1470
|
58
|
|
|
|
|
93
|
$date = XML::FeedPP::Util::get_w3cdtf($date); |
|
1471
|
58
|
|
|
|
|
118
|
$self->set_value( "dc:date", $date ); |
|
1472
|
|
|
|
|
|
|
} |
|
1473
|
|
|
|
|
|
|
|
|
1474
|
|
|
|
|
|
|
sub get_pubDate_native { |
|
1475
|
124
|
|
|
124
|
|
261
|
shift->get_value("dc:date"); |
|
1476
|
|
|
|
|
|
|
} |
|
1477
|
|
|
|
|
|
|
|
|
1478
|
|
|
|
|
|
|
*get_pubDate_w3cdtf = \&get_pubDate_native; |
|
1479
|
|
|
|
|
|
|
|
|
1480
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1481
|
|
|
|
|
|
|
package XML::FeedPP::Atom::Common; |
|
1482
|
44
|
|
|
44
|
|
259
|
use strict; |
|
|
44
|
|
|
|
|
74
|
|
|
|
44
|
|
|
|
|
1232
|
|
|
1483
|
44
|
|
|
44
|
|
205
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
400
|
|
|
|
44
|
|
|
|
|
44532
|
|
|
1484
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP ); |
|
1485
|
|
|
|
|
|
|
|
|
1486
|
|
|
|
|
|
|
sub merge_native_channel { |
|
1487
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
1488
|
0
|
0
|
|
|
|
0
|
my $tree = shift or next; |
|
1489
|
|
|
|
|
|
|
|
|
1490
|
0
|
|
|
|
|
0
|
XML::FeedPP::Util::merge_hash( $self->{feed}, $tree->{feed}, qw( entry ) ); |
|
1491
|
|
|
|
|
|
|
} |
|
1492
|
|
|
|
|
|
|
|
|
1493
|
|
|
|
|
|
|
sub add_item { |
|
1494
|
80
|
|
|
80
|
|
2697
|
my $self = shift; |
|
1495
|
80
|
|
|
|
|
157
|
my( $init, $link, @rest ) = &XML::FeedPP::Util::param_even_odd(@_); |
|
1496
|
|
|
|
|
|
|
|
|
1497
|
80
|
50
|
66
|
|
|
326
|
Carp::croak "add_item needs an argument" if ( ! ref $init && ! $link ); |
|
1498
|
80
|
100
|
|
|
|
154
|
if ( ref $link ) { |
|
1499
|
14
|
|
|
|
|
52
|
return $self->add_clone_item( $link ); |
|
1500
|
|
|
|
|
|
|
} |
|
1501
|
|
|
|
|
|
|
|
|
1502
|
66
|
|
|
|
|
165
|
my $item = $self->item_class->new(@rest); |
|
1503
|
66
|
100
|
|
|
|
204
|
$item->link($link) if $link; |
|
1504
|
66
|
100
|
|
|
|
164
|
$item->elements(@$init) if ref $init; |
|
1505
|
66
|
|
|
|
|
92
|
push( @{ $self->{feed}->{entry} }, $item ); |
|
|
66
|
|
|
|
|
167
|
|
|
1506
|
|
|
|
|
|
|
|
|
1507
|
66
|
|
|
|
|
159
|
$item; |
|
1508
|
|
|
|
|
|
|
} |
|
1509
|
|
|
|
|
|
|
|
|
1510
|
|
|
|
|
|
|
sub clear_item { |
|
1511
|
1
|
|
|
1
|
|
2309
|
my $self = shift; |
|
1512
|
1
|
|
|
|
|
3
|
$self->{feed}->{entry} = []; |
|
1513
|
|
|
|
|
|
|
} |
|
1514
|
|
|
|
|
|
|
|
|
1515
|
|
|
|
|
|
|
sub remove_item { |
|
1516
|
7
|
|
|
7
|
|
17
|
my $self = shift; |
|
1517
|
7
|
|
|
|
|
43
|
my $remove = shift; |
|
1518
|
7
|
50
|
|
|
|
23
|
my $list = $self->{feed}->{entry} or return; |
|
1519
|
7
|
|
|
|
|
35
|
my @deleted; |
|
1520
|
|
|
|
|
|
|
|
|
1521
|
7
|
100
|
|
|
|
38
|
if ( $remove =~ /^-?\d+/ ) { |
|
1522
|
6
|
|
|
|
|
20
|
@deleted = splice( @$list, $remove, 1 ); |
|
1523
|
|
|
|
|
|
|
} |
|
1524
|
|
|
|
|
|
|
else { |
|
1525
|
1
|
|
|
|
|
5
|
@deleted = grep { $_->link() eq $remove } @$list; |
|
|
3
|
|
|
|
|
10
|
|
|
1526
|
1
|
|
|
|
|
4
|
@$list = grep { $_->link() ne $remove } @$list; |
|
|
3
|
|
|
|
|
11
|
|
|
1527
|
|
|
|
|
|
|
} |
|
1528
|
|
|
|
|
|
|
|
|
1529
|
7
|
50
|
|
|
|
26
|
wantarray ? @deleted : shift @deleted; |
|
1530
|
|
|
|
|
|
|
} |
|
1531
|
|
|
|
|
|
|
|
|
1532
|
|
|
|
|
|
|
sub get_item { |
|
1533
|
104
|
|
|
104
|
|
21070
|
my $self = shift; |
|
1534
|
104
|
|
|
|
|
134
|
my $num = shift; |
|
1535
|
104
|
|
50
|
|
|
270
|
$self->{feed}->{entry} ||= []; |
|
1536
|
104
|
100
|
|
|
|
265
|
if ( defined $num ) { |
|
|
|
100
|
|
|
|
|
|
|
1537
|
35
|
|
|
|
|
94
|
return $self->{feed}->{entry}->[$num]; |
|
1538
|
|
|
|
|
|
|
} |
|
1539
|
|
|
|
|
|
|
elsif (wantarray) { |
|
1540
|
29
|
|
|
|
|
42
|
return @{ $self->{feed}->{entry} }; |
|
|
29
|
|
|
|
|
90
|
|
|
1541
|
|
|
|
|
|
|
} |
|
1542
|
|
|
|
|
|
|
else { |
|
1543
|
40
|
|
|
|
|
52
|
return scalar @{ $self->{feed}->{entry} }; |
|
|
40
|
|
|
|
|
188
|
|
|
1544
|
|
|
|
|
|
|
} |
|
1545
|
|
|
|
|
|
|
} |
|
1546
|
|
|
|
|
|
|
|
|
1547
|
|
|
|
|
|
|
sub sort_item { |
|
1548
|
12
|
|
|
12
|
|
28
|
my $self = shift; |
|
1549
|
12
|
50
|
|
|
|
62
|
my $list = $self->{feed}->{entry} or return; |
|
1550
|
12
|
100
|
|
|
|
61
|
my $epoch = [ map { $_->get_pubDate_epoch() || 0 } @$list ]; |
|
|
28
|
|
|
|
|
78
|
|
|
1551
|
28
|
|
|
|
|
54
|
my $sorted = [ map { $list->[$_] } sort { |
|
1552
|
12
|
|
|
|
|
70
|
$epoch->[$b] <=> $epoch->[$a] |
|
|
35
|
|
|
|
|
49
|
|
|
1553
|
|
|
|
|
|
|
} 0 .. $#$list ]; |
|
1554
|
12
|
|
|
|
|
40
|
@$list = @$sorted; |
|
1555
|
12
|
|
|
|
|
44
|
scalar @$list; |
|
1556
|
|
|
|
|
|
|
} |
|
1557
|
|
|
|
|
|
|
|
|
1558
|
|
|
|
|
|
|
sub uniq_item { |
|
1559
|
10
|
|
|
10
|
|
21
|
my $self = shift; |
|
1560
|
10
|
50
|
|
|
|
33
|
my $list = $self->{feed}->{entry} or return; |
|
1561
|
10
|
|
|
|
|
17
|
my (%check, @uniq); |
|
1562
|
10
|
|
|
|
|
26
|
foreach my $item (@$list) { |
|
1563
|
18
|
|
|
|
|
34
|
my $link = $item->guid(); |
|
1564
|
18
|
100
|
|
|
|
73
|
push( @uniq, $item ) unless $check{$link}++; |
|
1565
|
|
|
|
|
|
|
} |
|
1566
|
10
|
|
|
|
|
52
|
@$list = @uniq; |
|
1567
|
|
|
|
|
|
|
} |
|
1568
|
|
|
|
|
|
|
|
|
1569
|
|
|
|
|
|
|
sub limit_item { |
|
1570
|
7
|
|
|
7
|
|
15
|
my $self = shift; |
|
1571
|
7
|
|
|
|
|
9
|
my $limit = shift; |
|
1572
|
7
|
50
|
|
|
|
73
|
my $list = $self->{feed}->{entry} or return; |
|
1573
|
7
|
100
|
100
|
|
|
39
|
if ( $limit > 0 && $limit < scalar @$list ) { |
|
|
|
100
|
100
|
|
|
|
|
|
1574
|
3
|
|
|
|
|
43
|
@$list = splice( @$list, 0, $limit ); # remove from end |
|
1575
|
|
|
|
|
|
|
} |
|
1576
|
|
|
|
|
|
|
elsif ( $limit < 0 && -$limit < scalar @$list ) { |
|
1577
|
2
|
|
|
|
|
6
|
@$list = splice( @$list, $limit ); # remove from start |
|
1578
|
|
|
|
|
|
|
} |
|
1579
|
7
|
|
|
|
|
17
|
scalar @$list; |
|
1580
|
|
|
|
|
|
|
} |
|
1581
|
|
|
|
|
|
|
|
|
1582
|
98
|
|
|
98
|
|
191
|
sub docroot { shift->{feed}; } |
|
1583
|
0
|
|
|
0
|
|
0
|
sub channel { shift->{feed}; } |
|
1584
|
1
|
|
|
1
|
|
4
|
sub set { shift->{feed}->set(@_); } |
|
1585
|
1
|
|
|
1
|
|
6
|
sub get { shift->{feed}->get(@_); } |
|
1586
|
|
|
|
|
|
|
|
|
1587
|
|
|
|
|
|
|
sub language { |
|
1588
|
29
|
|
|
29
|
|
56
|
my $self = shift; |
|
1589
|
29
|
|
|
|
|
40
|
my $lang = shift; |
|
1590
|
29
|
100
|
|
|
|
89
|
return $self->{feed}->{'-xml:lang'} unless defined $lang; |
|
1591
|
8
|
|
|
|
|
20
|
$self->{feed}->{'-xml:lang'} = $lang; |
|
1592
|
|
|
|
|
|
|
} |
|
1593
|
|
|
|
|
|
|
|
|
1594
|
|
|
|
|
|
|
sub image { |
|
1595
|
27
|
|
|
27
|
|
79
|
my $self = shift; |
|
1596
|
27
|
|
|
|
|
39
|
my $href = shift; |
|
1597
|
27
|
|
|
|
|
35
|
my $title = shift; |
|
1598
|
|
|
|
|
|
|
|
|
1599
|
27
|
|
100
|
|
|
88
|
my $link = $self->{feed}->{link} || []; |
|
1600
|
27
|
100
|
|
|
|
76
|
$link = [$link] if UNIVERSAL::isa( $link, 'HASH' ); |
|
1601
|
|
|
|
|
|
|
my $icon = ( |
|
1602
|
|
|
|
|
|
|
grep { |
|
1603
|
27
|
|
|
|
|
53
|
ref $_ |
|
1604
|
|
|
|
|
|
|
&& exists $_->{'-rel'} |
|
1605
|
30
|
50
|
33
|
|
|
168
|
&& ($_->{'-rel'} eq "icon" ) |
|
1606
|
|
|
|
|
|
|
} @$link |
|
1607
|
|
|
|
|
|
|
)[0]; |
|
1608
|
|
|
|
|
|
|
|
|
1609
|
27
|
|
|
|
|
110
|
my $rext = join( "|", map {"\Q$_\E"} keys %$XML::FeedPP::MIME_TYPES ); |
|
|
243
|
|
|
|
|
358
|
|
|
1610
|
|
|
|
|
|
|
|
|
1611
|
27
|
100
|
|
|
|
115
|
if ( defined $href ) { |
|
|
|
100
|
|
|
|
|
|
|
1612
|
6
|
|
|
|
|
676
|
my $ext = ( $href =~ m#[^/]\.($rext)(\W|$)#i )[0]; |
|
1613
|
6
|
50
|
|
|
|
23
|
my $type = $XML::FeedPP::MIME_TYPES->{$ext} if $ext; |
|
1614
|
|
|
|
|
|
|
|
|
1615
|
6
|
100
|
|
|
|
15
|
if ( ref $icon ) { |
|
1616
|
1
|
|
|
|
|
2
|
$icon->{'-href'} = $href; |
|
1617
|
1
|
50
|
|
|
|
3
|
$icon->{'-type'} = $type if $type; |
|
1618
|
1
|
50
|
|
|
|
3
|
$icon->{'-title'} = $title if $title; |
|
1619
|
|
|
|
|
|
|
} |
|
1620
|
|
|
|
|
|
|
else { |
|
1621
|
5
|
|
|
|
|
9
|
my $newicon = {}; |
|
1622
|
5
|
|
|
|
|
10
|
$newicon->{'-rel'} = 'icon'; |
|
1623
|
5
|
|
|
|
|
9
|
$newicon->{'-href'} = $href; |
|
1624
|
5
|
50
|
|
|
|
13
|
$newicon->{'-type'} = $type if $type; |
|
1625
|
5
|
50
|
|
|
|
11
|
$newicon->{'-title'} = $title if $title; |
|
1626
|
5
|
|
|
|
|
8
|
my $flink = $self->{feed}->{link}; |
|
1627
|
5
|
50
|
|
|
|
26
|
if ( UNIVERSAL::isa( $flink, 'ARRAY' )) { |
|
|
|
0
|
|
|
|
|
|
|
1628
|
5
|
|
|
|
|
12
|
push( @$flink, $newicon ); |
|
1629
|
|
|
|
|
|
|
} |
|
1630
|
|
|
|
|
|
|
elsif ( UNIVERSAL::isa( $flink, 'HASH' )) { |
|
1631
|
0
|
|
|
|
|
0
|
$self->{feed}->{link} = [ $flink, $newicon ]; |
|
1632
|
|
|
|
|
|
|
} |
|
1633
|
|
|
|
|
|
|
else { |
|
1634
|
0
|
|
|
|
|
0
|
$self->{feed}->{link} = [ $newicon ]; |
|
1635
|
|
|
|
|
|
|
} |
|
1636
|
|
|
|
|
|
|
} |
|
1637
|
|
|
|
|
|
|
} |
|
1638
|
|
|
|
|
|
|
elsif ( ref $icon ) { |
|
1639
|
8
|
|
|
|
|
18
|
my $array = [ $icon->{'-href'} ]; |
|
1640
|
8
|
50
|
|
|
|
15
|
push( @$array, $icon->{'-title'} ) if exists $icon->{'-title'}; |
|
1641
|
8
|
100
|
|
|
|
36
|
return wantarray ? @$array : shift @$array; |
|
1642
|
|
|
|
|
|
|
} |
|
1643
|
19
|
|
|
|
|
342
|
undef; |
|
1644
|
|
|
|
|
|
|
} |
|
1645
|
|
|
|
|
|
|
|
|
1646
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1647
|
|
|
|
|
|
|
package XML::FeedPP::Atom::Atom03; |
|
1648
|
44
|
|
|
44
|
|
365
|
use strict; |
|
|
44
|
|
|
|
|
82
|
|
|
|
44
|
|
|
|
|
1118
|
|
|
1649
|
44
|
|
|
44
|
|
189
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
67
|
|
|
|
44
|
|
|
|
|
32904
|
|
|
1650
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Atom::Common ); |
|
1651
|
|
|
|
|
|
|
|
|
1652
|
|
|
|
|
|
|
sub channel_class { |
|
1653
|
66
|
|
|
66
|
|
368
|
'XML::FeedPP::Atom::Atom03::Feed'; |
|
1654
|
|
|
|
|
|
|
} |
|
1655
|
|
|
|
|
|
|
|
|
1656
|
|
|
|
|
|
|
sub item_class { |
|
1657
|
69
|
|
|
69
|
|
321
|
'XML::FeedPP::Atom::Atom03::Entry'; |
|
1658
|
|
|
|
|
|
|
} |
|
1659
|
|
|
|
|
|
|
|
|
1660
|
|
|
|
|
|
|
sub test_feed { |
|
1661
|
29
|
|
|
29
|
|
46
|
my $self = shift; |
|
1662
|
29
|
|
66
|
|
|
100
|
my $source = shift || $self; |
|
1663
|
29
|
50
|
|
|
|
60
|
return unless ref $source; |
|
1664
|
29
|
100
|
|
|
|
60
|
return unless ref $source->{feed}; |
|
1665
|
28
|
50
|
|
|
|
97
|
return unless exists $source->{feed}->{-xmlns}; |
|
1666
|
28
|
|
|
|
|
41
|
my $xmlns = $source->{feed}->{-xmlns}; |
|
1667
|
28
|
100
|
|
|
|
102
|
return if ($xmlns ne $XML::FeedPP::XMLNS_ATOM03); |
|
1668
|
27
|
|
|
|
|
77
|
__PACKAGE__; |
|
1669
|
|
|
|
|
|
|
} |
|
1670
|
|
|
|
|
|
|
|
|
1671
|
|
|
|
|
|
|
sub init_feed { |
|
1672
|
41
|
50
|
|
41
|
|
172
|
my $self = shift or return; |
|
1673
|
|
|
|
|
|
|
|
|
1674
|
41
|
|
66
|
|
|
239
|
$self->{feed} ||= $self->channel_class->new(); |
|
1675
|
41
|
|
|
|
|
110
|
$self->channel_class->ref_bless( $self->{feed} ); |
|
1676
|
|
|
|
|
|
|
|
|
1677
|
41
|
50
|
|
|
|
139
|
if ( ! UNIVERSAL::isa( $self->{feed}, 'HASH' ) ) { |
|
1678
|
0
|
|
|
|
|
0
|
Carp::croak "Invalid Atom 0.3 feed format: $self->{feed}"; |
|
1679
|
|
|
|
|
|
|
} |
|
1680
|
|
|
|
|
|
|
|
|
1681
|
41
|
|
|
|
|
195
|
$self->xmlns( 'xmlns' => $XML::FeedPP::XMLNS_ATOM03 ); |
|
1682
|
41
|
|
66
|
|
|
171
|
$self->{feed}->{'-version'} ||= $XML::FeedPP::ATOM03_VERSION; |
|
1683
|
|
|
|
|
|
|
|
|
1684
|
41
|
|
100
|
|
|
153
|
$self->{feed}->{entry} ||= []; |
|
1685
|
41
|
50
|
|
|
|
140
|
if ( UNIVERSAL::isa( $self->{feed}->{entry}, 'HASH' ) ) { |
|
1686
|
|
|
|
|
|
|
# if this feed has only one item |
|
1687
|
0
|
|
|
|
|
0
|
$self->{feed}->{entry} = [ $self->{feed}->{entry} ]; |
|
1688
|
|
|
|
|
|
|
} |
|
1689
|
41
|
|
|
|
|
85
|
foreach my $item ( @{ $self->{feed}->{entry} } ) { |
|
|
41
|
|
|
|
|
118
|
|
|
1690
|
16
|
|
|
|
|
38
|
$self->item_class->ref_bless($item); |
|
1691
|
|
|
|
|
|
|
} |
|
1692
|
41
|
|
100
|
|
|
210
|
$self->{feed}->{author} ||= { name => '' }; # dummy for validation |
|
1693
|
41
|
|
|
|
|
58
|
$self; |
|
1694
|
|
|
|
|
|
|
} |
|
1695
|
|
|
|
|
|
|
|
|
1696
|
|
|
|
|
|
|
sub title { |
|
1697
|
37
|
|
|
37
|
|
2977
|
my $self = shift; |
|
1698
|
37
|
|
|
|
|
65
|
my $title = shift; |
|
1699
|
37
|
100
|
|
|
|
131
|
return $self->{feed}->get_value('title') unless defined $title; |
|
1700
|
13
|
|
|
|
|
68
|
$self->{feed}->set_value( 'title' => $title, type => 'text/plain' ); |
|
1701
|
|
|
|
|
|
|
} |
|
1702
|
|
|
|
|
|
|
|
|
1703
|
|
|
|
|
|
|
sub description { |
|
1704
|
26
|
|
|
26
|
|
48
|
my $self = shift; |
|
1705
|
26
|
|
|
|
|
34
|
my $desc = shift; |
|
1706
|
|
|
|
|
|
|
return $self->{feed}->get_value('tagline') |
|
1707
|
26
|
100
|
66
|
|
|
79
|
|| $self->{feed}->get_value('subtitle') unless defined $desc; |
|
1708
|
7
|
|
|
|
|
18
|
$self->{feed}->set_value( 'tagline' => $desc, type => 'text/html', mode => 'escaped' ); |
|
1709
|
|
|
|
|
|
|
} |
|
1710
|
|
|
|
|
|
|
|
|
1711
|
|
|
|
|
|
|
sub pubDate { |
|
1712
|
37
|
|
|
37
|
|
75
|
my $self = shift; |
|
1713
|
37
|
|
|
|
|
61
|
my $date = shift; |
|
1714
|
37
|
100
|
|
|
|
112
|
return $self->get_pubDate_w3cdtf() unless defined $date; |
|
1715
|
14
|
|
|
|
|
44
|
$date = XML::FeedPP::Util::get_w3cdtf($date); |
|
1716
|
14
|
|
|
|
|
52
|
$self->{feed}->set_value( 'modified', $date ); |
|
1717
|
|
|
|
|
|
|
} |
|
1718
|
|
|
|
|
|
|
|
|
1719
|
|
|
|
|
|
|
sub get_pubDate_native { |
|
1720
|
37
|
|
|
37
|
|
53
|
my $self = shift; |
|
1721
|
|
|
|
|
|
|
$self->{feed}->get_value('modified') # Atom 0.3 |
|
1722
|
37
|
100
|
|
|
|
105
|
|| $self->{feed}->get_value('updated'); # Atom 1.0 |
|
1723
|
|
|
|
|
|
|
} |
|
1724
|
|
|
|
|
|
|
|
|
1725
|
|
|
|
|
|
|
*get_pubDate_w3cdtf = \&get_pubDate_native; |
|
1726
|
|
|
|
|
|
|
|
|
1727
|
|
|
|
|
|
|
sub copyright { |
|
1728
|
22
|
|
|
22
|
|
41
|
my $self = shift; |
|
1729
|
22
|
|
|
|
|
28
|
my $copy = shift; |
|
1730
|
|
|
|
|
|
|
return $self->{feed}->get_value('copyright') |
|
1731
|
22
|
100
|
66
|
|
|
55
|
|| $self->{feed}->get_value('rights') unless defined $copy; |
|
1732
|
6
|
|
|
|
|
22
|
$self->{feed}->set_value( 'copyright' => $copy ); |
|
1733
|
|
|
|
|
|
|
} |
|
1734
|
|
|
|
|
|
|
|
|
1735
|
|
|
|
|
|
|
sub link { |
|
1736
|
45
|
|
|
45
|
|
5134
|
my $self = shift; |
|
1737
|
45
|
|
|
|
|
66
|
my $href = shift; |
|
1738
|
|
|
|
|
|
|
|
|
1739
|
45
|
|
100
|
|
|
176
|
my $link = $self->{feed}->{link} || []; |
|
1740
|
45
|
100
|
|
|
|
140
|
$link = [$link] if UNIVERSAL::isa( $link, 'HASH' ); |
|
1741
|
45
|
|
|
|
|
97
|
$link = [ grep { ref $_ } @$link ]; |
|
|
29
|
|
|
|
|
84
|
|
|
1742
|
|
|
|
|
|
|
$link = [ grep { |
|
1743
|
45
|
50
|
|
|
|
93
|
! exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate' |
|
|
29
|
|
|
|
|
144
|
|
|
1744
|
|
|
|
|
|
|
} @$link ]; |
|
1745
|
|
|
|
|
|
|
$link = [ grep { |
|
1746
|
45
|
100
|
|
|
|
79
|
! exists $_->{'-type'} || $_->{'-type'} =~ m#^text/(x-)?html#i |
|
|
21
|
|
|
|
|
154
|
|
|
1747
|
|
|
|
|
|
|
} @$link ]; |
|
1748
|
45
|
|
|
|
|
81
|
my $html = shift @$link; |
|
1749
|
|
|
|
|
|
|
|
|
1750
|
45
|
100
|
|
|
|
128
|
if ( defined $href ) { |
|
|
|
100
|
|
|
|
|
|
|
1751
|
18
|
100
|
|
|
|
43
|
if ( ref $html ) { |
|
1752
|
2
|
|
|
|
|
3
|
$html->{'-href'} = $href; |
|
1753
|
|
|
|
|
|
|
} |
|
1754
|
|
|
|
|
|
|
else { |
|
1755
|
16
|
|
|
|
|
54
|
my $hash = { |
|
1756
|
|
|
|
|
|
|
-rel => 'alternate', |
|
1757
|
|
|
|
|
|
|
-type => 'text/html', |
|
1758
|
|
|
|
|
|
|
-href => $href, |
|
1759
|
|
|
|
|
|
|
}; |
|
1760
|
16
|
|
|
|
|
35
|
my $flink = $self->{feed}->{link}; |
|
1761
|
16
|
50
|
|
|
|
46
|
if ( ! ref $flink ) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
1762
|
16
|
|
|
|
|
45
|
$self->{feed}->{link} = [ $hash ]; |
|
1763
|
|
|
|
|
|
|
} |
|
1764
|
|
|
|
|
|
|
elsif ( UNIVERSAL::isa( $flink, 'ARRAY' )) { |
|
1765
|
0
|
|
|
|
|
0
|
push( @$flink, $hash ); |
|
1766
|
|
|
|
|
|
|
} |
|
1767
|
|
|
|
|
|
|
elsif ( UNIVERSAL::isa( $flink, 'HASH' )) { |
|
1768
|
0
|
|
|
|
|
0
|
$self->{feed}->{link} = [ $flink, $hash ]; |
|
1769
|
|
|
|
|
|
|
} |
|
1770
|
|
|
|
|
|
|
} |
|
1771
|
|
|
|
|
|
|
} |
|
1772
|
|
|
|
|
|
|
elsif ( ref $html ) { |
|
1773
|
19
|
|
|
|
|
84
|
return $html->{'-href'}; |
|
1774
|
|
|
|
|
|
|
} |
|
1775
|
26
|
|
|
|
|
54
|
return; |
|
1776
|
|
|
|
|
|
|
} |
|
1777
|
|
|
|
|
|
|
|
|
1778
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1779
|
|
|
|
|
|
|
package XML::FeedPP::Atom::Atom10; |
|
1780
|
44
|
|
|
44
|
|
301
|
use strict; |
|
|
44
|
|
|
|
|
81
|
|
|
|
44
|
|
|
|
|
1024
|
|
|
1781
|
44
|
|
|
44
|
|
199
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
72
|
|
|
|
44
|
|
|
|
|
30113
|
|
|
1782
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Atom::Common ); |
|
1783
|
|
|
|
|
|
|
|
|
1784
|
|
|
|
|
|
|
sub channel_class { |
|
1785
|
24
|
|
|
24
|
|
150
|
'XML::FeedPP::Atom::Atom10::Feed'; |
|
1786
|
|
|
|
|
|
|
} |
|
1787
|
|
|
|
|
|
|
|
|
1788
|
|
|
|
|
|
|
sub item_class { |
|
1789
|
28
|
|
|
28
|
|
140
|
'XML::FeedPP::Atom::Atom10::Entry'; |
|
1790
|
|
|
|
|
|
|
} |
|
1791
|
|
|
|
|
|
|
|
|
1792
|
|
|
|
|
|
|
sub test_feed { |
|
1793
|
34
|
|
|
34
|
|
58
|
my $self = shift; |
|
1794
|
34
|
|
66
|
|
|
103
|
my $source = shift || $self; |
|
1795
|
34
|
50
|
|
|
|
75
|
return unless ref $source; |
|
1796
|
34
|
100
|
|
|
|
77
|
return unless ref $source->{feed}; |
|
1797
|
33
|
50
|
|
|
|
77
|
return unless exists $source->{feed}->{-xmlns}; |
|
1798
|
33
|
|
|
|
|
50
|
my $xmlns = $source->{feed}->{-xmlns}; |
|
1799
|
33
|
100
|
|
|
|
83
|
return if ($xmlns ne $XML::FeedPP::XMLNS_ATOM10); |
|
1800
|
19
|
|
|
|
|
40
|
__PACKAGE__; |
|
1801
|
|
|
|
|
|
|
} |
|
1802
|
|
|
|
|
|
|
|
|
1803
|
|
|
|
|
|
|
sub init_feed { |
|
1804
|
17
|
50
|
|
17
|
|
75
|
my $self = shift or return; |
|
1805
|
|
|
|
|
|
|
|
|
1806
|
17
|
|
66
|
|
|
84
|
$self->{feed} ||= $self->channel_class->new(); |
|
1807
|
17
|
|
|
|
|
78
|
$self->channel_class->ref_bless( $self->{feed} ); |
|
1808
|
|
|
|
|
|
|
|
|
1809
|
17
|
50
|
|
|
|
67
|
if ( ! UNIVERSAL::isa( $self->{feed}, 'HASH' ) ) { |
|
1810
|
0
|
|
|
|
|
0
|
Carp::croak "Invalid Atom 1.0 feed format: $self->{feed}"; |
|
1811
|
|
|
|
|
|
|
} |
|
1812
|
|
|
|
|
|
|
|
|
1813
|
17
|
|
|
|
|
107
|
$self->xmlns( 'xmlns' => $XML::FeedPP::XMLNS_ATOM10 ); |
|
1814
|
|
|
|
|
|
|
# $self->{feed}->{'-version'} ||= $XML::FeedPP::ATOM10_VERSION; |
|
1815
|
|
|
|
|
|
|
|
|
1816
|
17
|
|
100
|
|
|
76
|
$self->{feed}->{entry} ||= []; |
|
1817
|
17
|
50
|
|
|
|
68
|
if ( UNIVERSAL::isa( $self->{feed}->{entry}, 'HASH' ) ) { |
|
1818
|
|
|
|
|
|
|
# if this feed has only one item |
|
1819
|
0
|
|
|
|
|
0
|
$self->{feed}->{entry} = [ $self->{feed}->{entry} ]; |
|
1820
|
|
|
|
|
|
|
} |
|
1821
|
17
|
|
|
|
|
31
|
foreach my $item ( @{ $self->{feed}->{entry} } ) { |
|
|
17
|
|
|
|
|
45
|
|
|
1822
|
15
|
|
|
|
|
29
|
$self->item_class->ref_bless($item); |
|
1823
|
|
|
|
|
|
|
} |
|
1824
|
|
|
|
|
|
|
# $self->{feed}->{author} ||= { name => '' }; # dummy for validation |
|
1825
|
17
|
|
|
|
|
27
|
$self; |
|
1826
|
|
|
|
|
|
|
} |
|
1827
|
|
|
|
|
|
|
|
|
1828
|
|
|
|
|
|
|
sub title { |
|
1829
|
17
|
|
|
17
|
|
2635
|
my $self = shift; |
|
1830
|
17
|
|
|
|
|
26
|
my $title = shift; |
|
1831
|
17
|
100
|
|
|
|
97
|
return $self->{feed}->get_value('title') unless defined $title; |
|
1832
|
3
|
|
|
|
|
18
|
$self->{feed}->set_value( 'title' => $title, @_ ); |
|
1833
|
|
|
|
|
|
|
} |
|
1834
|
|
|
|
|
|
|
|
|
1835
|
|
|
|
|
|
|
sub description { |
|
1836
|
12
|
|
|
12
|
|
29
|
my $self = shift; |
|
1837
|
12
|
|
|
|
|
48
|
my $desc = shift; |
|
1838
|
|
|
|
|
|
|
return $self->{feed}->get_value('content') |
|
1839
|
|
|
|
|
|
|
|| $self->{feed}->get_value('summary') |
|
1840
|
|
|
|
|
|
|
|| $self->{feed}->get_value('subtitle') |
|
1841
|
12
|
100
|
66
|
|
|
52
|
|| $self->{feed}->get_value('tagline') unless defined $desc; |
|
1842
|
3
|
|
|
|
|
19
|
$self->{feed}->set_value( 'content' => $desc, @_ ); # type => 'text' |
|
1843
|
|
|
|
|
|
|
} |
|
1844
|
|
|
|
|
|
|
|
|
1845
|
|
|
|
|
|
|
sub pubDate { |
|
1846
|
9
|
|
|
9
|
|
302
|
my $self = shift; |
|
1847
|
9
|
|
|
|
|
12
|
my $date = shift; |
|
1848
|
9
|
100
|
|
|
|
32
|
return $self->get_pubDate_w3cdtf() unless defined $date; |
|
1849
|
2
|
|
|
|
|
6
|
$date = XML::FeedPP::Util::get_w3cdtf($date); |
|
1850
|
2
|
|
|
|
|
6
|
$self->{feed}->set_value( 'updated', $date ); |
|
1851
|
|
|
|
|
|
|
} |
|
1852
|
|
|
|
|
|
|
|
|
1853
|
|
|
|
|
|
|
sub get_pubDate_native { |
|
1854
|
9
|
|
|
9
|
|
14
|
my $self = shift; |
|
1855
|
|
|
|
|
|
|
$self->{feed}->get_value('updated') # Atom 1.0 |
|
1856
|
9
|
100
|
|
|
|
23
|
|| $self->{feed}->get_value('modified') # Atom 0.3 |
|
1857
|
|
|
|
|
|
|
} |
|
1858
|
|
|
|
|
|
|
|
|
1859
|
|
|
|
|
|
|
*get_pubDate_w3cdtf = \&get_pubDate_native; |
|
1860
|
|
|
|
|
|
|
|
|
1861
|
|
|
|
|
|
|
sub copyright { |
|
1862
|
8
|
|
|
8
|
|
19
|
my $self = shift; |
|
1863
|
8
|
|
|
|
|
12
|
my $copy = shift; |
|
1864
|
|
|
|
|
|
|
return $self->{feed}->get_value('rights') |
|
1865
|
8
|
100
|
66
|
|
|
28
|
|| $self->{feed}->get_value('copyright') unless defined $copy; |
|
1866
|
2
|
|
|
|
|
5
|
$self->{feed}->set_value( 'rights' => $copy ); |
|
1867
|
|
|
|
|
|
|
} |
|
1868
|
|
|
|
|
|
|
|
|
1869
|
|
|
|
|
|
|
sub link { |
|
1870
|
18
|
|
|
18
|
|
3112
|
my $self = shift; |
|
1871
|
18
|
|
|
|
|
27
|
my $href = shift; |
|
1872
|
|
|
|
|
|
|
|
|
1873
|
18
|
|
100
|
|
|
71
|
my $link = $self->{feed}->{link} || []; |
|
1874
|
18
|
100
|
|
|
|
82
|
$link = [$link] if UNIVERSAL::isa( $link, 'HASH' ); |
|
1875
|
18
|
|
|
|
|
45
|
$link = [ grep { ref $_ } @$link ]; |
|
|
12
|
|
|
|
|
28
|
|
|
1876
|
|
|
|
|
|
|
$link = [ grep { |
|
1877
|
18
|
100
|
|
|
|
34
|
! exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate' |
|
|
12
|
|
|
|
|
63
|
|
|
1878
|
|
|
|
|
|
|
} @$link ]; |
|
1879
|
18
|
|
|
|
|
29
|
my $html = shift @$link; |
|
1880
|
|
|
|
|
|
|
|
|
1881
|
18
|
100
|
|
|
|
58
|
if ( defined $href ) { |
|
|
|
100
|
|
|
|
|
|
|
1882
|
6
|
100
|
|
|
|
27
|
if ( ref $html ) { |
|
1883
|
1
|
|
|
|
|
2
|
$html->{'-href'} = $href; |
|
1884
|
|
|
|
|
|
|
} |
|
1885
|
|
|
|
|
|
|
else { |
|
1886
|
5
|
|
|
|
|
17
|
my $hash = { |
|
1887
|
|
|
|
|
|
|
-rel => 'alternate', |
|
1888
|
|
|
|
|
|
|
-href => $href, |
|
1889
|
|
|
|
|
|
|
}; |
|
1890
|
5
|
|
|
|
|
11
|
my $flink = $self->{feed}->{link}; |
|
1891
|
5
|
50
|
|
|
|
38
|
if ( ! ref $flink ) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
1892
|
5
|
|
|
|
|
17
|
$self->{feed}->{link} = [ $hash ]; |
|
1893
|
|
|
|
|
|
|
} |
|
1894
|
|
|
|
|
|
|
elsif ( UNIVERSAL::isa( $flink, 'ARRAY' )) { |
|
1895
|
0
|
|
|
|
|
0
|
push( @$flink, $hash ); |
|
1896
|
|
|
|
|
|
|
} |
|
1897
|
|
|
|
|
|
|
elsif ( UNIVERSAL::isa( $flink, 'HASH' )) { |
|
1898
|
0
|
|
|
|
|
0
|
$self->{feed}->{link} = [ $flink, $hash ]; |
|
1899
|
|
|
|
|
|
|
} |
|
1900
|
|
|
|
|
|
|
} |
|
1901
|
|
|
|
|
|
|
} |
|
1902
|
|
|
|
|
|
|
elsif ( ref $html ) { |
|
1903
|
9
|
|
|
|
|
37
|
return $html->{'-href'}; |
|
1904
|
|
|
|
|
|
|
} |
|
1905
|
9
|
|
|
|
|
18
|
return; |
|
1906
|
|
|
|
|
|
|
} |
|
1907
|
|
|
|
|
|
|
|
|
1908
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1909
|
|
|
|
|
|
|
package XML::FeedPP::Atom; |
|
1910
|
44
|
|
|
44
|
|
288
|
use strict; |
|
|
44
|
|
|
|
|
87
|
|
|
|
44
|
|
|
|
|
1127
|
|
|
1911
|
44
|
|
|
44
|
|
210
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
108
|
|
|
|
44
|
|
|
|
|
4114
|
|
|
1912
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Atom::Atom03 ); |
|
1913
|
|
|
|
|
|
|
|
|
1914
|
|
|
|
|
|
|
# @ISA = qw( XML::FeedPP::Atom::Atom10 ); # if Atom 1.0 for default |
|
1915
|
|
|
|
|
|
|
|
|
1916
|
|
|
|
|
|
|
sub test_feed { |
|
1917
|
4
|
|
|
4
|
|
7
|
my $self = shift; |
|
1918
|
4
|
|
66
|
|
|
19
|
my $source = shift || $self; |
|
1919
|
4
|
50
|
|
|
|
11
|
return unless ref $source; |
|
1920
|
4
|
100
|
|
|
|
13
|
return unless ref $source->{feed}; |
|
1921
|
3
|
|
|
|
|
6
|
__PACKAGE__; |
|
1922
|
|
|
|
|
|
|
} |
|
1923
|
|
|
|
|
|
|
|
|
1924
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1925
|
|
|
|
|
|
|
package XML::FeedPP::Atom::Common::Feed; |
|
1926
|
44
|
|
|
44
|
|
245
|
use strict; |
|
|
44
|
|
|
|
|
72
|
|
|
|
44
|
|
|
|
|
1064
|
|
|
1927
|
44
|
|
|
44
|
|
210
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
83
|
|
|
|
44
|
|
|
|
|
8587
|
|
|
1928
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Element ); |
|
1929
|
|
|
|
|
|
|
|
|
1930
|
|
|
|
|
|
|
# ... |
|
1931
|
|
|
|
|
|
|
# http://www.ietf.org/rfc/rfc4287.txt |
|
1932
|
|
|
|
|
|
|
# 3. If the value of "type" is "xhtml", the content of atom:content |
|
1933
|
|
|
|
|
|
|
# MUST be a single XHTML div element [XHTML] and SHOULD be suitable |
|
1934
|
|
|
|
|
|
|
# for handling as XHTML. The XHTML div element itself MUST NOT be |
|
1935
|
|
|
|
|
|
|
# considered part of the content. |
|
1936
|
|
|
|
|
|
|
|
|
1937
|
|
|
|
|
|
|
sub _fetch_value { |
|
1938
|
139
|
|
|
139
|
|
159
|
my $self = shift; |
|
1939
|
139
|
|
|
|
|
144
|
my $value = shift; |
|
1940
|
|
|
|
|
|
|
|
|
1941
|
139
|
100
|
66
|
|
|
586
|
if ( UNIVERSAL::isa( $value, 'HASH' ) |
|
|
|
|
66
|
|
|
|
|
|
1942
|
|
|
|
|
|
|
&& exists $value->{'-type'} |
|
1943
|
|
|
|
|
|
|
&& ($value->{'-type'} eq "xhtml")) { |
|
1944
|
6
|
|
|
|
|
18
|
my $child = [ grep { /^[^\-\#]/ } keys %$value ]; |
|
|
17
|
|
|
|
|
46
|
|
|
1945
|
6
|
50
|
|
|
|
15
|
if (scalar @$child == 1) { |
|
1946
|
6
|
|
|
|
|
8
|
my $div = shift @$child; |
|
1947
|
6
|
50
|
|
|
|
26
|
if ($div =~ /^([^:]+:)?div$/i) { |
|
1948
|
6
|
|
|
|
|
34
|
return $value->{$div}; |
|
1949
|
|
|
|
|
|
|
} |
|
1950
|
|
|
|
|
|
|
} |
|
1951
|
|
|
|
|
|
|
} |
|
1952
|
|
|
|
|
|
|
|
|
1953
|
133
|
|
|
|
|
258
|
$self->SUPER::_fetch_value($value); |
|
1954
|
|
|
|
|
|
|
} |
|
1955
|
|
|
|
|
|
|
|
|
1956
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1957
|
|
|
|
|
|
|
package XML::FeedPP::Atom::Atom03::Feed; |
|
1958
|
44
|
|
|
44
|
|
286
|
use strict; |
|
|
44
|
|
|
|
|
92
|
|
|
|
44
|
|
|
|
|
1094
|
|
|
1959
|
44
|
|
|
44
|
|
211
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
106
|
|
|
|
44
|
|
|
|
|
2325
|
|
|
1960
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Atom::Common::Feed ); |
|
1961
|
|
|
|
|
|
|
|
|
1962
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1963
|
|
|
|
|
|
|
package XML::FeedPP::Atom::Atom10::Feed; |
|
1964
|
44
|
|
|
44
|
|
224
|
use strict; |
|
|
44
|
|
|
|
|
78
|
|
|
|
44
|
|
|
|
|
1070
|
|
|
1965
|
44
|
|
|
44
|
|
207
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
77
|
|
|
|
44
|
|
|
|
|
2007
|
|
|
1966
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Atom::Common::Feed ); |
|
1967
|
|
|
|
|
|
|
|
|
1968
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1969
|
|
|
|
|
|
|
package XML::FeedPP::Atom::Common::Entry; |
|
1970
|
44
|
|
|
44
|
|
202
|
use strict; |
|
|
44
|
|
|
|
|
80
|
|
|
|
44
|
|
|
|
|
885
|
|
|
1971
|
44
|
|
|
44
|
|
175
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
76
|
|
|
|
44
|
|
|
|
|
6089
|
|
|
1972
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Item ); |
|
1973
|
|
|
|
|
|
|
|
|
1974
|
|
|
|
|
|
|
sub author { |
|
1975
|
31
|
|
|
31
|
|
54
|
my $self = shift; |
|
1976
|
31
|
|
|
|
|
44
|
my $name = shift; |
|
1977
|
31
|
100
|
|
|
|
63
|
unless ( defined $name ) { |
|
1978
|
22
|
100
|
|
|
|
55
|
my $author = $self->{author}->{name} if ref $self->{author}; |
|
1979
|
22
|
|
|
|
|
58
|
return $author; |
|
1980
|
|
|
|
|
|
|
} |
|
1981
|
9
|
50
|
|
|
|
43
|
my $author = ref $name ? $name : { name => $name }; |
|
1982
|
9
|
|
|
|
|
24
|
$self->{author} = $author; |
|
1983
|
|
|
|
|
|
|
} |
|
1984
|
|
|
|
|
|
|
|
|
1985
|
187
|
|
|
187
|
|
417
|
sub guid { shift->get_or_set( 'id', @_ ); } |
|
1986
|
|
|
|
|
|
|
|
|
1987
|
|
|
|
|
|
|
*_fetch_value = \&XML::FeedPP::Atom::Common::Feed::_fetch_value; |
|
1988
|
|
|
|
|
|
|
|
|
1989
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
1990
|
|
|
|
|
|
|
package XML::FeedPP::Atom::Atom03::Entry; |
|
1991
|
44
|
|
|
44
|
|
242
|
use strict; |
|
|
44
|
|
|
|
|
97
|
|
|
|
44
|
|
|
|
|
970
|
|
|
1992
|
44
|
|
|
44
|
|
177
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
89
|
|
|
|
44
|
|
|
|
|
20416
|
|
|
1993
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Atom::Common::Entry ); |
|
1994
|
|
|
|
|
|
|
|
|
1995
|
|
|
|
|
|
|
sub description { |
|
1996
|
24
|
|
|
24
|
|
45
|
my $self = shift; |
|
1997
|
24
|
|
|
|
|
34
|
my $desc = shift; |
|
1998
|
24
|
100
|
100
|
|
|
88
|
return $self->get_value('content') |
|
1999
|
|
|
|
|
|
|
|| $self->get_value('summary') unless defined $desc; |
|
2000
|
8
|
|
|
|
|
33
|
$self->set_value( |
|
2001
|
|
|
|
|
|
|
'content' => $desc, |
|
2002
|
|
|
|
|
|
|
type => 'text/html', |
|
2003
|
|
|
|
|
|
|
mode => 'escaped' |
|
2004
|
|
|
|
|
|
|
); |
|
2005
|
|
|
|
|
|
|
} |
|
2006
|
|
|
|
|
|
|
|
|
2007
|
|
|
|
|
|
|
sub link { |
|
2008
|
106
|
|
|
106
|
|
1453
|
my $self = shift; |
|
2009
|
106
|
|
|
|
|
135
|
my $href = shift; |
|
2010
|
|
|
|
|
|
|
|
|
2011
|
106
|
|
100
|
|
|
335
|
my $link = $self->{link} || []; |
|
2012
|
106
|
100
|
|
|
|
338
|
$link = [$link] if UNIVERSAL::isa( $link, 'HASH' ); |
|
2013
|
106
|
|
|
|
|
192
|
$link = [ grep { ref $_ } @$link ]; |
|
|
53
|
|
|
|
|
136
|
|
|
2014
|
|
|
|
|
|
|
$link = [ grep { |
|
2015
|
106
|
50
|
|
|
|
217
|
! exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate' |
|
|
53
|
|
|
|
|
277
|
|
|
2016
|
|
|
|
|
|
|
} @$link ]; |
|
2017
|
|
|
|
|
|
|
$link = [ grep { |
|
2018
|
106
|
100
|
|
|
|
185
|
! exists $_->{'-type'} || $_->{'-type'} =~ m#^text/(x-)?html#i |
|
|
53
|
|
|
|
|
389
|
|
|
2019
|
|
|
|
|
|
|
} @$link ]; |
|
2020
|
106
|
|
|
|
|
167
|
my $html = shift @$link; |
|
2021
|
|
|
|
|
|
|
|
|
2022
|
106
|
100
|
|
|
|
242
|
if ( defined $href ) { |
|
|
|
50
|
|
|
|
|
|
|
2023
|
54
|
100
|
|
|
|
100
|
if ( ref $html ) { |
|
2024
|
1
|
|
|
|
|
2
|
$html->{'-href'} = $href; |
|
2025
|
|
|
|
|
|
|
} |
|
2026
|
|
|
|
|
|
|
else { |
|
2027
|
53
|
|
|
|
|
175
|
my $hash = { |
|
2028
|
|
|
|
|
|
|
-rel => 'alternate', |
|
2029
|
|
|
|
|
|
|
-type => 'text/html', |
|
2030
|
|
|
|
|
|
|
-href => $href, |
|
2031
|
|
|
|
|
|
|
}; |
|
2032
|
53
|
|
|
|
|
91
|
my $flink = $self->{link}; |
|
2033
|
53
|
50
|
0
|
|
|
143
|
if ( ! ref $flink ) { |
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2034
|
53
|
|
|
|
|
129
|
$self->{link} = [ $hash ]; |
|
2035
|
|
|
|
|
|
|
} |
|
2036
|
|
|
|
|
|
|
elsif ( ref $flink && UNIVERSAL::isa( $flink, 'ARRAY' )) { |
|
2037
|
0
|
|
|
|
|
0
|
push( @$flink, $hash ); |
|
2038
|
|
|
|
|
|
|
} |
|
2039
|
|
|
|
|
|
|
elsif ( ref $flink && UNIVERSAL::isa( $flink, 'HASH' )) { |
|
2040
|
0
|
|
|
|
|
0
|
$self->{link} = [ $flink, $hash ]; |
|
2041
|
|
|
|
|
|
|
} |
|
2042
|
|
|
|
|
|
|
} |
|
2043
|
54
|
100
|
|
|
|
186
|
$self->guid( $href ) unless defined $self->guid(); |
|
2044
|
|
|
|
|
|
|
} |
|
2045
|
|
|
|
|
|
|
elsif ( ref $html ) { |
|
2046
|
52
|
|
|
|
|
219
|
return $html->{'-href'}; |
|
2047
|
|
|
|
|
|
|
} |
|
2048
|
54
|
|
|
|
|
119
|
return; |
|
2049
|
|
|
|
|
|
|
} |
|
2050
|
|
|
|
|
|
|
|
|
2051
|
|
|
|
|
|
|
sub pubDate { |
|
2052
|
57
|
|
|
57
|
|
104
|
my $self = shift; |
|
2053
|
57
|
|
|
|
|
75
|
my $date = shift; |
|
2054
|
57
|
100
|
|
|
|
130
|
return $self->get_pubDate_w3cdtf() unless defined $date; |
|
2055
|
38
|
|
|
|
|
58
|
$date = XML::FeedPP::Util::get_w3cdtf($date); |
|
2056
|
38
|
|
|
|
|
95
|
$self->set_value( 'issued', $date ); |
|
2057
|
38
|
|
|
|
|
63
|
$self->set_value( 'modified', $date ); |
|
2058
|
|
|
|
|
|
|
} |
|
2059
|
|
|
|
|
|
|
|
|
2060
|
|
|
|
|
|
|
sub get_pubDate_native { |
|
2061
|
66
|
|
|
66
|
|
91
|
my $self = shift; |
|
2062
|
66
|
50
|
66
|
|
|
114
|
$self->get_value('modified') # Atom 0.3 |
|
|
|
|
66
|
|
|
|
|
|
2063
|
|
|
|
|
|
|
|| $self->get_value('issued') # Atom 0.3 |
|
2064
|
|
|
|
|
|
|
|| $self->get_value('updated') # Atom 1.0 |
|
2065
|
|
|
|
|
|
|
|| $self->get_value('published'); # Atom 1.0 |
|
2066
|
|
|
|
|
|
|
} |
|
2067
|
|
|
|
|
|
|
|
|
2068
|
|
|
|
|
|
|
*get_pubDate_w3cdtf = \&get_pubDate_native; |
|
2069
|
|
|
|
|
|
|
|
|
2070
|
|
|
|
|
|
|
sub title { |
|
2071
|
48
|
|
|
48
|
|
1116
|
my $self = shift; |
|
2072
|
48
|
|
|
|
|
65
|
my $title = shift; |
|
2073
|
48
|
100
|
|
|
|
146
|
return $self->get_value('title') unless defined $title; |
|
2074
|
25
|
|
|
|
|
57
|
$self->set_value( 'title' => $title, type => 'text/plain' ); |
|
2075
|
|
|
|
|
|
|
} |
|
2076
|
|
|
|
|
|
|
|
|
2077
|
14
|
|
|
14
|
|
29
|
sub category { undef; } # this element is NOT supported for Atom 0.3 |
|
2078
|
|
|
|
|
|
|
|
|
2079
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
2080
|
|
|
|
|
|
|
package XML::FeedPP::Atom::Atom10::Entry; |
|
2081
|
44
|
|
|
44
|
|
262
|
use strict; |
|
|
44
|
|
|
|
|
70
|
|
|
|
44
|
|
|
|
|
984
|
|
|
2082
|
44
|
|
|
44
|
|
188
|
use vars qw( @ISA ); |
|
|
44
|
|
|
|
|
77
|
|
|
|
44
|
|
|
|
|
24328
|
|
|
2083
|
|
|
|
|
|
|
@ISA = qw( XML::FeedPP::Atom::Common::Entry ); |
|
2084
|
|
|
|
|
|
|
|
|
2085
|
|
|
|
|
|
|
sub description { |
|
2086
|
18
|
|
|
18
|
|
6006
|
my $self = shift; |
|
2087
|
18
|
|
|
|
|
24
|
my $desc = shift; |
|
2088
|
18
|
100
|
100
|
|
|
82
|
return $self->get_value('content') |
|
2089
|
|
|
|
|
|
|
|| $self->get_value('summary') unless defined $desc; |
|
2090
|
3
|
|
|
|
|
10
|
$self->set_value( 'content' => $desc, @_ ); |
|
2091
|
|
|
|
|
|
|
} |
|
2092
|
|
|
|
|
|
|
|
|
2093
|
|
|
|
|
|
|
sub link { |
|
2094
|
24
|
|
|
24
|
|
44
|
my $self = shift; |
|
2095
|
24
|
|
|
|
|
47
|
my $href = shift; |
|
2096
|
|
|
|
|
|
|
|
|
2097
|
24
|
|
100
|
|
|
96
|
my $link = $self->{link} || []; |
|
2098
|
24
|
100
|
|
|
|
91
|
$link = [$link] if UNIVERSAL::isa( $link, 'HASH' ); |
|
2099
|
24
|
|
|
|
|
58
|
$link = [ grep { ref $_ } @$link ]; |
|
|
12
|
|
|
|
|
27
|
|
|
2100
|
|
|
|
|
|
|
$link = [ grep { |
|
2101
|
24
|
100
|
|
|
|
45
|
! exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate' |
|
|
12
|
|
|
|
|
44
|
|
|
2102
|
|
|
|
|
|
|
} @$link ]; |
|
2103
|
24
|
|
|
|
|
34
|
my $html = shift @$link; |
|
2104
|
|
|
|
|
|
|
|
|
2105
|
24
|
100
|
|
|
|
68
|
if ( defined $href ) { |
|
|
|
50
|
|
|
|
|
|
|
2106
|
14
|
100
|
|
|
|
25
|
if ( ref $html ) { |
|
2107
|
1
|
|
|
|
|
1
|
$html->{'-href'} = $href; |
|
2108
|
|
|
|
|
|
|
} |
|
2109
|
|
|
|
|
|
|
else { |
|
2110
|
13
|
|
|
|
|
23
|
my $hash = { |
|
2111
|
|
|
|
|
|
|
# -rel => 'alternate', |
|
2112
|
|
|
|
|
|
|
-href => $href, |
|
2113
|
|
|
|
|
|
|
}; |
|
2114
|
13
|
|
|
|
|
24
|
my $flink = $self->{link}; |
|
2115
|
13
|
50
|
0
|
|
|
23
|
if ( ! ref $flink ) { |
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2116
|
13
|
|
|
|
|
29
|
$self->{link} = [ $hash ]; |
|
2117
|
|
|
|
|
|
|
} |
|
2118
|
|
|
|
|
|
|
elsif ( ref $flink && UNIVERSAL::isa( $flink, 'ARRAY' )) { |
|
2119
|
0
|
|
|
|
|
0
|
push( @$flink, $hash ); |
|
2120
|
|
|
|
|
|
|
} |
|
2121
|
|
|
|
|
|
|
elsif ( ref $flink && UNIVERSAL::isa( $flink, 'HASH' )) { |
|
2122
|
0
|
|
|
|
|
0
|
$self->{link} = [ $flink, $hash ]; |
|
2123
|
|
|
|
|
|
|
} |
|
2124
|
|
|
|
|
|
|
} |
|
2125
|
14
|
100
|
|
|
|
42
|
$self->guid( $href ) unless defined $self->guid(); |
|
2126
|
|
|
|
|
|
|
} |
|
2127
|
|
|
|
|
|
|
elsif ( ref $html ) { |
|
2128
|
10
|
|
|
|
|
33
|
return $html->{'-href'}; |
|
2129
|
|
|
|
|
|
|
} |
|
2130
|
14
|
|
|
|
|
25
|
return; |
|
2131
|
|
|
|
|
|
|
} |
|
2132
|
|
|
|
|
|
|
|
|
2133
|
|
|
|
|
|
|
sub pubDate { |
|
2134
|
13
|
|
|
13
|
|
26
|
my $self = shift; |
|
2135
|
13
|
|
|
|
|
17
|
my $date = shift; |
|
2136
|
13
|
100
|
|
|
|
31
|
return $self->get_pubDate_w3cdtf() unless defined $date; |
|
2137
|
4
|
|
|
|
|
7
|
$date = XML::FeedPP::Util::get_w3cdtf($date); |
|
2138
|
4
|
|
|
|
|
10
|
$self->set_value( 'updated', $date ); |
|
2139
|
|
|
|
|
|
|
} |
|
2140
|
|
|
|
|
|
|
|
|
2141
|
|
|
|
|
|
|
sub get_pubDate_native { |
|
2142
|
21
|
|
|
21
|
|
35
|
my $self = shift; |
|
2143
|
21
|
50
|
66
|
|
|
48
|
$self->get_value('updated') # Atom 1.0 |
|
|
|
|
66
|
|
|
|
|
|
2144
|
|
|
|
|
|
|
|| $self->get_value('published') # Atom 1.0 |
|
2145
|
|
|
|
|
|
|
|| $self->get_value('issued') # Atom 0.3 |
|
2146
|
|
|
|
|
|
|
|| $self->get_value('modified'); # Atom 0.3 |
|
2147
|
|
|
|
|
|
|
} |
|
2148
|
|
|
|
|
|
|
|
|
2149
|
|
|
|
|
|
|
*get_pubDate_w3cdtf = \&get_pubDate_native; |
|
2150
|
|
|
|
|
|
|
|
|
2151
|
|
|
|
|
|
|
sub title { |
|
2152
|
16
|
|
|
16
|
|
1022
|
my $self = shift; |
|
2153
|
16
|
|
|
|
|
24
|
my $title = shift; |
|
2154
|
16
|
|
50
|
|
|
51
|
my $type = shift || 'text'; |
|
2155
|
16
|
100
|
|
|
|
46
|
return $self->get_value('title') unless defined $title; |
|
2156
|
5
|
|
|
|
|
14
|
$self->set_value( 'title' => $title, type => $type ); |
|
2157
|
|
|
|
|
|
|
} |
|
2158
|
|
|
|
|
|
|
|
|
2159
|
|
|
|
|
|
|
sub category { |
|
2160
|
35
|
|
|
35
|
|
3428
|
my $self = shift; |
|
2161
|
35
|
100
|
|
|
|
68
|
if ( scalar @_ ) { |
|
2162
|
15
|
100
|
|
|
|
36
|
my $cate = ref $_[0] ? $_[0] : \@_; |
|
2163
|
15
|
|
|
|
|
28
|
my $list = [ map {+{-term=>$_}} @$cate ]; |
|
|
26
|
|
|
|
|
60
|
|
|
2164
|
15
|
100
|
|
|
|
56
|
$self->{category} = ( scalar @$list > 1 ) ? $list : shift @$list; |
|
2165
|
|
|
|
|
|
|
} |
|
2166
|
|
|
|
|
|
|
else { |
|
2167
|
20
|
50
|
|
|
|
44
|
return unless exists $self->{category}; |
|
2168
|
20
|
|
50
|
|
|
55
|
my $list = $self->{category} || []; |
|
2169
|
20
|
100
|
66
|
|
|
93
|
$list = [ $list ] if ( defined $list && ! UNIVERSAL::isa( $list, 'ARRAY' )); |
|
2170
|
20
|
50
|
33
|
|
|
37
|
my $term = [ map {ref $_ && exists $_->{-term} && $_->{-term} } @$list ]; |
|
|
36
|
|
|
|
|
154
|
|
|
2171
|
|
|
|
|
|
|
# return wantarray ? @$term : shift @$term; |
|
2172
|
20
|
100
|
|
|
|
68
|
return ( scalar @$term > 1 ) ? $term : shift @$term; |
|
2173
|
|
|
|
|
|
|
} |
|
2174
|
|
|
|
|
|
|
} |
|
2175
|
|
|
|
|
|
|
|
|
2176
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
2177
|
|
|
|
|
|
|
package XML::FeedPP::Element; |
|
2178
|
44
|
|
|
44
|
|
277
|
use strict; |
|
|
44
|
|
|
|
|
68
|
|
|
|
44
|
|
|
|
|
52627
|
|
|
2179
|
|
|
|
|
|
|
|
|
2180
|
|
|
|
|
|
|
sub new { |
|
2181
|
491
|
|
|
491
|
|
658
|
my $package = shift; |
|
2182
|
491
|
|
|
|
|
689
|
my $self = {@_}; |
|
2183
|
491
|
|
|
|
|
660
|
bless $self, $package; |
|
2184
|
491
|
|
|
|
|
943
|
$self; |
|
2185
|
|
|
|
|
|
|
} |
|
2186
|
|
|
|
|
|
|
|
|
2187
|
|
|
|
|
|
|
sub ref_bless { |
|
2188
|
299
|
|
|
299
|
|
431
|
my $package = shift; |
|
2189
|
299
|
|
|
|
|
377
|
my $self = shift; |
|
2190
|
299
|
|
|
|
|
443
|
bless $self, $package; |
|
2191
|
299
|
|
|
|
|
426
|
$self; |
|
2192
|
|
|
|
|
|
|
} |
|
2193
|
|
|
|
|
|
|
|
|
2194
|
|
|
|
|
|
|
sub set { |
|
2195
|
29
|
|
|
29
|
|
103
|
my $self = shift; |
|
2196
|
|
|
|
|
|
|
|
|
2197
|
29
|
|
|
|
|
58
|
while ( scalar @_ ) { |
|
2198
|
127
|
|
|
|
|
163
|
my $key = shift @_; |
|
2199
|
127
|
|
|
|
|
139
|
my $val = shift @_; |
|
2200
|
127
|
|
|
|
|
149
|
my $node = $self; |
|
2201
|
127
|
|
|
|
|
293
|
while ( $key =~ s#^([^/]+)/##s ) { |
|
2202
|
36
|
|
|
|
|
63
|
my $child = $1; |
|
2203
|
36
|
100
|
|
|
|
89
|
if ( ref $node->{$child} ) { |
|
|
|
50
|
|
|
|
|
|
|
2204
|
|
|
|
|
|
|
# ok |
|
2205
|
|
|
|
|
|
|
} |
|
2206
|
|
|
|
|
|
|
elsif ( defined $node->{$child} ) { |
|
2207
|
0
|
|
|
|
|
0
|
$node->{$child} = { '#text' => $node->{$child} }; |
|
2208
|
|
|
|
|
|
|
} |
|
2209
|
|
|
|
|
|
|
else { |
|
2210
|
18
|
|
|
|
|
26
|
$node->{$child} = {}; |
|
2211
|
|
|
|
|
|
|
} |
|
2212
|
36
|
|
|
|
|
63
|
$node = $node->{$child}; |
|
2213
|
|
|
|
|
|
|
} |
|
2214
|
127
|
|
|
|
|
255
|
my ( $tagname, $attr ) = split( /\@/, $key, 2 ); |
|
2215
|
127
|
100
|
66
|
|
|
376
|
if ( $tagname eq "" && defined $attr ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
2216
|
6
|
|
|
|
|
16
|
$node->{ '-' . $attr } = $val; |
|
2217
|
|
|
|
|
|
|
} |
|
2218
|
|
|
|
|
|
|
elsif ( defined $attr ) { |
|
2219
|
59
|
100
|
100
|
|
|
168
|
if ( ref $node->{$tagname} && |
|
2220
|
|
|
|
|
|
|
UNIVERSAL::isa( $node->{$tagname}, 'ARRAY' )) { |
|
2221
|
1
|
|
|
|
|
3
|
$node->{$tagname} = shift @{$node->{$tagname}}; |
|
|
1
|
|
|
|
|
3
|
|
|
2222
|
|
|
|
|
|
|
} |
|
2223
|
59
|
|
|
|
|
92
|
my $hkey = '-' . $attr; |
|
2224
|
59
|
100
|
|
|
|
115
|
if ( ref $node->{$tagname} ) { |
|
|
|
100
|
|
|
|
|
|
|
2225
|
25
|
|
|
|
|
77
|
$node->{$tagname}->{$hkey} = $val; |
|
2226
|
|
|
|
|
|
|
} |
|
2227
|
|
|
|
|
|
|
elsif ( defined $node->{$tagname} ) { |
|
2228
|
|
|
|
|
|
|
$node->{$tagname} = { |
|
2229
|
4
|
|
|
|
|
17
|
'#text' => $node->{$tagname}, |
|
2230
|
|
|
|
|
|
|
$hkey => $val, |
|
2231
|
|
|
|
|
|
|
}; |
|
2232
|
|
|
|
|
|
|
} |
|
2233
|
|
|
|
|
|
|
else { |
|
2234
|
30
|
|
|
|
|
101
|
$node->{$tagname} = { $hkey => $val }; |
|
2235
|
|
|
|
|
|
|
} |
|
2236
|
|
|
|
|
|
|
} |
|
2237
|
|
|
|
|
|
|
elsif ( defined $tagname ) { |
|
2238
|
62
|
50
|
66
|
|
|
154
|
if ( ref $node->{$tagname} && |
|
2239
|
|
|
|
|
|
|
UNIVERSAL::isa( $node->{$tagname}, 'ARRAY' )) { |
|
2240
|
0
|
|
|
|
|
0
|
$node->{$tagname} = shift @{$node->{$tagname}}; |
|
|
0
|
|
|
|
|
0
|
|
|
2241
|
|
|
|
|
|
|
} |
|
2242
|
62
|
100
|
|
|
|
108
|
if ( ref $node->{$tagname} ) { |
|
2243
|
19
|
|
|
|
|
39
|
$node->{$tagname}->{'#text'} = $val; |
|
2244
|
|
|
|
|
|
|
} |
|
2245
|
|
|
|
|
|
|
else { |
|
2246
|
43
|
|
|
|
|
141
|
$node->{$tagname} = $val; |
|
2247
|
|
|
|
|
|
|
} |
|
2248
|
|
|
|
|
|
|
} |
|
2249
|
|
|
|
|
|
|
} |
|
2250
|
|
|
|
|
|
|
} |
|
2251
|
|
|
|
|
|
|
|
|
2252
|
|
|
|
|
|
|
sub get { |
|
2253
|
228
|
|
|
228
|
|
45090
|
my $self = shift; |
|
2254
|
228
|
|
|
|
|
303
|
my $key = shift; |
|
2255
|
228
|
|
|
|
|
289
|
my $node = $self; |
|
2256
|
|
|
|
|
|
|
|
|
2257
|
228
|
|
|
|
|
879
|
while ( $key =~ s#^([^/]+)/##s ) { |
|
2258
|
84
|
|
|
|
|
172
|
my $child = $1; |
|
2259
|
84
|
50
|
|
|
|
153
|
return unless ref $node; |
|
2260
|
84
|
100
|
|
|
|
166
|
return unless exists $node->{$child}; |
|
2261
|
72
|
|
|
|
|
158
|
$node = $node->{$child}; |
|
2262
|
|
|
|
|
|
|
} |
|
2263
|
216
|
|
|
|
|
563
|
my ( $tagname, $attr ) = split( /\@/, $key, 2 ); |
|
2264
|
216
|
100
|
|
|
|
437
|
return unless ref $node; |
|
2265
|
|
|
|
|
|
|
# return unless exists $node->{$tagname}; |
|
2266
|
204
|
100
|
66
|
|
|
576
|
if ( $tagname eq "" && defined $attr ) { # @attribute |
|
|
|
100
|
|
|
|
|
|
|
2267
|
7
|
50
|
|
|
|
22
|
return unless exists $node->{ '-' . $attr }; |
|
2268
|
7
|
|
|
|
|
32
|
return $node->{ '-' . $attr }; |
|
2269
|
|
|
|
|
|
|
} |
|
2270
|
|
|
|
|
|
|
elsif ( defined $attr ) { # node@attribute |
|
2271
|
98
|
100
|
|
|
|
248
|
return unless ref $node->{$tagname}; |
|
2272
|
80
|
|
|
|
|
140
|
my $hkey = '-' . $attr; |
|
2273
|
80
|
100
|
|
|
|
213
|
if ( UNIVERSAL::isa( $node->{$tagname}, 'ARRAY' )) { |
|
2274
|
|
|
|
|
|
|
my $list = [ |
|
2275
|
28
|
100
|
100
|
|
|
84
|
map { ref $_ && exists $_->{$hkey} ? $_->{$hkey} : undef } |
|
2276
|
8
|
|
|
|
|
10
|
@{$node->{$tagname}} ]; |
|
|
8
|
|
|
|
|
17
|
|
|
2277
|
8
|
100
|
|
|
|
28
|
return @$list if wantarray; |
|
2278
|
4
|
|
|
|
|
8
|
return ( grep { defined $_ } @$list )[0]; |
|
|
12
|
|
|
|
|
27
|
|
|
2279
|
|
|
|
|
|
|
} |
|
2280
|
72
|
50
|
|
|
|
140
|
return unless exists $node->{$tagname}->{$hkey}; |
|
2281
|
72
|
|
|
|
|
269
|
return $node->{$tagname}->{$hkey}; |
|
2282
|
|
|
|
|
|
|
} |
|
2283
|
|
|
|
|
|
|
else { # node |
|
2284
|
99
|
100
|
|
|
|
375
|
return $node->{$tagname} unless ref $node->{$tagname}; |
|
2285
|
30
|
100
|
|
|
|
99
|
if ( UNIVERSAL::isa( $node->{$tagname}, 'ARRAY' )) { |
|
2286
|
|
|
|
|
|
|
my $list = [ |
|
2287
|
4
|
100
|
|
|
|
20
|
map { ref $_ ? $_->{'#text'} : $_ } |
|
2288
|
1
|
|
|
|
|
2
|
@{$node->{$tagname}} ]; |
|
|
1
|
|
|
|
|
3
|
|
|
2289
|
1
|
50
|
|
|
|
19
|
return @$list if wantarray; |
|
2290
|
0
|
|
|
|
|
0
|
return ( grep { defined $_ } @$list )[0]; |
|
|
0
|
|
|
|
|
0
|
|
|
2291
|
|
|
|
|
|
|
} |
|
2292
|
29
|
|
|
|
|
127
|
return $node->{$tagname}->{'#text'}; |
|
2293
|
|
|
|
|
|
|
} |
|
2294
|
|
|
|
|
|
|
} |
|
2295
|
|
|
|
|
|
|
|
|
2296
|
|
|
|
|
|
|
sub get_set_array { |
|
2297
|
153
|
|
|
153
|
|
212
|
my $self = shift; |
|
2298
|
153
|
|
|
|
|
197
|
my $elem = shift; |
|
2299
|
153
|
|
|
|
|
177
|
my $value = shift; |
|
2300
|
153
|
100
|
|
|
|
323
|
if ( ref $value ) { |
|
|
|
100
|
|
|
|
|
|
|
2301
|
21
|
|
|
|
|
60
|
$self->{$elem} = $value; |
|
2302
|
|
|
|
|
|
|
} elsif ( defined $value ) { |
|
2303
|
29
|
50
|
|
|
|
49
|
$value = [ $value, @_ ] if scalar @_; |
|
2304
|
29
|
|
|
|
|
63
|
$self->{$elem} = $value; |
|
2305
|
|
|
|
|
|
|
} else { |
|
2306
|
103
|
|
|
|
|
192
|
my @ret = $self->get_value($elem); |
|
2307
|
103
|
100
|
|
|
|
352
|
return scalar @ret > 1 ? \@ret : $ret[0]; |
|
2308
|
|
|
|
|
|
|
} |
|
2309
|
|
|
|
|
|
|
} |
|
2310
|
|
|
|
|
|
|
|
|
2311
|
|
|
|
|
|
|
sub get_or_set { |
|
2312
|
785
|
|
|
785
|
|
998
|
my $self = shift; |
|
2313
|
785
|
|
|
|
|
983
|
my $elem = shift; |
|
2314
|
|
|
|
|
|
|
return scalar @_ |
|
2315
|
785
|
100
|
|
|
|
1860
|
? $self->set_value( $elem, @_ ) |
|
2316
|
|
|
|
|
|
|
: $self->get_value($elem); |
|
2317
|
|
|
|
|
|
|
} |
|
2318
|
|
|
|
|
|
|
|
|
2319
|
|
|
|
|
|
|
sub get_value { |
|
2320
|
2059
|
|
|
2059
|
|
2365
|
my $self = shift; |
|
2321
|
2059
|
|
|
|
|
2466
|
my $elem = shift; |
|
2322
|
2059
|
100
|
|
|
|
3589
|
unless(exists $self->{$elem}) { |
|
2323
|
|
|
|
|
|
|
#XXX TreePP does not understand prefixes, which is usually not a |
|
2324
|
|
|
|
|
|
|
# problem because most clients break on them... "best practices" |
|
2325
|
|
|
|
|
|
|
# for feeds often explicitly state to use "the default" namespace. |
|
2326
|
|
|
|
|
|
|
# Let's try to ignore the namespace here. |
|
2327
|
964
|
|
|
|
|
8624
|
($elem) = grep /\:\Q$elem\E$/, keys %$self; |
|
2328
|
964
|
100
|
|
|
|
3533
|
defined $elem or return; |
|
2329
|
|
|
|
|
|
|
} |
|
2330
|
|
|
|
|
|
|
|
|
2331
|
1096
|
|
|
|
|
1439
|
my $value = $self->{$elem}; |
|
2332
|
1096
|
100
|
|
|
|
3256
|
return $value unless ref $value; |
|
2333
|
|
|
|
|
|
|
|
|
2334
|
|
|
|
|
|
|
# multiple elements |
|
2335
|
190
|
100
|
|
|
|
468
|
if ( UNIVERSAL::isa( $value, 'ARRAY' )) { |
|
2336
|
42
|
100
|
|
|
|
89
|
if ( wantarray ) { |
|
2337
|
39
|
|
|
|
|
68
|
return map { $self->_fetch_value($_) } @$value; |
|
|
107
|
|
|
|
|
212
|
|
|
2338
|
|
|
|
|
|
|
} else { |
|
2339
|
3
|
|
|
|
|
9
|
return $self->_fetch_value($value->[0]); |
|
2340
|
|
|
|
|
|
|
} |
|
2341
|
|
|
|
|
|
|
} |
|
2342
|
|
|
|
|
|
|
|
|
2343
|
148
|
|
|
|
|
399
|
return $self->_fetch_value($value); |
|
2344
|
|
|
|
|
|
|
} |
|
2345
|
|
|
|
|
|
|
|
|
2346
|
|
|
|
|
|
|
sub _fetch_value { |
|
2347
|
395
|
|
|
395
|
|
481
|
my $self = shift; |
|
2348
|
395
|
|
|
|
|
431
|
my $value = shift; |
|
2349
|
|
|
|
|
|
|
|
|
2350
|
395
|
100
|
|
|
|
944
|
if ( UNIVERSAL::isa( $value, 'HASH' )) { |
|
2351
|
|
|
|
|
|
|
# text node of an element with attributes |
|
2352
|
|
|
|
|
|
|
return defined $value->{'#text'} |
|
2353
|
143
|
50
|
|
|
|
408
|
? $self->_fetch_value($value->{'#text'}) |
|
2354
|
|
|
|
|
|
|
: ''; |
|
2355
|
|
|
|
|
|
|
} |
|
2356
|
|
|
|
|
|
|
|
|
2357
|
252
|
100
|
|
|
|
566
|
if ( UNIVERSAL::isa( $value, 'SCALAR' )) { |
|
2358
|
|
|
|
|
|
|
# CDATA section as a scalar reference |
|
2359
|
27
|
|
|
|
|
109
|
return $$value; |
|
2360
|
|
|
|
|
|
|
} |
|
2361
|
|
|
|
|
|
|
|
|
2362
|
225
|
|
|
|
|
655
|
return $value; |
|
2363
|
|
|
|
|
|
|
} |
|
2364
|
|
|
|
|
|
|
|
|
2365
|
|
|
|
|
|
|
sub set_value { |
|
2366
|
839
|
|
|
839
|
|
1014
|
my $self = shift; |
|
2367
|
839
|
|
|
|
|
910
|
my $elem = shift; |
|
2368
|
839
|
|
|
|
|
935
|
my $text = shift; |
|
2369
|
839
|
|
|
|
|
1059
|
my $attr = \@_; |
|
2370
|
839
|
100
|
|
|
|
2631
|
if ( UNIVERSAL::isa( $self->{$elem}, 'HASH' )) { |
|
2371
|
15
|
|
|
|
|
53
|
$self->{$elem}->{'#text'} = $text; |
|
2372
|
|
|
|
|
|
|
} |
|
2373
|
|
|
|
|
|
|
else { |
|
2374
|
824
|
|
|
|
|
1326
|
$self->{$elem} = $text; |
|
2375
|
|
|
|
|
|
|
} |
|
2376
|
839
|
100
|
|
|
|
1982
|
$self->set_attr( $elem, @$attr ) if scalar @$attr; |
|
2377
|
839
|
|
|
|
|
1511
|
undef; |
|
2378
|
|
|
|
|
|
|
} |
|
2379
|
|
|
|
|
|
|
|
|
2380
|
|
|
|
|
|
|
sub get_attr { |
|
2381
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
2382
|
0
|
|
|
|
|
0
|
my $elem = shift; |
|
2383
|
0
|
|
|
|
|
0
|
my $key = shift; |
|
2384
|
0
|
0
|
|
|
|
0
|
return unless exists $self->{$elem}; |
|
2385
|
0
|
0
|
|
|
|
0
|
return unless ref $self->{$elem}; |
|
2386
|
0
|
0
|
|
|
|
0
|
return unless exists $self->{$elem}->{ '-' . $key }; |
|
2387
|
0
|
|
|
|
|
0
|
$self->{$elem}->{ '-' . $key }; |
|
2388
|
|
|
|
|
|
|
} |
|
2389
|
|
|
|
|
|
|
|
|
2390
|
|
|
|
|
|
|
sub set_attr { |
|
2391
|
160
|
|
|
160
|
|
205
|
my $self = shift; |
|
2392
|
160
|
|
|
|
|
194
|
my $elem = shift; |
|
2393
|
160
|
|
|
|
|
642
|
my $attr = \@_; |
|
2394
|
160
|
50
|
|
|
|
304
|
if ( defined $self->{$elem} ) { |
|
2395
|
160
|
|
|
|
|
250
|
my $scalar = ref $self->{$elem}; |
|
2396
|
160
|
100
|
|
|
|
333
|
$scalar = undef if ($scalar eq 'SCALAR'); |
|
2397
|
160
|
100
|
|
|
|
296
|
if (! $scalar) { |
|
2398
|
145
|
|
|
|
|
358
|
$self->{$elem} = { '#text' => $self->{$elem} }; |
|
2399
|
|
|
|
|
|
|
} |
|
2400
|
|
|
|
|
|
|
} |
|
2401
|
|
|
|
|
|
|
else { |
|
2402
|
0
|
|
|
|
|
0
|
$self->{$elem} = {}; |
|
2403
|
|
|
|
|
|
|
} |
|
2404
|
160
|
|
|
|
|
336
|
while ( scalar @$attr ) { |
|
2405
|
175
|
|
|
|
|
272
|
my $key = shift @$attr; |
|
2406
|
175
|
|
|
|
|
241
|
my $val = shift @$attr; |
|
2407
|
175
|
50
|
|
|
|
297
|
if ( defined $val ) { |
|
2408
|
|
|
|
|
|
|
# $val = $$val if (ref $val eq 'SCALAR'); |
|
2409
|
175
|
|
|
|
|
546
|
$self->{$elem}->{ '-' . $key } = $val; |
|
2410
|
|
|
|
|
|
|
} |
|
2411
|
|
|
|
|
|
|
else { |
|
2412
|
0
|
|
|
|
|
0
|
delete $self->{$elem}->{ '-' . $key }; |
|
2413
|
|
|
|
|
|
|
} |
|
2414
|
|
|
|
|
|
|
} |
|
2415
|
160
|
|
|
|
|
224
|
undef; |
|
2416
|
|
|
|
|
|
|
} |
|
2417
|
|
|
|
|
|
|
|
|
2418
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
2419
|
|
|
|
|
|
|
package XML::FeedPP::Util; |
|
2420
|
44
|
|
|
44
|
|
286
|
use strict; |
|
|
44
|
|
|
|
|
100
|
|
|
|
44
|
|
|
|
|
58728
|
|
|
2421
|
|
|
|
|
|
|
|
|
2422
|
|
|
|
|
|
|
my ( @DoW, @MoY, %MoY ); |
|
2423
|
|
|
|
|
|
|
@DoW = qw(Sun Mon Tue Wed Thu Fri Sat); |
|
2424
|
|
|
|
|
|
|
@MoY = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); |
|
2425
|
|
|
|
|
|
|
@MoY{ map { uc($_) } @MoY } = ( 1 .. 12 ); |
|
2426
|
|
|
|
|
|
|
my $tz_now = time(); |
|
2427
|
|
|
|
|
|
|
my $tz_offset = Time::Local::timegm( localtime($tz_now) ) - |
|
2428
|
|
|
|
|
|
|
Time::Local::timegm( gmtime($tz_now) ); |
|
2429
|
|
|
|
|
|
|
my $tz_hour = int( $tz_offset / 3600 ); |
|
2430
|
|
|
|
|
|
|
my $tz_min = int( $tz_offset / 60 ) % 60; |
|
2431
|
|
|
|
|
|
|
my $rfc1123_regexp = qr{ |
|
2432
|
|
|
|
|
|
|
^(?:[A-Za-z]+,\s*)? (\d+)\s+ ([A-Za-z]+)\s+ (\d+)\s+ |
|
2433
|
|
|
|
|
|
|
(\d+):(\d+)(?::(\d+)(?:\.\d*)?)?\s* |
|
2434
|
|
|
|
|
|
|
([\+\-]\d+:?\d{2} | [ECMP][DS]T )? |
|
2435
|
|
|
|
|
|
|
}xi; |
|
2436
|
|
|
|
|
|
|
my $w3cdtf_regexp = qr{ |
|
2437
|
|
|
|
|
|
|
^(\d+)-(\d+)-(\d+) |
|
2438
|
|
|
|
|
|
|
(?:T(\d+):(\d+)(?::(\d+)(?:\.\d*)?\:?)?\s* |
|
2439
|
|
|
|
|
|
|
([\+\-]\d+:?\d{2})?|$) |
|
2440
|
|
|
|
|
|
|
}x; |
|
2441
|
|
|
|
|
|
|
my $tzmap = {qw( |
|
2442
|
|
|
|
|
|
|
EDT -4 EST -5 CDT -5 CST -6 |
|
2443
|
|
|
|
|
|
|
MDT -6 MST -7 PDT -7 PST -8 |
|
2444
|
|
|
|
|
|
|
)}; |
|
2445
|
|
|
|
|
|
|
|
|
2446
|
|
|
|
|
|
|
sub epoch_to_w3cdtf { |
|
2447
|
15
|
|
|
15
|
|
992
|
my $epoch = shift; |
|
2448
|
15
|
50
|
|
|
|
28
|
return unless defined $epoch; |
|
2449
|
15
|
|
|
|
|
64
|
my ( $sec, $min, $hour, $day, $mon, $year ) = gmtime($epoch+$tz_offset); |
|
2450
|
15
|
|
|
|
|
24
|
$year += 1900; |
|
2451
|
15
|
|
|
|
|
18
|
$mon++; |
|
2452
|
15
|
50
|
|
|
|
27
|
my $tz = $tz_offset ? sprintf( '%+03d:%02d', $tz_hour, $tz_min ) : 'Z'; |
|
2453
|
15
|
|
|
|
|
64
|
sprintf( '%04d-%02d-%02dT%02d:%02d:%02d%s', |
|
2454
|
|
|
|
|
|
|
$year, $mon, $day, $hour, $min, $sec, $tz ); |
|
2455
|
|
|
|
|
|
|
} |
|
2456
|
|
|
|
|
|
|
|
|
2457
|
|
|
|
|
|
|
sub epoch_to_rfc1123 { |
|
2458
|
12
|
|
|
12
|
|
1439
|
my $epoch = shift; |
|
2459
|
12
|
50
|
|
|
|
20
|
return unless defined $epoch; |
|
2460
|
12
|
|
|
|
|
53
|
my ( $sec, $min, $hour, $mday, $mon, $year, $wday ) = gmtime($epoch+$tz_offset); |
|
2461
|
12
|
|
|
|
|
22
|
$year += 1900; |
|
2462
|
12
|
50
|
|
|
|
22
|
my $tz = $tz_offset ? sprintf( '%+03d%02d', $tz_hour, $tz_min ) : 'GMT'; |
|
2463
|
12
|
|
|
|
|
64
|
sprintf( '%s, %02d %s %04d %02d:%02d:%02d %s', |
|
2464
|
|
|
|
|
|
|
$DoW[$wday], $mday, $MoY[$mon], $year, $hour, $min, $sec, $tz ); |
|
2465
|
|
|
|
|
|
|
} |
|
2466
|
|
|
|
|
|
|
|
|
2467
|
|
|
|
|
|
|
sub rfc1123_to_w3cdtf { |
|
2468
|
101
|
|
|
101
|
|
8570
|
my $str = shift; |
|
2469
|
101
|
50
|
|
|
|
195
|
return unless defined $str; |
|
2470
|
101
|
|
|
|
|
819
|
my ( $mday, $mon, $year, $hour, $min, $sec, $tz ) = ( $str =~ $rfc1123_regexp ); |
|
2471
|
101
|
50
|
33
|
|
|
520
|
return unless ( $year && $mon && $mday ); |
|
|
|
|
33
|
|
|
|
|
|
2472
|
101
|
100
|
|
|
|
269
|
$year += 2000 if $year < 77; |
|
2473
|
101
|
100
|
|
|
|
184
|
$year += 1900 if $year < 100; |
|
2474
|
101
|
50
|
|
|
|
266
|
$mon = $MoY{ uc($mon) } or return; |
|
2475
|
101
|
100
|
66
|
|
|
387
|
if ( defined $tz && $tz ne '' && $tz ne 'GMT' ) { |
|
|
|
|
66
|
|
|
|
|
|
2476
|
64
|
|
|
|
|
121
|
my $off = &get_tz_offset($tz) / 60; |
|
2477
|
64
|
|
|
|
|
279
|
$tz = sprintf( '%+03d:%02d', $off/60, $off%60 ); |
|
2478
|
|
|
|
|
|
|
} |
|
2479
|
|
|
|
|
|
|
else { |
|
2480
|
37
|
|
|
|
|
70
|
$tz = 'Z'; |
|
2481
|
|
|
|
|
|
|
} |
|
2482
|
101
|
|
|
|
|
609
|
sprintf( '%04d-%02d-%02dT%02d:%02d:%02d%s', |
|
2483
|
|
|
|
|
|
|
$year, $mon, $mday, $hour, $min, $sec, $tz ); |
|
2484
|
|
|
|
|
|
|
} |
|
2485
|
|
|
|
|
|
|
|
|
2486
|
|
|
|
|
|
|
sub w3cdtf_to_rfc1123 { |
|
2487
|
51
|
|
|
51
|
|
69
|
my $str = shift; |
|
2488
|
51
|
50
|
|
|
|
103
|
return unless defined $str; |
|
2489
|
51
|
|
|
|
|
334
|
my ( $year, $mon, $mday, $hour, $min, $sec, $tz ) = ( $str =~ $w3cdtf_regexp ); |
|
2490
|
51
|
50
|
33
|
|
|
335
|
return unless ( $year > 1900 && $mon && $mday ); |
|
|
|
|
33
|
|
|
|
|
|
2491
|
51
|
|
100
|
|
|
125
|
$hour ||= 0; |
|
2492
|
51
|
|
100
|
|
|
84
|
$min ||= 0; |
|
2493
|
51
|
|
100
|
|
|
93
|
$sec ||= 0; |
|
2494
|
51
|
50
|
|
|
|
74
|
my $epoch = eval { Time::Local::timegm( $sec, $min, $hour, $mday, $mon-1, $year ) } |
|
|
51
|
|
|
|
|
169
|
|
|
2495
|
|
|
|
|
|
|
or return; |
|
2496
|
|
|
|
|
|
|
|
|
2497
|
51
|
|
|
|
|
1659
|
my $wday = ( gmtime($epoch) )[6]; |
|
2498
|
51
|
100
|
66
|
|
|
232
|
if ( defined $tz && $tz ne '' && $tz ne 'Z' ) { |
|
|
|
|
66
|
|
|
|
|
|
2499
|
35
|
|
|
|
|
79
|
my $off = &get_tz_offset($tz) / 60; |
|
2500
|
35
|
|
|
|
|
148
|
$tz = sprintf( '%+03d%02d', $off/60, $off%60 ); |
|
2501
|
|
|
|
|
|
|
} |
|
2502
|
|
|
|
|
|
|
else { |
|
2503
|
16
|
|
|
|
|
29
|
$tz = 'GMT'; |
|
2504
|
|
|
|
|
|
|
} |
|
2505
|
51
|
|
|
|
|
387
|
sprintf( |
|
2506
|
|
|
|
|
|
|
'%s, %02d %s %04d %02d:%02d:%02d %s', |
|
2507
|
|
|
|
|
|
|
$DoW[$wday], $mday, $MoY[ $mon - 1 ], $year, $hour, $min, $sec, $tz |
|
2508
|
|
|
|
|
|
|
); |
|
2509
|
|
|
|
|
|
|
} |
|
2510
|
|
|
|
|
|
|
|
|
2511
|
|
|
|
|
|
|
sub rfc1123_to_epoch { |
|
2512
|
52
|
|
|
52
|
|
5672
|
my $str = shift; |
|
2513
|
52
|
50
|
|
|
|
104
|
return unless defined $str; |
|
2514
|
52
|
|
|
|
|
436
|
my ( $mday, $mon, $year, $hour, $min, $sec, $tz ) = ( $str =~ $rfc1123_regexp ); |
|
2515
|
52
|
50
|
33
|
|
|
246
|
return unless ( $year && $mon && $mday ); |
|
|
|
|
33
|
|
|
|
|
|
2516
|
52
|
100
|
|
|
|
122
|
$year += 2000 if $year < 77; |
|
2517
|
52
|
100
|
|
|
|
83
|
$year += 1900 if $year < 100; |
|
2518
|
52
|
50
|
|
|
|
136
|
$mon = $MoY{ uc($mon) } or return; |
|
2519
|
52
|
50
|
|
|
|
64
|
my $epoch = eval { Time::Local::timegm( $sec, $min, $hour, $mday, $mon-1, $year ) } |
|
|
52
|
|
|
|
|
122
|
|
|
2520
|
|
|
|
|
|
|
or return; |
|
2521
|
52
|
|
|
|
|
1205
|
$epoch -= &get_tz_offset( $tz ); |
|
2522
|
52
|
|
|
|
|
123
|
$epoch; |
|
2523
|
|
|
|
|
|
|
} |
|
2524
|
|
|
|
|
|
|
|
|
2525
|
|
|
|
|
|
|
sub w3cdtf_to_epoch { |
|
2526
|
73
|
|
|
73
|
|
1648
|
my $str = shift; |
|
2527
|
73
|
50
|
|
|
|
124
|
return unless defined $str; |
|
2528
|
73
|
|
|
|
|
423
|
my ( $year, $mon, $mday, $hour, $min, $sec, $tz ) = ( $str =~ $w3cdtf_regexp ); |
|
2529
|
73
|
50
|
33
|
|
|
335
|
return unless ( $year > 1900 && $mon && $mday ); |
|
|
|
|
33
|
|
|
|
|
|
2530
|
73
|
|
50
|
|
|
141
|
$hour ||= 0; |
|
2531
|
73
|
|
50
|
|
|
114
|
$min ||= 0; |
|
2532
|
73
|
|
50
|
|
|
105
|
$sec ||= 0; |
|
2533
|
73
|
50
|
|
|
|
84
|
my $epoch = eval { Time::Local::timegm( $sec, $min, $hour, $mday, $mon-1, $year ) } |
|
|
73
|
|
|
|
|
195
|
|
|
2534
|
|
|
|
|
|
|
or return; |
|
2535
|
|
|
|
|
|
|
|
|
2536
|
73
|
|
|
|
|
1645
|
$epoch -= &get_tz_offset( $tz ); |
|
2537
|
73
|
|
|
|
|
243
|
$epoch; |
|
2538
|
|
|
|
|
|
|
} |
|
2539
|
|
|
|
|
|
|
|
|
2540
|
|
|
|
|
|
|
sub get_tz_offset { |
|
2541
|
224
|
|
|
224
|
|
303
|
my $tz = shift; |
|
2542
|
224
|
100
|
|
|
|
382
|
return 0 unless defined $tz; |
|
2543
|
166
|
100
|
|
|
|
330
|
return $tzmap->{$tz}*60*60 if exists $tzmap->{$tz}; |
|
2544
|
158
|
50
|
|
|
|
585
|
return 0 unless( $tz =~ m/^([\+\-]?)(\d+):?(\d{2})$/ ); |
|
2545
|
158
|
|
|
|
|
474
|
my( $pm, $ho, $mi ) = ( $1, $2, $3 ); |
|
2546
|
158
|
|
|
|
|
301
|
my $off = $ho * 60 + $mi; |
|
2547
|
158
|
100
|
|
|
|
303
|
$off *= ( $pm eq "-" ) ? -60 : 60; |
|
2548
|
158
|
|
|
|
|
284
|
$off; |
|
2549
|
|
|
|
|
|
|
} |
|
2550
|
|
|
|
|
|
|
|
|
2551
|
|
|
|
|
|
|
sub get_w3cdtf { |
|
2552
|
218
|
|
|
218
|
|
1901
|
my $date = shift; |
|
2553
|
218
|
100
|
|
|
|
386
|
return unless defined $date; |
|
2554
|
181
|
100
|
|
|
|
1932
|
if ( $date =~ /^\d+$/s ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
2555
|
6
|
|
|
|
|
13
|
return &epoch_to_w3cdtf($date); |
|
2556
|
|
|
|
|
|
|
} |
|
2557
|
|
|
|
|
|
|
elsif ( $date =~ $rfc1123_regexp ) { |
|
2558
|
81
|
|
|
|
|
185
|
return &rfc1123_to_w3cdtf($date); |
|
2559
|
|
|
|
|
|
|
} |
|
2560
|
|
|
|
|
|
|
elsif ( $date =~ $w3cdtf_regexp ) { |
|
2561
|
94
|
|
|
|
|
178
|
return $date; |
|
2562
|
|
|
|
|
|
|
} |
|
2563
|
0
|
|
|
|
|
0
|
undef; |
|
2564
|
|
|
|
|
|
|
} |
|
2565
|
|
|
|
|
|
|
|
|
2566
|
|
|
|
|
|
|
sub get_rfc1123 { |
|
2567
|
96
|
|
|
96
|
|
1715
|
my $date = shift; |
|
2568
|
96
|
50
|
|
|
|
167
|
return unless defined $date; |
|
2569
|
96
|
100
|
|
|
|
1085
|
if ( $date =~ /^\d+$/s ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
2570
|
3
|
|
|
|
|
10
|
return &epoch_to_rfc1123($date); |
|
2571
|
|
|
|
|
|
|
} |
|
2572
|
|
|
|
|
|
|
elsif ( $date =~ $rfc1123_regexp ) { |
|
2573
|
42
|
|
|
|
|
108
|
return $date; |
|
2574
|
|
|
|
|
|
|
} |
|
2575
|
|
|
|
|
|
|
elsif ( $date =~ $w3cdtf_regexp ) { |
|
2576
|
51
|
|
|
|
|
137
|
return &w3cdtf_to_rfc1123($date); |
|
2577
|
|
|
|
|
|
|
} |
|
2578
|
0
|
|
|
|
|
0
|
undef; |
|
2579
|
|
|
|
|
|
|
} |
|
2580
|
|
|
|
|
|
|
|
|
2581
|
|
|
|
|
|
|
sub get_epoch { |
|
2582
|
129
|
|
|
129
|
|
165
|
my $date = shift; |
|
2583
|
129
|
100
|
|
|
|
287
|
return unless defined $date; |
|
2584
|
97
|
50
|
|
|
|
882
|
if ( $date =~ /^\d+$/s ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
2585
|
0
|
|
|
|
|
0
|
return $date; |
|
2586
|
|
|
|
|
|
|
} |
|
2587
|
|
|
|
|
|
|
elsif ( $date =~ $rfc1123_regexp ) { |
|
2588
|
33
|
|
|
|
|
77
|
return &rfc1123_to_epoch($date); |
|
2589
|
|
|
|
|
|
|
} |
|
2590
|
|
|
|
|
|
|
elsif ( $date =~ $w3cdtf_regexp ) { |
|
2591
|
64
|
|
|
|
|
113
|
return &w3cdtf_to_epoch($date); |
|
2592
|
|
|
|
|
|
|
} |
|
2593
|
0
|
|
|
|
|
0
|
undef; |
|
2594
|
|
|
|
|
|
|
} |
|
2595
|
|
|
|
|
|
|
|
|
2596
|
|
|
|
|
|
|
sub merge_hash { |
|
2597
|
3
|
50
|
|
3
|
|
11
|
my $base = shift or return; |
|
2598
|
3
|
50
|
|
|
|
10
|
my $merge = shift or return; |
|
2599
|
|
|
|
|
|
|
|
|
2600
|
3
|
|
|
|
|
9
|
my %exclude = map { $_ => 1 } @_; |
|
|
0
|
|
|
|
|
0
|
|
|
2601
|
3
|
|
|
|
|
15
|
foreach my $key ( keys %$merge ) { |
|
2602
|
31
|
100
|
66
|
|
|
116
|
next if $exclude{$key} || exists $base->{$key}; |
|
2603
|
25
|
|
|
|
|
60
|
$base->{$key} = $merge->{$key}; |
|
2604
|
|
|
|
|
|
|
} |
|
2605
|
|
|
|
|
|
|
} |
|
2606
|
|
|
|
|
|
|
|
|
2607
|
|
|
|
|
|
|
sub param_even_odd { |
|
2608
|
556
|
100
|
|
556
|
|
1288
|
if ( (scalar @_) % 2 == 0 ) { |
|
2609
|
|
|
|
|
|
|
# even num of args - new( key1 => val1, key2 => arg2 ); |
|
2610
|
216
|
|
|
|
|
362
|
my $array = [ @_ ]; |
|
2611
|
216
|
|
|
|
|
509
|
return $array; |
|
2612
|
|
|
|
|
|
|
} |
|
2613
|
|
|
|
|
|
|
else { |
|
2614
|
|
|
|
|
|
|
# odd num of args - new( first, key1 => val1, key2 => arg2 ); |
|
2615
|
340
|
|
|
|
|
801
|
return ( undef, @_ ); |
|
2616
|
|
|
|
|
|
|
} |
|
2617
|
|
|
|
|
|
|
} |
|
2618
|
|
|
|
|
|
|
|
|
2619
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
|
2620
|
|
|
|
|
|
|
1; |
|
2621
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |