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