Mojolicious/Plugin/FeedReader.pm

filter: Statementstmt 98.5% 67 / 68 Branchbran 77.2% 17 / 22 Conditioncond 95.2% 20 / 21 MC/DCmcdc 90.0% 9 / 10 Subroutinesub 92.8% 13 / 14 Podpod 75.0% 3 / 4 totaltotal 92.8% 129 / 139 CC 21 SCAR 19.4
CC
21
Cov
94%
parse_rss
13.1
__ANON__
6.2
find_feeds
4.0
CRAP 6.9
↑ Summary Mojo/Feed/Reader.pm »
1 package Mojolicious::Plugin::FeedReader;
2 1 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use Mojo::Feed::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = "0.22";
7  
8 1 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶has feed_reader => sub { Mojo::Feed::Reader->new };
Subroutine __ANON__: not called CC=1 SCAR=1.2
11  
12 6 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
13 6 my $self = shift;
14 6 return $self->SUPER::new(feed_reader => Mojo::Feed::Reader->new(@_));
15 }
16  
17 4 ▶sub register {
Subroutine register: called CC=1 SCAR=0.0
Pod documented
18 4 my ($self, $app) = @_;
19 4 $self->feed_reader->ua($app->ua);
20 4 ▶ $app->helper(parse_feed => sub { shift; $self->parse_rss(@_); });
Subroutine __ANON__: called CC=1 SCAR=0.0
21 4 ▶ $app->helper(parse_rss => sub { shift; $self->parse_rss(@_); });
Subroutine __ANON__: called CC=1 SCAR=0.0
22 4 ▶ $app->helper(find_feeds => sub { shift; $self->find_feeds(@_); });
Subroutine __ANON__: called CC=1 SCAR=0.0
23 4 ▶ $app->helper(parse_opml => sub { shift; $self->feed_reader->parse_opml(@_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
24 }
25  
26 27 ▶sub parse_rss {
Subroutine parse_rss: called CC=13 SCAR=25.8
Pod undocumented
27 27 my $self = shift;
28 27 my @args = @_;
29  
30 # handle deprecated case of using Mojo::DOM as input
31 27 ▶ if (ref $args[0] && blessed $args[0] && $args[0]->isa('Mojo::DOM')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[0] and builtin::blessed($args[0]) and $args[0]->isa("Mojo::DOM")) 1 26 27
Condition100%6/6
ref $args[0] and builtin::blessed($args[0]) and $args[0]->isa("Mojo::DOM")
!ll&&!rl&&r
12141
ref $args[0] and builtin::blessed($args[0])
!ll&&!rl&&r
10215
MC/DC100%3/3
ref $args[0] and builtin::blessed($args[0]) and $args[0]->isa("Mojo::DOM")
ref $args[0] builtin::blessed($args[0]) $args[0]->isa("Mojo::DOM")
Truth table100%4/4
A and B and C
A= ref $args[0]B= builtin::blessed($args[0])C= $args[0]->isa("Mojo::DOM")
ABCresult
0XX0
10X0
1100
1111
32 1 $args[0] = $args[0]->to_string();
33 }
34  
35 # handle special case of being passed a callback - make non-blocking call
36 27 ▶ if ( ref $args[0]
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[0] and builtin::blessed($args[0]) and $args[0]->isa('Mojo::URL') and ref $args[1] and ref $args[1] eq 'CODE') { } 2 25 27
Condition91%11/12
ref $args[0] and builtin::blessed($args[0]) and $args[0]->isa("Mojo::URL") and ref $args[1] and ref $args[1] eq "CODE"
!ll&&!rl&&r
2502
ref $args[0] and builtin::blessed($args[0]) and $args[0]->isa("Mojo::URL") and ref $args[1]
!ll&&!rl&&r
2142
ref $args[0] and builtin::blessed($args[0]) and $args[0]->isa("Mojo::URL")
!ll&&!rl&&r
1386
ref $args[0] and builtin::blessed($args[0])
!ll&&!rl&&r
11214
MC/DC80%4/5
ref $args[0] and builtin::blessed($args[0]) and $args[0]->isa("Mojo::URL") and ref $args[1] and ref $args[1] eq "CODE"
ref $args[0] builtin::blessed($args[0]) $args[0]->isa("Mojo::URL") ref $args[1] ref $args[1] eq "CODE"
Truth table83%5/6
A and B and C and D and E
A= ref $args[0]B= builtin::blessed($args[0])C= $args[0]->isa("Mojo::URL")D= ref $args[1]E= ref $args[1] eq "CODE"
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
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 1 ▶ sub {
Subroutine __ANON__: called CC=6 SCAR=18.3
45 1 my $tx = pop;
46 1 my $feed = undef;
47 1 my $result = $tx->result;
48 1 ▶ if ($result->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->is_success) 1 0 1
49 1 my $feed_obj = $self->feed_reader->parse($result->body,
50 $result->content->charset);
51 1 ▶ if ($feed_obj) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feed_obj) 1 0 1
52 1 $feed = $feed_obj->to_hash;
53 1 $feed->{'htmlUrl'} = delete $feed->{'link'};
54 1 ▶ for (keys %$feed) { delete $feed->{$_} if ($feed->{$_} eq '') };
Branch: 1 branch
BranchTrueFalseTotal
if $feed->{$_} eq "" 0 7 7
55 1 ▶ delete $feed->{'items'} if (scalar @{$feed->{'items'}} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$feed->{"items"};} == 0 0 1 1
56 }
57 }
58 1 $args[1]->($feed);
59 }
60 2 );
61 }
62 else {
63 25 my $feed_obj = $self->feed_reader->parse(@args);
64 25 ▶ return undef unless ($feed_obj);
Branch: 1 branch
BranchTrueFalseTotal
unless $feed_obj 2 23 25
65 23 my $feed = $feed_obj->to_hash;
66 23 $feed->{'htmlUrl'} = delete $feed->{'link'};
67 23 ▶ for (keys %$feed) { delete $feed->{$_} if ($feed->{$_} eq '') };
Branch: 1 branch
BranchTrueFalseTotal
if $feed->{$_} eq "" 32 129 161
68 23 ▶ delete $feed->{'items'} if (scalar @{$feed->{'items'}} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$feed->{"items"};} == 0 0 23 23
69 23 return $feed;
70 }
71 }
72  
73 13 ▶sub find_feeds {
Subroutine find_feeds: called CC=4 SCAR=13.9
Pod documented
74 13 my $self = shift;
75 13 my $cb;
76 13 ▶ if (ref $_[-1] && ref $_[-1] eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[-1] and ref $_[-1] eq "CODE") 3 10 13
Condition100%3/3
ref $_[-1] and ref $_[-1] eq "CODE"
!ll&&!rl&&r
913
MC/DC100%2/2
ref $_[-1] and ref $_[-1] eq "CODE"
ref $_[-1] ref $_[-1] eq "CODE"
Truth table100%3/3
A and B
A= ref $_[-1]B= ref $_[-1] eq "CODE"
ABresult
0X0
100
111
77 3 $cb = pop @_;
78 }
79 13 my $promise = $self->feed_reader->discover(@_);
80 13 ▶ if ($cb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb) { } 3 10 13
81 3 return $promise->then($cb);
82 }
83 else {
84 10 my @res;
85 10 ▶ $promise->then(sub { @res = @_; })->wait;
Subroutine __ANON__: called CC=1 SCAR=0.0
86 10 return @res;
87 }
88 }
89  
90 1 1;
91  
92 __END__
↑ Summary Mojo/Feed/Reader.pm »