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