line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::LinkEmbedder::Link::Text::Pastie; |
2
|
1
|
|
|
1
|
|
2431
|
use Mojo::Base 'Mojolicious::Plugin::LinkEmbedder::Link::Text'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
has media_id => sub { |
5
|
|
|
|
|
|
|
local $_ = shift->url->path->to_string; |
6
|
|
|
|
|
|
|
return $1 if m!(?:pastes/)?(\d+)!; |
7
|
|
|
|
|
|
|
return ''; |
8
|
|
|
|
|
|
|
}; |
9
|
|
|
|
|
|
|
|
10
|
0
|
|
|
0
|
0
|
|
sub provider_name {'pastie.com'} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub learn { |
13
|
0
|
|
|
0
|
0
|
|
my ($self, $c, $cb) = @_; |
14
|
0
|
0
|
|
|
|
|
my $raw_url = $self->raw_url or return $self->SUPER::learn($c, $cb); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$self->ua->get( |
17
|
|
|
|
|
|
|
$raw_url, |
18
|
|
|
|
|
|
|
sub { |
19
|
0
|
|
|
0
|
|
|
my ($ua, $tx) = @_; |
20
|
0
|
0
|
|
|
|
|
if ($tx->success) { |
21
|
0
|
|
|
|
|
|
$self->{text} = $tx->res->dom->at('pre')->content; |
22
|
0
|
|
|
|
|
|
$self->{text} =~ s! !\n!g; |
23
|
0
|
|
|
|
|
|
$self->{text} =~ s!
|
24
|
|
|
|
|
|
|
} |
25
|
0
|
|
|
|
|
|
$self->$cb; |
26
|
|
|
|
|
|
|
}, |
27
|
0
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub pretty_url { |
31
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
32
|
0
|
0
|
|
|
|
|
my $media_id = $self->media_id or return $self->SUPER::pretty_url; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
Mojo::URL->new("http://pastie.org/pastes/$media_id"); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub raw_url { |
38
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
39
|
0
|
0
|
|
|
|
|
my $media_id = $self->media_id or return; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
Mojo::URL->new("http://pastie.org/pastes/$media_id/text"); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |