line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::LinkEmbedder::Link::Image::Xkcd; |
2
|
1
|
|
|
1
|
|
460
|
use Mojo::Base 'Mojolicious::Plugin::LinkEmbedder::Link::Image'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
has media_id => sub { shift->url->path->[0] }; |
5
|
0
|
|
|
0
|
1
|
|
sub provider_name {'Xkcd'} |
6
|
|
|
|
|
|
|
has [qw( media_hover_text media_url media_title )]; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub learn { |
9
|
0
|
|
|
0
|
1
|
|
my ($self, $c, $cb) = @_; |
10
|
0
|
|
|
|
|
|
my $ua = $self->{ua}; |
11
|
|
|
|
|
|
|
my $delay = Mojo::IOLoop->delay( |
12
|
|
|
|
|
|
|
sub { |
13
|
0
|
|
|
0
|
|
|
my $delay = shift; |
14
|
0
|
|
|
|
|
|
$ua->get($self->url, $delay->begin); |
15
|
|
|
|
|
|
|
}, |
16
|
|
|
|
|
|
|
sub { |
17
|
0
|
|
|
0
|
|
|
my ($ua, $tx) = @_; |
18
|
0
|
|
0
|
|
|
|
my $link = $tx->res->dom->at('#comic img') || {}; |
19
|
0
|
0
|
|
|
|
|
$self->media_url(Mojo::URL->new($link->{src})) if $link->{src}; |
20
|
0
|
|
0
|
|
|
|
$self->media_title($link->{alt} || $link->{title} || $self->url); |
21
|
0
|
|
0
|
|
|
|
$self->media_hover_text($link->{title} || $self->media_title); |
22
|
0
|
|
|
|
|
|
$self->$cb; |
23
|
|
|
|
|
|
|
}, |
24
|
0
|
|
|
|
|
|
); |
25
|
0
|
0
|
|
|
|
|
$delay->wait unless $delay->ioloop->is_running; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub to_embed { |
29
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
$self->tag(img => src => $self->media_url, alt => $self->media_title, title => $self->media_hover_text); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=encoding utf8 |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 NAME |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Mojolicious::Plugin::LinkEmbedder::Link::Image::Xkcd - xkcd.com image/comic |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This class inherits from L. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 media_hover_text |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
The secret part of xkcd jokes |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 media_id |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Extracts the media_id from the url directly |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 media_url |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
URL to the image itself, extracted from the retrieved page |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 media_title |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
The title of the image, extracted from the retrieved page |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 provider_name |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 METHODS |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 learn |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Gets the file imformation from the page meta information |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 to_embed |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Returns an img tag. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 AUTHOR |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Joel Berger - C |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |