line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::LinkEmbedder::Link::Text::HTML; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Mojolicious::Plugin::LinkEmbedder::Link::Text::HTML - HTML document |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
This class inherits from L. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
369
|
use Mojo::Base 'Mojolicious::Plugin::LinkEmbedder::Link::Text'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
12
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 audio |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 canon_url |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Holds the content from "og:url" meta tag. Fallback to |
22
|
|
|
|
|
|
|
L. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head2 description |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Holds the content from "og:description" meta tag. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 image |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Holds the content from "og:image" or "og:image:url" meta tag. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 title |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Holds the content from "og:title" meta tag or the "title" tag. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 type |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Holds the content from "og:type" meta tag. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 video |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Holds the content from "og:video" meta tag. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has audio => ''; |
47
|
|
|
|
|
|
|
has canon_url => sub { shift->url }; |
48
|
|
|
|
|
|
|
has description => ''; |
49
|
|
|
|
|
|
|
has image => ''; |
50
|
|
|
|
|
|
|
has title => ''; |
51
|
|
|
|
|
|
|
has type => ''; |
52
|
|
|
|
|
|
|
has video => ''; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 METHODS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 learn |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub learn { |
61
|
4
|
|
|
4
|
1
|
28
|
my ($self, $c, $cb) = @_; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$self->ua->get( |
64
|
|
|
|
|
|
|
$self->url, |
65
|
|
|
|
|
|
|
sub { |
66
|
4
|
|
|
4
|
|
15034
|
my ($ua, $tx) = @_; |
67
|
4
|
50
|
|
|
|
20
|
my $dom = $tx->success ? $tx->res->dom : undef; |
68
|
4
|
50
|
|
|
|
3939
|
$self->_tx($tx)->_learn_from_dom($dom) if $dom; |
69
|
4
|
|
|
|
|
88
|
$self->$cb; |
70
|
|
|
|
|
|
|
}, |
71
|
4
|
|
|
|
|
60
|
); |
72
|
|
|
|
|
|
|
|
73
|
4
|
|
|
|
|
5344
|
$self; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 to_embed |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Returns data about the HTML page in a div tag. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub to_embed { |
83
|
5
|
|
|
5
|
1
|
6
|
my $self = shift; |
84
|
|
|
|
|
|
|
|
85
|
5
|
100
|
|
|
|
10
|
if ($self->image) { |
86
|
|
|
|
|
|
|
return $self->tag( |
87
|
|
|
|
|
|
|
div => class => 'link-embedder text-html', |
88
|
|
|
|
|
|
|
sub { |
89
|
|
|
|
|
|
|
return join( |
90
|
|
|
|
|
|
|
'', |
91
|
|
|
|
|
|
|
$self->tag( |
92
|
|
|
|
|
|
|
div => class => 'link-embedder-media', |
93
|
4
|
|
|
|
|
11
|
sub { $self->tag(img => src => $self->image, alt => $self->title) } |
94
|
|
|
|
|
|
|
), |
95
|
|
|
|
|
|
|
$self->tag(h3 => $self->title), |
96
|
|
|
|
|
|
|
$self->tag(p => $self->description), |
97
|
|
|
|
|
|
|
$self->tag( |
98
|
|
|
|
|
|
|
div => class => 'link-embedder-link', |
99
|
|
|
|
|
|
|
sub { |
100
|
4
|
|
|
|
|
8
|
$self->tag(a => href => $self->canon_url, title => $self->canon_url, $self->canon_url); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
) |
103
|
4
|
|
|
4
|
|
20
|
); |
104
|
|
|
|
|
|
|
} |
105
|
4
|
|
|
|
|
47
|
); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
1
|
|
|
|
|
14
|
return $self->SUPER::to_embed(@_); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _learn_from_dom { |
112
|
4
|
|
|
4
|
|
207
|
my ($self, $dom) = @_; |
113
|
4
|
|
|
|
|
4
|
my $e; |
114
|
|
|
|
|
|
|
|
115
|
4
|
50
|
|
|
|
16
|
$self->audio($e->{content}) if $e = $dom->at('meta[property="og:audio"]'); |
116
|
|
|
|
|
|
|
|
117
|
4
|
50
|
33
|
|
|
2200
|
$self->description($e->{content} || $e->{value}) |
|
|
|
66
|
|
|
|
|
118
|
|
|
|
|
|
|
if $e = $dom->at('meta[property="og:description"]') || $dom->at('meta[name="twitter:description"]'); |
119
|
|
|
|
|
|
|
|
120
|
4
|
100
|
33
|
|
|
1295
|
$self->image($e->{content} || $e->{value}) |
|
|
|
100
|
|
|
|
|
121
|
|
|
|
|
|
|
if $e |
122
|
|
|
|
|
|
|
= $dom->at('meta[property="og:image"]') |
123
|
|
|
|
|
|
|
|| $dom->at('meta[property="og:image:url"]') |
124
|
|
|
|
|
|
|
|| $dom->at('meta[name="twitter:image"]'); |
125
|
|
|
|
|
|
|
|
126
|
4
|
50
|
50
|
|
|
2381
|
$self->title($e->{content} || $e->{value} || $e->text || '') |
|
|
|
66
|
|
|
|
|
127
|
|
|
|
|
|
|
if $e = $dom->at('meta[property="og:title"]') || $dom->at('meta[name="twitter:title"]') || $dom->at('title'); |
128
|
|
|
|
|
|
|
|
129
|
4
|
100
|
66
|
|
|
2157
|
$self->type($e->{content}) if $e = $dom->at('meta[property="og:type"]') || $dom->at('meta[name="twitter:card"]'); |
130
|
4
|
50
|
|
|
|
2694
|
$self->video($e->{content}) if $e = $dom->at('meta[property="og:video"]'); |
131
|
4
|
50
|
33
|
|
|
1593
|
$self->canon_url($e->{content} || $e->{value}) |
|
|
|
66
|
|
|
|
|
132
|
|
|
|
|
|
|
if $e = $dom->at('meta[property="og:url"]') || $dom->at('meta[name="twitter:url"]'); |
133
|
4
|
50
|
33
|
|
|
1773
|
$self->media_id($self->canon_url) if $self->canon_url and !defined $self->{media_id}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Jan Henning Thorsen - C |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |