lib/MojoMojo/Formatter/Gist.pm

filter: Statementstmt 90.9% 30 / 33 Branchbran 75.0% 6 / 8 Conditioncond 55.5% 5 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 79.6% 51 / 64 CC 9 SCAR 14.9
CC
9
Cov
82%
process
7.0
format_content
4.0
BEGIN
1.0
CRAP 4.5
« lib/MojoMojo/Formatter/TOC.pm ↑ Summary lib/MojoMojo/Formatter/GoogleSearch.pm »
1 package MojoMojo::Formatter::Gist;
2 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use parent qw/MojoMojo::Formatter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 MojoMojo::Formatter::Gist - Embed Gist script
9  
10 =head1 DESCRIPTION
11  
12 Embed Gist script by writing {{gist <id>}}.
13  
14 if you write:
15  
16 {{gist 618402}}
17  
18 it will be formatted, like this
19  
20 <script src="https://gist.github.com/618402.js"></script>
21  
22 then you can see the syntax highlighted source code.
23  
24 =head1 METHODS
25  
26 =head2 format_content_order
27  
28 The Gist formatter has no special requirements
29 in terms of the order it gets run in, so it has a priority of 17.
30  
31 =cut
32  
33 744 ▶sub format_content_order { 17 }
Subroutine format_content_order: called CC=1 SCAR=0.0
Pod documented
34  
35 =head2 format_content
36  
37 Calls the formatter. Takes a ref to the content as well as the context object.
38  
39 =cut
40  
41 129 ▶sub format_content {
Subroutine format_content: called CC=4 SCAR=13.9
Pod documented
42 129 my ( $class, $content, $c ) = @_;
43  
44 129 ▶ return unless $$content;
Branch: 1 branch
BranchTrueFalseTotal
unless $$content 0 129 129
45  
46 129 my @lines = split /\n/, $$content;
47 129 $$content = '';
48  
49 129 my $re = $class->gen_re( qr/gist\s+(\d+)/ );
50  
51 129 for my $line (@lines) {
52 735 ▶ if ( $line =~ m/$re/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$re/) 3 732 735
53 3 $line = $class->process($c, $line, $re, $1);
54 }
55 735 $$content .= $line . "\n";
56 }
57  
58 }
59  
60 =head2 process
61  
62 Here the actual formatting is done.
63  
64 =cut
65 3 ▶sub process {
Subroutine process: called CC=6 SCAR=19.5
Pod documented
66 3 my ( $class, $c, $line, $re, $id) = @_;
67  
68 3 my $gist = $c->loc('Gist Script');
69  
70 3 ▶ if (!$id || $id !~ /^\d+$/){
Branch: 1 branch
BranchTrueFalseTotal
unless ($id and $id =~ /^\d+$/) 0 3 3
Condition33%1/3
$id and $id =~ /^\d+$/
!ll&&!rl&&r
003
MC/DC0%0/2
$id and $id =~ /^\d+$/
$id $id =~ /^\d+$/
Truth table33%1/3
A and B
A= $idB= $id =~ /^\d+$/
ABresult
0X0
100
111
71 0 $line =~ s/$re/"$gist: $id ". $c->loc('is not a valid id')/e;
72 0 return $line;
73 }
74  
75 3 my $url = "https://gist.github.com/$id";
76  
77 3 my $ar = $c->action->reverse;
78 3 ▶ if ( $ar && ($ar eq 'pageadmin/edit' || $ar eq 'jsrpc/render') ){
Branch: 1 branch
BranchTrueFalseTotal
if ($ar and $ar eq 'pageadmin/edit' || $ar eq 'jsrpc/render') { } 2 1 3
Condition66%4/6
$ar and $ar eq "pageadmin/edit" || $ar eq "jsrpc/render"
!ll&&!rl&&r
102
$ar eq "pageadmin/edit" or $ar eq "jsrpc/render"
l!l&&r!l&&!r
110
MC/DC33%1/3
$ar and $ar eq "pageadmin/edit" || $ar eq "jsrpc/render"
$ar $ar eq "pageadmin/edit" $ar eq "jsrpc/render"
Truth table75%3/4
A and B or C
A= $arB= $ar eq "pageadmin/edit"C= $ar eq "jsrpc/render"
ABCresult
0XX0
1000
11X1
1011
79 2 $line =~ s!$re!<div style='width: 95%;height: 90px; border: 1px black dotted;'>$gist - <a href="$url">gist:$id</a></div>!;
80 2 $c->stash->{precompile_off} = 1;
81 } else {
82 1 $line =~ s!$re!<script src="$url.js"></script>!;
83 }
84  
85 3 return $line;
86 }
87  
88  
89 =head1 SEE ALSO
90  
91 L<MojoMojo> and L<Module::Pluggable::Ordered>.
92 Gist is <https://gist.github.com/>.
93  
94 =head1 AUTHORS
95  
96 Dai Okabayashi, L<bayashi at cpan . org>
97  
98 =head1 LICENSE
99  
100 This library is free software. You can redistribute it and/or modify
101 it under the same terms as Perl itself.
102  
103 =cut
104  
105 27 1;
« lib/MojoMojo/Formatter/TOC.pm ↑ Summary lib/MojoMojo/Formatter/GoogleSearch.pm »