| 1 |
NAME |
| 2 |
AnyEvent::Feed - Receiving RSS/Atom Feed reader with XML::Feed |
| 3 |
|
| 4 |
VERSION |
| 5 |
Version 0.3 |
| 6 |
|
| 7 |
SYNOPSIS |
| 8 |
use AnyEvent; |
| 9 |
use AnyEvent::Feed; |
| 10 |
|
| 11 |
my $feed_reader = |
| 12 |
AnyEvent::Feed->new ( |
| 13 |
url => 'http://example.com/atom.xml', |
| 14 |
); |
| 15 |
|
| 16 |
$feed_reader->fetch (sub { |
| 17 |
my ($feed_reader, $new_entries, $feed, $error) = @_; |
| 18 |
|
| 19 |
if (defined $error) { |
| 20 |
warn "ERROR: $error\n"; |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
# $feed is the XML::Feed object belonging to that fetch. |
| 25 |
|
| 26 |
for (@$new_entries) { |
| 27 |
my ($hash, $entry) = @$_; |
| 28 |
# $hash a unique hash describing the $entry |
| 29 |
# $entry is the XML::Feed::Entry object of the new entries |
| 30 |
# since the last fetch. |
| 31 |
} |
| 32 |
}); |
| 33 |
|
| 34 |
# Or: |
| 35 |
|
| 36 |
my $feed_reader = |
| 37 |
AnyEvent::Feed->new ( |
| 38 |
url => 'http://example.com/atom.xml', |
| 39 |
interval => $seconds, |
| 40 |
|
| 41 |
on_fetch => sub { |
| 42 |
my ($feed_reader, $new_entries, $feed, $error) = @_; |
| 43 |
|
| 44 |
if (defined $error) { |
| 45 |
warn "ERROR: $error\n"; |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
# see above |
| 50 |
} |
| 51 |
); |
| 52 |
|
| 53 |
DESCRIPTION |
| 54 |
This module implements some glue between AnyEvent::HTTP and XML::Feed. |
| 55 |
It can fetch a RSS/Atom feed on a regular interval as well as on |
| 56 |
customized times. It also keeps track of already fetched entries so that |
| 57 |
you will only get the new entries. |
| 58 |
|
| 59 |
METHODS |
| 60 |
$feed_reader = AnyEvent::Feed->new (url => $url, %args) |
| 61 |
This is the constructor for a new feed reader for the RSS/Atom feed |
| 62 |
reachable by the URL $url. %args may contain additional key/value |
| 63 |
pairs: |
| 64 |
|
| 65 |
interval => $seconds |
| 66 |
If this is set you also have to specify the "on_fetch" callback |
| 67 |
(see below). It will try to fetch the $url every $seconds |
| 68 |
seconds and call the callback given by "on_fetch" with the |
| 69 |
result. |
| 70 |
|
| 71 |
headers => $http_hdrs |
| 72 |
Additional HTTP headers for each GET request can be passed in |
| 73 |
the $http_hdrs hash reference, just like you would pass it to |
| 74 |
the "headers" argument of the "http_get" request of |
| 75 |
AnyEvent::HTTP. |
| 76 |
|
| 77 |
username => $http_user |
| 78 |
password => $http_pass |
| 79 |
These are the HTTP username and password that will be used for |
| 80 |
Basic HTTP Authentication with the HTTP server when fetching the |
| 81 |
feed. This is mostly sugar for you so you don't have to encode |
| 82 |
them yourself and pass them to the "headers" argument above. |
| 83 |
|
| 84 |
on_fetch => $cb->($feed_reader, $new_entries, $feed_obj, $error) |
| 85 |
This callback is called if the "interval" parameter is given |
| 86 |
(see above) with the same arguments as the callback given to the |
| 87 |
"fetch" method (see below). |
| 88 |
|
| 89 |
entry_ages => $hash |
| 90 |
This will set the hash which keeps track of seen and old |
| 91 |
entries. See also the documentation of the "entry_ages" method |
| 92 |
below. The default will be an empty hash reference. |
| 93 |
|
| 94 |
max_entry_age => $count |
| 95 |
This will set the maximum number of times an entry is kept in |
| 96 |
the "entry_ages" hash after it has not been seen in the feed |
| 97 |
anymore. The default value is 2 which means that an entry hash |
| 98 |
is removed from the "entry_ages" hash after it has not been seen |
| 99 |
in the feed for 2 fetches. |
| 100 |
|
| 101 |
$feed_reader->url |
| 102 |
Just returns the url that this feed reader is fetching from. |
| 103 |
|
| 104 |
$feed_reader->entry_ages ($new_entry_ages) |
| 105 |
my $entry_ages = $feed_reader->entry_ages |
| 106 |
This will set the age hash which will keep track of already seen |
| 107 |
entries. The keys of the hash will be the calculated hashes of the |
| 108 |
entries and the values will be a counter of how often they have NOT |
| 109 |
been seen anymore (kind of an age counter). After each fetch this |
| 110 |
hash is updated and seen entries get a value of 0. |
| 111 |
|
| 112 |
$feed_reader->fetch ($cb->($feed_reader, $new_entries, $feed_obj, |
| 113 |
$error)) |
| 114 |
This will initiate a HTTP GET on the URL passed to "new" and call |
| 115 |
$cb when done. |
| 116 |
|
| 117 |
$feed_reader is the feed reader object itself. $new_entries is an |
| 118 |
array reference containing the new entries. A new entry in that |
| 119 |
array is another array containing a calculated hash over the |
| 120 |
contents of the new entry, and the XML::Feed::Entry object of that |
| 121 |
entry. $feed_obj is the XML::Feed feed object used to parse the |
| 122 |
fetched feed and contains all entries (and not just the 'new' ones). |
| 123 |
|
| 124 |
What a 'new' entry is, is decided by a map of hashes as described in |
| 125 |
the "entry_ages" method's documentation above. |
| 126 |
|
| 127 |
AUTHOR |
| 128 |
Robin Redeker, "<[email protected]>" |
| 129 |
|
| 130 |
SEE ALSO |
| 131 |
XML::Feed |
| 132 |
|
| 133 |
AnyEvent::HTTP |
| 134 |
|
| 135 |
AnyEvent |
| 136 |
|
| 137 |
BUGS |
| 138 |
Known Bugs |
| 139 |
There is actually a known bug with encodings of contents of Atom feeds. |
| 140 |
XML::Atom by default gives you UTF-8 encoded data. You have to set this |
| 141 |
global variable to be able to use the XML::Feed::Entry interface without |
| 142 |
knowledge of the underlying feed type: |
| 143 |
|
| 144 |
$XML::Atom::ForceUnicode = 1; |
| 145 |
|
| 146 |
I've re-reported this bug against XML::Feed, as I think it should take |
| 147 |
care of this. XML::Atom should probably just fix it's Unicode interface, |
| 148 |
but it seems to be a bit deserted w.r.t. fixing the bugs in the tracker. |
| 149 |
|
| 150 |
Contact |
| 151 |
Please report any bugs or feature requests to "bug-anyevent-feed at |
| 152 |
rt.cpan.org", or through the web interface at |
| 153 |
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-Feed>. I will |
| 154 |
be notified and then you'll automatically be notified of progress on |
| 155 |
your bug as I make changes. |
| 156 |
|
| 157 |
SUPPORT |
| 158 |
You can find documentation for this module with the perldoc command. |
| 159 |
|
| 160 |
perldoc AnyEvent::Feed |
| 161 |
|
| 162 |
You can also look for information at: |
| 163 |
|
| 164 |
* IRC: AnyEvent::Feed IRC Channel |
| 165 |
|
| 166 |
See the same channel as the AnyEvent::XMPP module: |
| 167 |
|
| 168 |
IRC Network: http://freenode.net/ |
| 169 |
Server : chat.freenode.net |
| 170 |
Channel : #ae_xmpp |
| 171 |
|
| 172 |
Feel free to join and ask questions! |
| 173 |
|
| 174 |
* AnnoCPAN: Annotated CPAN documentation |
| 175 |
|
| 176 |
<http://annocpan.org/dist/AnyEvent-Feed> |
| 177 |
|
| 178 |
* CPAN Ratings |
| 179 |
|
| 180 |
<http://cpanratings.perl.org/d/AnyEvent-Feed> |
| 181 |
|
| 182 |
* RT: CPAN's request tracker |
| 183 |
|
| 184 |
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-Feed> |
| 185 |
|
| 186 |
* Search CPAN |
| 187 |
|
| 188 |
<http://search.cpan.org/dist/AnyEvent-Feed> |
| 189 |
|
| 190 |
COPYRIGHT & LICENSE |
| 191 |
Copyright 2009 Robin Redeker, all rights reserved. |
| 192 |
|
| 193 |
This program is free software; you can redistribute it and/or modify it |
| 194 |
under the same terms as Perl itself. |
| 195 |
|