| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Feed::Data::Parser::Base; |
|
2
|
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
6173
|
use Moo; |
|
|
11
|
|
|
|
|
40
|
|
|
|
11
|
|
|
|
|
60
|
|
|
4
|
11
|
|
|
11
|
|
3965
|
use Feed::Data::Object; |
|
|
11
|
|
|
|
|
37
|
|
|
|
11
|
|
|
|
|
169
|
|
|
5
|
11
|
|
|
11
|
|
435
|
use Compiled::Params::OO qw/cpo/; |
|
|
11
|
|
|
|
|
22
|
|
|
|
11
|
|
|
|
|
76
|
|
|
6
|
11
|
|
|
11
|
|
6695
|
use HTML::LinkExtor; |
|
|
11
|
|
|
|
|
27846
|
|
|
|
11
|
|
|
|
|
143
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
11
|
|
|
11
|
|
425
|
use Types::Standard qw/Object ScalarRef Str HashRef ArrayRef/; |
|
|
11
|
|
|
|
|
22
|
|
|
|
11
|
|
|
|
|
85
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $validate; |
|
11
|
|
|
|
|
|
|
BEGIN { |
|
12
|
11
|
|
|
11
|
|
11925
|
$validate = cpo( |
|
13
|
|
|
|
|
|
|
parse => [Object], |
|
14
|
|
|
|
|
|
|
first_image_tag => [Object, Str] |
|
15
|
|
|
|
|
|
|
); |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'content_ref' => ( |
|
21
|
|
|
|
|
|
|
is => 'rw', |
|
22
|
|
|
|
|
|
|
lazy => 1, |
|
23
|
|
|
|
|
|
|
isa => ScalarRef |
|
24
|
|
|
|
|
|
|
default => q{}, |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'parser' => ( |
|
28
|
|
|
|
|
|
|
is => 'rw', |
|
29
|
|
|
|
|
|
|
isa => Object|HashRef, |
|
30
|
|
|
|
|
|
|
lazy => 1, |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'potential_fields' => ( |
|
34
|
|
|
|
|
|
|
is => 'rw', |
|
35
|
|
|
|
|
|
|
isa => HashRef, |
|
36
|
|
|
|
|
|
|
lazy => 1, |
|
37
|
|
|
|
|
|
|
default => sub { |
|
38
|
|
|
|
|
|
|
return { |
|
39
|
|
|
|
|
|
|
title => 'title', |
|
40
|
|
|
|
|
|
|
description => 'description', |
|
41
|
|
|
|
|
|
|
date => 'pubDate', |
|
42
|
|
|
|
|
|
|
author => 'author', |
|
43
|
|
|
|
|
|
|
category => 'category', |
|
44
|
|
|
|
|
|
|
permalink => 'permaLink', |
|
45
|
|
|
|
|
|
|
comment => 'comments', |
|
46
|
|
|
|
|
|
|
link => 'link', |
|
47
|
|
|
|
|
|
|
content => 'content', |
|
48
|
|
|
|
|
|
|
image => 'image', |
|
49
|
|
|
|
|
|
|
}; |
|
50
|
|
|
|
|
|
|
}, |
|
51
|
|
|
|
|
|
|
); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has 'feed' => ( |
|
54
|
|
|
|
|
|
|
is => 'rw', |
|
55
|
|
|
|
|
|
|
isa => ArrayRef, |
|
56
|
|
|
|
|
|
|
lazy => 1, |
|
57
|
|
|
|
|
|
|
default => sub { |
|
58
|
|
|
|
|
|
|
my $self = shift; |
|
59
|
|
|
|
|
|
|
my @feed; |
|
60
|
|
|
|
|
|
|
foreach my $item ( @{ $self->parser->{items} } ) { |
|
61
|
|
|
|
|
|
|
my %args; |
|
62
|
|
|
|
|
|
|
my $potential = $self->potential_fields; |
|
63
|
|
|
|
|
|
|
while (my ($field, $action) = each %{ $potential }) { |
|
64
|
|
|
|
|
|
|
my $value; |
|
65
|
|
|
|
|
|
|
if ($value = $self->get_value($item, $action)){ |
|
66
|
|
|
|
|
|
|
$args{$field} = $value; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
elsif ($action eq 'image') { |
|
69
|
|
|
|
|
|
|
my $content = $self->get_value($item, 'content'); |
|
70
|
|
|
|
|
|
|
if ( $content ) { |
|
71
|
|
|
|
|
|
|
$value = $self->first_image_tag($content); |
|
72
|
|
|
|
|
|
|
$args{$field} = $value; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
else { |
|
75
|
|
|
|
|
|
|
next; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
my $object = Feed::Data::Object->new(object => \%args); |
|
80
|
|
|
|
|
|
|
push @feed, $object; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
return \@feed; |
|
83
|
|
|
|
|
|
|
}, |
|
84
|
|
|
|
|
|
|
); |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub parse { |
|
87
|
12
|
|
|
12
|
0
|
93
|
my ($self) = $validate->parse->(@_); |
|
88
|
12
|
|
|
|
|
374
|
return $self->feed; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub first_image_tag { |
|
92
|
0
|
|
|
0
|
0
|
|
my ($self, $content) = $validate->first_image_tag->(@_); |
|
93
|
0
|
|
|
|
|
|
my $p = HTML::LinkExtor->new; |
|
94
|
0
|
|
|
|
|
|
$p->parse($content); |
|
95
|
0
|
|
|
|
|
|
my @links = $p->links; |
|
96
|
0
|
|
|
|
|
|
for (@links) { |
|
97
|
0
|
0
|
|
|
|
|
my ($img, %attr) = @$_ if $_->[0] eq 'img'; |
|
98
|
0
|
0
|
|
|
|
|
if ($img) { |
|
99
|
0
|
0
|
|
|
|
|
next if $attr{src} =~ m{twitter|facebook|google|pinterest|tumblr|linkedin}; |
|
100
|
0
|
|
|
|
|
|
return $attr{src}; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; # End of Feed::Data |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |