summaryrefslogtreecommitdiffstats
path: root/lib/Crawl/Bot/Role/RSS.pm
blob: 7a0177e9bf5702e3d5aca38972f63e84a420f592 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package Crawl::Bot::Role::RSS;
use Moose::Role;

use XML::RAI;
use Try::Tiny;

with 'Crawl::Bot::Role::CachedItems';

requires 'rss_feed';

sub current_items {
    my $self = shift;
    my $rss = try { XML::RAI->parse_uri($self->rss_feed) } catch { warn $_ };
    return unless ref($rss) eq 'ARRAY';
    # after the XML::RAI object goes out of scope, the item objects become
    # worthless. how dumb. capture the relevant data in some hashrefs instead.
    return map {
        my $item = $_;
        +{
            map { $_ => $item->$_ }
                qw(identifier title link creator)
         }
    } @{ $rss->items };
}

no Moose::Role;

1;