Data/Parser/Base.pm

filter: Statementstmt 79.2% 42 / 53 Branchbran 50.0% 7 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 2 totaltotal 73.4% 58 / 79 CC 10 SCAR 23.2
CC
10
Cov
73%
first_image_tag
30.0
__ANON__
6.0
BEGIN
1.0
CRAP 10.2
↑ Summary Data/Parser.pm »
1 package Feed::Data::Parser::Base;
2  
3 12 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use Feed::Data::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Compiled::Params::OO qw/cpo/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use HTML::LinkExtor;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 12 ▶use Types::Standard qw/Object ScalarRef Str HashRef ArrayRef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 our $validate;
11 BEGIN {
12 12 ▶ $validate = cpo(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 parse => [Object],
14 first_image_tag => [Object, Str]
15 );
16 }
17  
18 12 has 'content_ref' => (
19 is => 'rw',
20 lazy => 1,
21 isa => ScalarRef
22 default => q{},
23 );
24  
25 12 has 'parser' => (
26 is => 'rw',
27 isa => Object|HashRef,
28 lazy => 1,
29 );
30  
31 has 'potential_fields' => (
32 is => 'rw',
33 isa => HashRef,
34 lazy => 1,
35 default => sub {
36 return {
37 9 ▶ title => 'title',
Subroutine __ANON__: called CC=1 SCAR=0.0
38 description => 'description',
39 date => 'pubDate',
40 author => 'author',
41 category => 'category',
42 permalink => 'permaLink',
43 comment => 'comments',
44 link => 'link',
45 content => 'content',
46 image => 'image',
47 };
48 },
49 12 );
50  
51 has 'feed' => (
52 is => 'rw',
53 isa => ArrayRef,
54 lazy => 1,
55 default => sub {
56 13 ▶ my $self = shift;
Subroutine __ANON__: called CC=6 SCAR=18.0
57 13 my @feed;
58 13 foreach my $item ( @{ $self->parser->{items} } ) {
59 24 my %args;
60 24 my $potential = $self->potential_fields;
61 24 ▶ while (my ($field, $action) = each %{ $potential }) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$potential;}) 240 24 264
62 240 my $value;
63 240 ▶ if ($value = $self->get_value($item, $action)){
Branch: 2 branches
BranchTrueFalseTotal
if ($value = $self->get_value($item, $action)) { } 149 91 240
elsif ($action eq 'image') { } 22 69 91
64 149 $args{$field} = $value;
65 }
66 elsif ($action eq 'image') {
67 22 my $content = $self->get_value($item, 'content');
68 22 ▶ if ( $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) { } 0 22 22
69 0 $value = $self->first_image_tag($content);
70 0 $args{$field} = $value;
71 }
72 else {
73 22 next;
74 }
75 }
76 }
77 24 my $object = Feed::Data::Object->new(object => \%args);
78 24 push @feed, $object;
79 }
80 13 return \@feed;
81 },
82 12 );
83  
84 sub parse {
85 13 ▶ my ($self) = $validate->parse->(@_);
Subroutine parse: called CC=1 SCAR=0.0
Pod undocumented
86 13 return $self->feed;
87 }
88  
89 sub first_image_tag {
90 0 ▶ my ($self, $content) = $validate->first_image_tag->(@_);
Subroutine first_image_tag: not called CC=5 SCAR=34.0
Pod undocumented
91 0 my $p = HTML::LinkExtor->new;
92 0 $p->parse($content);
93 0 my @links = $p->links;
94 0 for (@links) {
95 0 ▶ my ($img, %attr) = @$_ if $_->[0] eq 'img';
Branch: 1 branch
BranchTrueFalseTotal
if $_->[0] eq "img" 0 0 0
96 0 ▶ if ($img) {
Branch: 1 branch
BranchTrueFalseTotal
if ($img) 0 0 0
97 0 ▶ next if $attr{src} =~ m{twitter|facebook|google|pinterest|tumblr|linkedin};
Branch: 1 branch
BranchTrueFalseTotal
if $attr{"src"} =~ /twitter|facebook|google|pinterest|tumblr|linkedin/ 0 0 0
98 0 return $attr{src};
99 }
100 }
101 }
102  
103 12 1; # End of Feed::Data
104  
105 __END__
↑ Summary Data/Parser.pm »