summaryrefslogtreecommitdiff
path: root/lib/Feed/Role/LinkedPage.pm
blob: 694e4c10dea0f3407e32fd46d38580354b65a028 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package Feed::Role::LinkedPage; 
use Moose::Role;
use 5.012;
use namespace::autoclean;
use XML::Feed::Content;
 
=head1 NAME
 
Feed::Role::LinkedPage - fetch the linked resource instead of using
the RSS summary
 
=head1 SYNOPSIS
 
    set_feed_class(Feed->with_traits(
        'Mail',
        'LinkedPage',
        'ContentOnly',
    ));
 
If your feed only has summaries or only the first paragraph, maybe you
want to fetch the complete HTML page for processing.
 
=cut
 
around extract_entries => sub {
    my ($orig$self) = @_;
 
    $self->log->trace('around extract_entries - begin');
 
    # Fetch the linked HTML page from the feed instead of 
    # using the content of the feed itself 
 
    my $entries$self->$orig();
    splice @$entries, 2;
 
    for my $entry (@{ $entries }) {
        $self->log->trace('around extract_entries - fetching ' . $entry->link);
        my $res$self->user_agent->get( $entry->link );
        if$res->is_success and $res->decoded_content ) {
            my $c= XML::Feed::Content->wrap({
                type => $res->header( 'Content-Type' ),
                body => $res->decoded_content,
                base => $entry->link,
            });
            $entry->content( $c );
        };
    };
 
    $self->log->trace('around extract_entries - end');
    $entries
};
 
1;