line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::LinkEmbedder::Link::Text::Pastie; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Mojolicious::Plugin::LinkEmbedder::Link::Text::Pastie - pastie.org link |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
This class inherit from L. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 OUTPUT HTML |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
This is an example output: |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$txt |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
434
|
use Mojo::Base 'Mojolicious::Plugin::LinkEmbedder::Link::Text'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 media_id |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$str = $self->media_id; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has media_id => sub { |
30
|
|
|
|
|
|
|
local $_ = shift->url->path->to_string; |
31
|
|
|
|
|
|
|
return $1 if m!(?:pastes/)?(\d+)!; |
32
|
|
|
|
|
|
|
return ''; |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 provider_name |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
0
|
1
|
|
sub provider_name {'pastie.com'} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 METHODS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 learn |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub learn { |
48
|
0
|
|
|
0
|
1
|
|
my ($self, $c, $cb) = @_; |
49
|
0
|
0
|
|
|
|
|
my $raw_url = $self->raw_url or return $self->SUPER::learn($c, $cb); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$self->ua->get( |
52
|
|
|
|
|
|
|
$raw_url, |
53
|
|
|
|
|
|
|
sub { |
54
|
0
|
|
|
0
|
|
|
my ($ua, $tx) = @_; |
55
|
0
|
0
|
|
|
|
|
if ($tx->success) { |
56
|
0
|
|
|
|
|
|
$self->{text} = $tx->res->dom->at('pre')->content; |
57
|
0
|
|
|
|
|
|
$self->{text} =~ s! !\n!g; |
58
|
0
|
|
|
|
|
|
$self->{text} =~ s!
|
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
$self->$cb; |
61
|
|
|
|
|
|
|
}, |
62
|
0
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 pretty_url |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub pretty_url { |
70
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
71
|
0
|
0
|
|
|
|
|
my $media_id = $self->media_id or return $self->SUPER::pretty_url; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
Mojo::URL->new("http://pastie.org/pastes/$media_id"); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 raw_url |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub raw_url { |
81
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
82
|
0
|
0
|
|
|
|
|
my $media_id = $self->media_id or return; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
Mojo::URL->new("http://pastie.org/pastes/$media_id/text"); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 AUTHOR |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Jan Henning Thorsen |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |