File Coverage

blib/lib/Mojolicious/Plugin/LinkEmbedder/Link/Image/Xkcd.pm
Criterion Covered Total %
statement 3 18 16.6
branch 0 4 0.0
condition 0 8 0.0
subroutine 1 6 16.6
pod 0 3 0.0
total 4 39 10.2


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::LinkEmbedder::Link::Image::Xkcd;
2 1     1   1869 use Mojo::Base 'Mojolicious::Plugin::LinkEmbedder::Link::Image';
  1         3  
  1         5  
3              
4             has media_id => sub { shift->url->path->[0] };
5 0     0 0   sub provider_name {'Xkcd'}
6             has [qw( media_hover_text media_url media_title )];
7              
8             sub learn {
9 0     0 0   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 0   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;