File Coverage

blib/lib/Mojolicious/Plugin/LinkEmbedder/Link/Image/Imgur.pm
Criterion Covered Total %
statement 3 17 17.6
branch 0 2 0.0
condition 0 7 0.0
subroutine 1 6 16.6
pod 0 3 0.0
total 4 35 11.4


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::LinkEmbedder::Link::Image::Imgur;
2 1     1   2267 use Mojo::Base 'Mojolicious::Plugin::LinkEmbedder::Link::Image';
  1         2  
  1         6  
3              
4             has media_id => sub { shift->url->path->[0] };
5 0     0 0   sub provider_name {'Imgur'}
6             has [qw( 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           my $dom = $tx->res->dom;
19 0   0       $self->media_url(Mojo::URL->new(($dom->at('meta[property="og:image"]') || {})->{content}));
20 0   0       $self->media_title(($dom->at('meta[property="og:title"]') || {})->{content});
21 0           $self->$cb;
22             },
23 0           );
24 0 0         $delay->wait unless $delay->ioloop->is_running;
25             }
26              
27             sub to_embed {
28 0     0 0   my $self = shift;
29              
30 0   0       $self->tag(
31             img => src => $self->media_url,
32             alt => $self->media_title || $self->media_url,
33             title => $self->media_title
34             );
35             }
36              
37             1;