lib/Lip/Pod.pm

filter: Statementstmt 100% 44 / 44 Branchbran 87.5% 14 / 16 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 88.5% 77 / 87 CC 12 SCAR 17.5
CC
12
Cov
91%
command
9.6
preprocess_paragraph
4.0
BEGIN
1.0
CRAP 5.7
↑ Summary script/lip2pod »
1 #!/usr/bin/perl -w
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =begin lip
5  
6 =for none
7 ###############################################################################
8 ###############################################################################
9  
10 =head1 NAME
11  
12 Lip::Pod - Literate Perl filter
13  
14 =cut
15  
16 =for none
17 ###############################################################################
18 ###############################################################################
19  
20 =head1 CONCEPT
21  
22 Leaves all pod code intact, and indents all non-pod code by two spaces. C<=cut>
23 directives are eaten. An C<=head1>, C<=cut> pair is wrapped around the output.
24 Lines consisting entirely of '#' (and at least 3 of them) are ignored in the
25 non-pod zones (to allow for dividing lines in the source code).
26  
27 =cut
28  
29  
30 =for none
31 ###############################################################################
32 ###############################################################################
33  
34 =head1 SUBCLASS Pod::Parser
35  
36 Defines a subclass of B<Pod::Parser> which implements the indentation and
37 C<=cut> skipping described in L<SYNOPSIS>.
38  
39 =cut
40  
41 package Lip::Pod;
42  
43 1 ▶use Pod::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 @ISA = qw(Pod::Parser);
47  
48 1 ▶use Text::Tabs;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50  
51 =for none
52 ###############################################################################
53  
54 =head2 begin_input()
55  
56 Print out the Literate Perl preamble.
57  
58 =cut
59  
60 sub begin_input
61 1 ▶{
Subroutine begin_input: called CC=1 SCAR=0.0
Pod documented
62 1 my ($self) = @_;
63 1 my $out_fh = $self->output_handle();
64  
65 1 print $out_fh "=pod\n\n";
66 }
67  
68  
69 =for none
70 ###############################################################################
71  
72 =head2 command()
73  
74 Pass through all commands, except C<=cut>, which is not passed through so that
75 the entire output is POD.
76  
77 =cut
78  
79 sub command
80 5 ▶{
Subroutine command: called CC=9 SCAR=22.7
Pod documented
81 5 my ($self, $cmd, $text, $line_num, $pod_para) = @_;
82  
83 5 ▶ if (($cmd eq 'begin') and ($text =~ m/^\s*lip\s*$/)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmd eq 'begin' and $text =~ /^\s*lip\s*$/) { } 1 4 5
elsif ($cmd eq 'end' and $text =~ /^\s*lip\s*$/) { } 1 6 7
Condition66%2/3
$cmd eq "begin" and $text =~ /^\s*lip\s*$/
!ll&&!rl&&r
401
MC/DC50%1/2
$cmd eq "begin" and $text =~ /^\s*lip\s*$/
$cmd eq "begin" $text =~ /^\s*lip\s*$/
Truth table66%2/3
A and B
A= $cmd eq "begin"B= $text =~ /^\s*lip\s*$/
ABresult
0X0
100
111
84 1 $self->{lip} = 1;
85 1 return;
86 ▶ } elsif (($cmd eq 'end') and ($text =~ m/^\s*lip\s*$/)) {
Condition66%2/3
$cmd eq "end" and $text =~ /^\s*lip\s*$/
!ll&&!rl&&r
301
MC/DC50%1/2
$cmd eq "end" and $text =~ /^\s*lip\s*$/
$cmd eq "end" $text =~ /^\s*lip\s*$/
Truth table66%2/3
A and B
A= $cmd eq "end"B= $text =~ /^\s*lip\s*$/
ABresult
0X0
100
111
87 1 $self->{lip} = 0;
88 1 return;
89 }
90  
91 3 ▶ return unless $self->{lip};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"lip"} 0 3 3
92  
93 3 ▶ return if $cmd eq 'cut';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "cut" 1 2 3
94 2 ▶ return if (($cmd eq 'for') and ($text =~ m/^\s*none\b/));
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "for" and $text =~ /^\s*none\b/ 0 2 2
Condition33%1/3
$cmd eq "for" and $text =~ /^\s*none\b/
!ll&&!rl&&r
200
MC/DC0%0/2
$cmd eq "for" and $text =~ /^\s*none\b/
$cmd eq "for" $text =~ /^\s*none\b/
Truth table33%1/3
A and B
A= $cmd eq "for"B= $text =~ /^\s*none\b/
ABresult
0X0
100
111
95  
96 2 my $out_fh = $self->output_handle();
97  
98 2 print $out_fh "=$cmd ", $text;
99 }
100  
101  
102 =for none
103 ###############################################################################
104  
105 =head2 end_input()
106  
107 Print out the Literate Perl postamble.
108  
109 =cut
110  
111 sub end_input
112 1 ▶{
Subroutine end_input: called CC=1 SCAR=0.0
Pod documented
113 1 my ($self) = @_;
114  
115 1 my $out_fh = $self->output_handle();
116  
117 1 print $out_fh "=cut\n\n";
118 }
119  
120  
121 =for none
122 ###############################################################################
123  
124 =head2 preprocess_paragraph()
125  
126 Indents non-POD paragraphs by two spaces.
127  
128 =cut
129  
130 sub preprocess_paragraph
131 11 ▶{
Subroutine preprocess_paragraph: called CC=4 SCAR=13.9
Pod documented
132 11 my ($self, $text, $line_num) = @_;
133 11 my @text;
134  
135 11 ▶ return $text if $text =~ m/^=begin\s+lip\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /^=begin\s+lip\s*$/ 1 10 11
136  
137 10 ▶ return "" unless $self->{lip};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"lip"} 2 8 10
138 8 ▶ return $text unless $self->cutting;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->cutting 6 2 8
139  
140 2 @text = split($/, $text, -1);
141 2 @text = expand(@text);
142 2 map { s/^(\s*\S)/ $1/; } @text;
143 2 $text = join($/, @text);
144  
145 2 my $out_fh = $self->output_handle();
146 2 print $out_fh $text;
147  
148 2 return "";
149 }
150  
151  
152 =for none
153 ###############################################################################
154 ###############################################################################
155  
156 =end lip
157  
158 =cut
159  
160 1 1;
161  
162 __END__
↑ Summary script/lip2pod »