LinkEmbedder/Link/OpenSUSE.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 48 CC 3 SCAR 14.6
CC
3
Cov
0%
learn_p
6.0
_fetch_paste
6.0
_parse_paste
2.0
CRAP 4.3
1 package LinkEmbedder::Link::OpenSUSE;
2 use Mojo::Base 'LinkEmbedder::Link';
3  
4 use constant DEBUG => $ENV{LINK_EMBEDDER_DEBUG} || 0;
5  
6 has provider_name => 'openSUSE';
7 has _paste => undef;
8  
9 sub learn_p {
10 my $self = shift;
11 my $url = $self->url;
12 my $fetch = $url->host eq 'paste.opensuse.org' && @{$url->path} && $url->path->[-1] =~ /^(\d+)$/;
13  
14 return $fetch ? $self->_fetch_paste($1) : $self->SUPER::learn_p;
15 }
16  
17 sub _fetch_paste {
18 my ($self, $paste_id) = @_;
19 my $raw_url = $self->url->clone;
20  
21 $raw_url->path(sprintf '/view/raw/%s', $paste_id);
22 warn "[LinkEmbedder] openSUSE paste URL $raw_url\n" if DEBUG;
23 return $self->title("Paste $paste_id")->type("rich")->_get_p($raw_url)->then(sub { $self->_parse_paste(shift) });
24 }
25  
26 sub _parse_paste {
27 my ($self, $tx) = @_;
28 $self->{paste} = $tx->res->body;
29 $self->template->[1] = 'paste.html.ep';
30 return $self;
31 }
32  
33 1;