line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
9608
|
use strictures 1; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
25
|
|
2
|
|
|
|
|
|
|
package Mojito::Filter::Shortcuts; |
3
|
|
|
|
|
|
|
{ |
4
|
|
|
|
|
|
|
$Mojito::Filter::Shortcuts::VERSION = '0.24'; |
5
|
|
|
|
|
|
|
} |
6
|
1
|
|
|
1
|
|
80
|
use Moo::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
1273
|
use MooX::Types::MooseLike::Base qw(:all); |
|
1
|
|
|
|
|
6757
|
|
|
1
|
|
|
|
|
498
|
|
8
|
1
|
|
|
1
|
|
623
|
use Mojito::Model::MetaCPAN; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use 5.010; |
10
|
|
|
|
|
|
|
use Data::Dumper::Concise; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with('Mojito::Role::Config'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has shortcuts => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
isa => ArrayRef, |
17
|
|
|
|
|
|
|
lazy => 1, |
18
|
|
|
|
|
|
|
builder => '_build_shortcuts', |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
sub _build_shortcuts { |
21
|
|
|
|
|
|
|
my $self = shift; |
22
|
|
|
|
|
|
|
my @shortcuts = qw( |
23
|
|
|
|
|
|
|
cpan_URL |
24
|
|
|
|
|
|
|
metacpan_module_URL |
25
|
|
|
|
|
|
|
metacpan_author_URL |
26
|
|
|
|
|
|
|
internal_URL |
27
|
|
|
|
|
|
|
gist_URL |
28
|
|
|
|
|
|
|
cpan_recent_synopses |
29
|
|
|
|
|
|
|
cpan_synopsis); |
30
|
|
|
|
|
|
|
push @shortcuts, 'fonality_ticket' if ($self->config->{fonality_ticket_url}); |
31
|
|
|
|
|
|
|
return \@shortcuts; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 Methods |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 expand_shortcuts |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Expand the available shortcuts into the content. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub expand_shortcuts { |
43
|
|
|
|
|
|
|
my ($self, $content) = @_; |
44
|
|
|
|
|
|
|
foreach my $shortcut ( @{$self->shortcuts} ) { |
45
|
|
|
|
|
|
|
$content = $self->${shortcut}(${content}); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
return $content; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 cpan_URL |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Expand the cpan abbreviated shortcut. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub cpan_URL { |
57
|
|
|
|
|
|
|
my ($self, $content) = @_; |
58
|
|
|
|
|
|
|
return if !$content; |
59
|
|
|
|
|
|
|
$content =~ s/\{\{cpan\s+([^}]*)}}/<a href="http:\/\/search.cpan.org\/perldoc?$1">$1<\/a>/sig; |
60
|
|
|
|
|
|
|
return $content; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 gist_URL |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Expand the gist.github.com abbreviated shortcut. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub gist_URL { |
70
|
|
|
|
|
|
|
my ($self, $content) = @_; |
71
|
|
|
|
|
|
|
return if !$content; |
72
|
|
|
|
|
|
|
$content =~ s/\{\{gist\s+([^}]*)}}/<script src="https:\/\/gist.github.com\/$1.js"><\/script>/sig; |
73
|
|
|
|
|
|
|
return $content; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
has metacpan => ( |
77
|
|
|
|
|
|
|
is => 'ro', |
78
|
|
|
|
|
|
|
lazy => 1, |
79
|
|
|
|
|
|
|
default => sub { Mojito::Model::MetaCPAN->new }, |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 cpan_synopsis |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Show the CPAN SYNOPSIS for a Perl Module |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub cpan_synopsis { |
89
|
|
|
|
|
|
|
my ($self, $content) = @_; |
90
|
|
|
|
|
|
|
return if !$content; |
91
|
|
|
|
|
|
|
$content =~ s/\{\{cpan.synopsis\s+([^}]*)}}/$self->metacpan->get_synopsis_formatted($1, 'presentation')/esig; |
92
|
|
|
|
|
|
|
return $content; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 cpan_recent_synopses |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Show the synopses of the CPAN recent releases |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub cpan_recent_synopses { |
102
|
|
|
|
|
|
|
my ($self, $content) = @_; |
103
|
|
|
|
|
|
|
return if !$content; |
104
|
|
|
|
|
|
|
$content =~ s/\{\{cpan.synopses.recent\s*(\d+)}}/$self->metacpan->get_recent_synopses($1)/esig; |
105
|
|
|
|
|
|
|
return $content; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
=head2 metacpan_module_URL |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Expand the cpan abbreviated shortcut. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub metacpan_module_URL { |
114
|
|
|
|
|
|
|
my ($self, $content) = @_; |
115
|
|
|
|
|
|
|
return if !$content; |
116
|
|
|
|
|
|
|
$content =~ s|\{\{metacpan\s+([^}]*)}}|<a href="http://metacpan.org/module/$1">$1</a>|sig; |
117
|
|
|
|
|
|
|
return $content; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
=head2 metacpan_module_URL |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Expand the cpan abbreviated shortcut. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub metacpan_author_URL { |
126
|
|
|
|
|
|
|
my ($self, $content) = @_; |
127
|
|
|
|
|
|
|
return if !$content; |
128
|
|
|
|
|
|
|
$content =~ s|\{\{metacpan.author\s+([^}]*)}}|<a href="http://metacpan.org/author/$1">$1</a>|sig; |
129
|
|
|
|
|
|
|
return $content; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 internal_URL |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Expand an internal URL |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub internal_URL { |
140
|
|
|
|
|
|
|
my ($self, $content) = @_; |
141
|
|
|
|
|
|
|
return if !$content; |
142
|
|
|
|
|
|
|
my ($base_url, $path_info, $http_referer, $http_host) = @{$self->config}{qw/base_url PATH_INFO HTTP_REFERER HTTP_HOST/}; |
143
|
|
|
|
|
|
|
my $add_link = sub { |
144
|
|
|
|
|
|
|
my ($link, $title) = @_; |
145
|
|
|
|
|
|
|
# Strip ending slash as we only append the base_url to link starting with a slash |
146
|
|
|
|
|
|
|
$base_url =~ s|/$||; |
147
|
|
|
|
|
|
|
if ($link !~ m|^/|) { |
148
|
|
|
|
|
|
|
# If we have a path_info of /preview then we want to use the |
149
|
|
|
|
|
|
|
# referred instead as the path_info. |
150
|
|
|
|
|
|
|
if ($path_info eq '/preview') { |
151
|
|
|
|
|
|
|
# create path info from where the post came |
152
|
|
|
|
|
|
|
($path_info) = $http_referer =~ m|${http_host}${base_url}(.*)/edit$|; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
$path_info = ($path_info =~ m|/$|) ? $path_info : $path_info . '/'; |
155
|
|
|
|
|
|
|
$base_url .= $path_info; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
return "<a href='${base_url}${link}'>${title}</a>"; |
158
|
|
|
|
|
|
|
}; |
159
|
|
|
|
|
|
|
$content =~ s/\[\[([^\|]*)\|([^\]]*)\]\]/$add_link->($1,$2)/esig; |
160
|
|
|
|
|
|
|
return $content; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1 |