| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MojoMojo::Formatter::IDLink; |
|
2
|
27
|
|
|
27
|
|
70287
|
use strict; |
|
|
27
|
|
|
|
|
70
|
|
|
|
27
|
|
|
|
|
968
|
|
|
3
|
27
|
|
|
27
|
|
136
|
use warnings; |
|
|
27
|
|
|
|
|
63
|
|
|
|
27
|
|
|
|
|
627
|
|
|
4
|
27
|
|
|
27
|
|
448
|
use parent qw/MojoMojo::Formatter/; |
|
|
27
|
|
|
|
|
269
|
|
|
|
27
|
|
|
|
|
138
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
MojoMojo::Formatter::IDLink - Linked {{id:<service name> <word>}} |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=cut |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $CONF = { |
|
13
|
|
|
|
|
|
|
tw => 'http://twitter.com/%s', |
|
14
|
|
|
|
|
|
|
htb => 'http://b.hatena.ne.jp/%s', |
|
15
|
|
|
|
|
|
|
htd => 'http://d.hatena.ne.jp/%s', |
|
16
|
|
|
|
|
|
|
cpan => 'http://search.cpan.org/~%s/', |
|
17
|
|
|
|
|
|
|
fb => 'http://facebook.com/%s', |
|
18
|
|
|
|
|
|
|
}; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $DEFAULT = 'tw'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if you write: |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
{{id bayashi}} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
it will format like this |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
<a href="http://twitter.com/bayashi">bayashi</a> |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
you can write: |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
{{id:cpan bayashi}} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
it will format like this |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
<a href="http://search.cpan.org/~bayashi/">bayashi</a> |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 METHODS |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 format_content_order |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
The IDLink formatter has no special requirements |
|
45
|
|
|
|
|
|
|
in terms of the order it gets run in, so it has a priority of 10. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
|
|
49
|
868
|
|
|
868
|
1
|
2360
|
sub format_content_order { 10 } |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 format_content |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Calls the formatter. Takes a ref to the content as well as the context object. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub format_content { |
|
58
|
129
|
|
|
129
|
1
|
16231
|
my ( $class, $content, $c ) = @_; |
|
59
|
|
|
|
|
|
|
|
|
60
|
129
|
50
|
|
|
|
492
|
return unless $$content; |
|
61
|
|
|
|
|
|
|
|
|
62
|
129
|
|
|
|
|
629
|
my @lines = split /\n/, $$content; |
|
63
|
129
|
|
|
|
|
353
|
$$content = ''; |
|
64
|
|
|
|
|
|
|
|
|
65
|
129
|
|
|
|
|
677
|
my $re = $class->gen_re( qr/id(?::([^\s]+))?\s+(.+)/ ); |
|
66
|
|
|
|
|
|
|
|
|
67
|
129
|
|
|
|
|
485
|
for my $line (@lines) { |
|
68
|
653
|
100
|
|
|
|
2201
|
if ( $line =~ m/$re/ ) { |
|
69
|
5
|
|
|
|
|
18
|
$line = $class->process($c, $line, $re, $1, $2); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
653
|
|
|
|
|
1517
|
$$content .= $line . "\n"; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 process |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Here the actual formatting is done. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
|
81
|
|
|
|
|
|
|
sub process { |
|
82
|
5
|
|
|
5
|
1
|
9
|
my $class = shift; |
|
83
|
5
|
|
|
|
|
20
|
my ($c, $line, $re, $site, $id) = @_; |
|
84
|
|
|
|
|
|
|
|
|
85
|
5
|
|
66
|
|
|
17
|
$site ||= $DEFAULT; |
|
86
|
|
|
|
|
|
|
|
|
87
|
5
|
50
|
|
|
|
16
|
unless ($CONF->{$site}) { |
|
88
|
0
|
|
|
|
|
0
|
my $sites = join ',', keys %{$CONF}; |
|
|
0
|
|
|
|
|
0
|
|
|
89
|
0
|
|
|
|
|
0
|
$line =~ s/$re/"IDLink: ". $c->loc('identifier is wrong.'). " use [$sites]"/e; |
|
|
0
|
|
|
|
|
0
|
|
|
90
|
0
|
|
|
|
|
0
|
return $line; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
5
|
|
|
|
|
21
|
my $url = sprintf($CONF->{$site}, $id); |
|
94
|
|
|
|
|
|
|
|
|
95
|
5
|
|
|
|
|
38
|
$line =~ s!$re!<a href="$url">$id</a>!; |
|
96
|
|
|
|
|
|
|
|
|
97
|
5
|
|
|
|
|
18
|
return $line; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L<MojoMojo> and L<Module::Pluggable::Ordered>. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 AUTHORS |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Dai Okabayashi, L<bayashi at cpan . org> |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 LICENSE |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This library is free software. You can redistribute it and/or modify |
|
112
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |