lib/MojoMojo/Formatter/CPANHyperlink.pm

filter: Statementstmt 100% 15 / 15 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 100% 2 / 2 totaltotal 100% 22 / 22 CC 2 SCAR 4.1
CC
2
Cov
100%
format_content
2.0
BEGIN
1.0
format_content_order
1.0
CRAP 1.5
« lib/MojoMojo/Schema/ResultSet/Attachment.pm ↑ Summary lib/MojoMojo/Formatter/Main.pm »
1 package MojoMojo::Formatter::CPANHyperlink;
2  
3 27 ▶use parent qw/MojoMojo::Formatter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 MojoMojo::Formatter::CPANHyperlink - automatically hyperlink CPAN modules when
8 using the syntax {{cpan Some::Module}}
9  
10 =head1 DESCRIPTION
11  
12 Normally, to hyperlink to a CPAN module, you'd write:
13  
14 [MojoMojo::Formatter::CPANHyperlink](http://search.cpan.org/perldoc?MojoMojo::Formatter::CPANHyperlink)
15  
16 This plugin lets you write just
17  
18 {{cpan MojoMojo::Formatter::CPANHyperlink}}
19  
20 Just like POD, it supports adding a section after the module name:
21  
22 {{cpan Catalyst::Manual::Cookbook/Deployment}}
23  
24 will create a link to
25  
26 http://search.cpan.org/perldoc?Catalyst::Manual::Cookbook#Deployment
27  
28 Sections can contain any characters, except two consecutive closed braces:
29  
30 {{cpan Catalyst::Test/($res, $c) = ctx request( ... ); }}
31  
32 will link to
33  
34 http://search.cpan.org/perldoc?Catalyst::Test#($res,_$c)_=_ctx_request(_..._);
35  
36 In anticipation of future plugin syntax, you can optionally add a trailing slash
37  
38 {{cpan Some::Module/Section /}}
39  
40 =head1 METHODS
41  
42 =head2 format_content_order
43  
44 The CPANHyperlink formatter has no special requirements in terms of the order
45 it gets run in, so it has a priority of 10.
46  
47 =cut
48  
49 868 ▶sub format_content_order { 10 }
Subroutine format_content_order: called CC=1 SCAR=0.0
Pod documented
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 132 ▶sub format_content {
Subroutine format_content: called CC=2 SCAR=6.9
Pod documented
58 132 my ( $class, $content ) = @_;
59  
60 132 my $component = qr/(?:[_[:alpha:]]\w*)/;
61 132 my $cpan_module = qr[ $component (?: ::$component )* ]x;
62 132 my $section = qr[ .*? (?= \s* /? }} ) ]x;
63  
64 132 $$content =~ s[
65 \{\{cpan \s+ ($cpan_module) (?: / ($section))? \s* \/? }}
66 ] [
67 14 my ($module, $section) = ($1, $2);
68 14 ▶ if (defined $section) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $section) { } 2 12 14
69 2 (my $anchor=$section) =~ s/\s/_/g;
70 2 qq(<a href="http://search.cpan.org/perldoc?$module#$anchor" class="external">$section in $module</a>)
71 } else {
72 12 qq(<a href="http://search.cpan.org/perldoc?$module" class="external">$module</a>)
73 }
74 ]eixg;
75 }
76  
77  
78 =head1 SEE ALSO
79  
80 L<MojoMojo> and L<Module::Pluggable::Ordered>.
81  
82 =head1 AUTHORS
83  
84 Dan Dascalescu, L<http://dandascalescu.com>
85  
86 =head1 LICENSE
87  
88 This library is free software. You can redistribute it and/or modify
89 it under the same terms as Perl itself.
90  
91 =cut
92  
93 27 1;
« lib/MojoMojo/Schema/ResultSet/Attachment.pm ↑ Summary lib/MojoMojo/Formatter/Main.pm »