File Coverage

blib/lib/Mojolicious/Plugin/LinkEmbedder/Link/Text/Pastebin.pm
Criterion Covered Total %
statement 3 13 23.0
branch 0 6 0.0
condition n/a
subroutine 1 5 20.0
pod 0 3 0.0
total 4 27 14.8


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::LinkEmbedder::Link::Text::Pastebin;
2 1     1   1708 use Mojo::Base 'Mojolicious::Plugin::LinkEmbedder::Link::Text';
  1         2  
  1         6  
3              
4             has media_id => sub {
5             shift->url->path =~ m!^/?(\w+)! ? $1 : '';
6             };
7              
8 0     0 0   sub provider_name {'pastebin.com'}
9              
10             sub learn {
11 0     0 0   my ($self, $c, $cb) = @_;
12 0 0         my $raw_url = $self->raw_url or return $self->SUPER::learn($c, $cb);
13              
14             $self->ua->get(
15             $raw_url,
16             sub {
17 0     0     my ($ua, $tx) = @_;
18 0 0         $self->{text} = Mojo::Util::xml_escape($tx->res->body) if $tx->success;
19 0           $self->$cb;
20             },
21 0           );
22             }
23              
24             sub raw_url {
25 0     0 0   my $self = shift;
26 0 0         my $media_id = $self->media_id or return;
27              
28 0           Mojo::URL->new('http://pastebin.com/raw.php')->query(i => $media_id);
29             }
30              
31             1;