line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::LinkEmbedder::Link::Text::Pastie; |
2
|
1
|
|
|
1
|
|
626
|
use Mojo::Base 'Mojolicious::Plugin::LinkEmbedder::Link::Text'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
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
|
1
|
|
sub provider_name {'pastie.com'} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub learn { |
13
|
0
|
|
|
0
|
1
|
|
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
|
1
|
|
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
|
1
|
|
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; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=encoding utf8 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Mojolicious::Plugin::LinkEmbedder::Link::Text::Pastie - pastie.org link |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This class inherit from L. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 OUTPUT HTML |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This is an example output: |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$txt |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 media_id |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$str = $self->media_id; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 provider_name |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 METHODS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 learn |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 pretty_url |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 raw_url |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 AUTHOR |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Jan Henning Thorsen |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |