line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::FeedReader; |
2
|
1
|
|
|
1
|
|
657015
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
6
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
683
|
use Mojo::Feed::Reader; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
8
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.20"; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
57
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1043
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has feed_reader => sub { Mojo::Feed::Reader->new }; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
6
|
|
|
6
|
1
|
55176
|
my $self = shift; |
14
|
6
|
|
|
|
|
63
|
return $self->SUPER::new(feed_reader => Mojo::Feed::Reader->new(@_)); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub register { |
18
|
4
|
|
|
4
|
1
|
81
|
my ($self, $app) = @_; |
19
|
4
|
|
|
|
|
18
|
$self->feed_reader->ua($app->ua); |
20
|
4
|
|
|
20
|
|
122
|
$app->helper(parse_feed => sub { shift; $self->parse_rss(@_); }); |
|
20
|
|
|
|
|
117120
|
|
|
20
|
|
|
|
|
103
|
|
21
|
4
|
|
|
1
|
|
448
|
$app->helper(parse_rss => sub { shift; $self->parse_rss(@_); }); |
|
1
|
|
|
|
|
305
|
|
|
1
|
|
|
|
|
5
|
|
22
|
4
|
|
|
13
|
|
247
|
$app->helper(find_feeds => sub { shift; $self->find_feeds(@_); }); |
|
13
|
|
|
|
|
103368
|
|
|
13
|
|
|
|
|
60
|
|
23
|
4
|
|
|
3
|
|
247
|
$app->helper(parse_opml => sub { shift; $self->feed_reader->parse_opml(@_) }); |
|
3
|
|
|
|
|
26304
|
|
|
3
|
|
|
|
|
18
|
|
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub parse_rss { |
27
|
27
|
|
|
27
|
0
|
5061
|
my $self = shift; |
28
|
27
|
|
|
|
|
71
|
my @args = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# handle deprecated case of using Mojo::DOM as input |
31
|
27
|
100
|
100
|
|
|
346
|
if (ref $args[0] && blessed $args[0] && $args[0]->isa('Mojo::DOM')) { |
|
|
|
100
|
|
|
|
|
32
|
1
|
|
|
|
|
5
|
$args[0] = $args[0]->to_string(); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# handle special case of being passed a callback - make non-blocking call |
36
|
27
|
100
|
100
|
|
|
2357
|
if ( ref $args[0] |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
37
|
|
|
|
|
|
|
&& blessed $args[0] |
38
|
|
|
|
|
|
|
&& $args[0]->isa('Mojo::URL') |
39
|
|
|
|
|
|
|
&& ref $args[1] |
40
|
|
|
|
|
|
|
&& ref $args[1] eq 'CODE') |
41
|
|
|
|
|
|
|
{ |
42
|
|
|
|
|
|
|
$self->feed_reader->ua->get( |
43
|
|
|
|
|
|
|
$args[0], |
44
|
|
|
|
|
|
|
sub { |
45
|
2
|
|
|
2
|
|
20792
|
my $tx = pop; |
46
|
2
|
|
|
|
|
7
|
my $feed = undef; |
47
|
2
|
|
|
|
|
8
|
my $result = $tx->result; |
48
|
2
|
50
|
|
|
|
57
|
if ($result->is_success) { |
49
|
2
|
|
|
|
|
38
|
my $feed_obj = $self->feed_reader->parse($result->body, |
50
|
|
|
|
|
|
|
$result->content->charset); |
51
|
2
|
50
|
|
|
|
9756
|
if ($feed_obj) { |
52
|
2
|
|
|
|
|
16
|
$feed = $feed_obj->to_hash; |
53
|
2
|
|
|
|
|
12
|
$feed->{'htmlUrl'} = delete $feed->{'link'}; |
54
|
2
|
50
|
|
|
|
19
|
for (keys %$feed) { delete $feed->{$_} if ($feed->{$_} eq '') }; |
|
14
|
|
|
|
|
37
|
|
55
|
2
|
50
|
|
|
|
8
|
delete $feed->{'items'} if (scalar @{$feed->{'items'}} == 0); |
|
2
|
|
|
|
|
120
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
2
|
|
|
|
|
18
|
$args[1]->($feed); |
59
|
|
|
|
|
|
|
} |
60
|
2
|
|
|
|
|
10
|
); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
25
|
|
|
|
|
113
|
my $feed_obj = $self->feed_reader->parse(@args); |
64
|
25
|
100
|
|
|
|
367375
|
return undef unless ($feed_obj); |
65
|
23
|
|
|
|
|
173
|
my $feed = $feed_obj->to_hash; |
66
|
23
|
|
|
|
|
95
|
$feed->{'htmlUrl'} = delete $feed->{'link'}; |
67
|
23
|
100
|
|
|
|
133
|
for (keys %$feed) { delete $feed->{$_} if ($feed->{$_} eq '') }; |
|
161
|
|
|
|
|
386
|
|
68
|
23
|
50
|
|
|
|
67
|
delete $feed->{'items'} if (scalar @{$feed->{'items'}} == 0); |
|
23
|
|
|
|
|
94
|
|
69
|
23
|
|
|
|
|
4612
|
return $feed; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub find_feeds { |
74
|
13
|
|
|
13
|
1
|
28
|
my $self = shift; |
75
|
13
|
|
|
|
|
22
|
my $cb; |
76
|
13
|
100
|
100
|
|
|
84
|
if (ref $_[-1] && ref $_[-1] eq 'CODE') { |
77
|
3
|
|
|
|
|
11
|
$cb = pop @_; |
78
|
|
|
|
|
|
|
} |
79
|
13
|
|
|
|
|
53
|
my $promise = $self->feed_reader->discover(@_); |
80
|
13
|
100
|
|
|
|
27445
|
if ($cb) { |
81
|
3
|
|
|
|
|
13
|
$promise->then($cb); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
10
|
|
|
|
|
20
|
my @res; |
85
|
10
|
|
|
10
|
|
52
|
$promise->then(sub { @res = @_; })->wait; |
|
10
|
|
|
|
|
5936
|
|
86
|
10
|
|
|
|
|
2553
|
return @res; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |