Simple/JustPod.pm

filter: Statementstmt 96.2% 152 / 158 Branchbran 87.5% 28 / 32 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 97.3% 37 / 38 Podpod 3.5% 1 / 28 totaltotal 84.2% 220 / 261 CC 18 SCAR 7.6
CC
18
Cov
94%
_start_fcode
5.0
check_that_all_is_closed
4.9
_end_fcode
3.0
CRAP 2.1
« Simple/PullParserToken.pm ↑ Summary Simple/Text.pm »
1 package Pod::Simple::JustPod;
2 # ABSTRACT: Pod::Simple formatter that extracts POD from a file containing
3 # other things as well
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use Pod::Simple::Methody ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 our @ISA = ('Pod::Simple::Methody');
9  
10 22 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11 22 my $self = shift;
12 22 my $new = $self->SUPER::new(@_);
13  
14 22 $new->accept_targets('*');
15 22 $new->keep_encoding_directive(1);
16 22 $new->preserve_whitespace(1);
17 22 $new->complain_stderr(1);
18 22 $new->_output_is_for_JustPod(1);
19  
20 22 return $new;
21 }
22  
23 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24  
25 1398 ▶sub check_that_all_is_closed {
Subroutine check_that_all_is_closed: called CC=4 SCAR=15.9
Pod undocumented
26  
27 # Actually checks that the things we depend on being balanced in fact are,
28 # so that we can continue in spit of pod errors
29  
30 1398 my $self = shift;
31 1398 ▶ while ($self->{inL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"inL"}) 0 1398 1398
32 0 $self->end_L(@_);
33 }
34 1398 ▶ while ($self->{fcode_end} && @{$self->{fcode_end}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"fcode_end"} and @{$self->{"fcode_end"};}) 0 1398 1398
Condition66%2/3
$self->{"fcode_end"} and @{$self->{"fcode_end"};}
!ll&&!rl&&r
13912590
MC/DC0%0/2
$self->{"fcode_end"} and @{$self->{"fcode_end"};}
$self->{"fcode_end"} @{$self->{"fcode_end"};}
Truth table66%2/3
A and B
A= $self->{"fcode_end"}B= @{$self->{"fcode_end"};}
ABresult
0X0
100
111
35 0 $self->_end_fcode(@_);
36 }
37 }
38  
39 4570 ▶sub handle_text {
Subroutine handle_text: called CC=2 SCAR=6.9
Pod undocumented
40  
41 # Add text to the output buffer. This is skipped if within a L<>, as we use
42 # the 'raw' attribute of that tag instead.
43  
44 4570 ▶ $_[0]{buffer} .= $_[1] unless $_[0]{inL} ;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"inL"} 4451 119 4570
45 }
46  
47 409 ▶sub spacer {
Subroutine spacer: called CC=3 SCAR=11.0
Pod undocumented
48  
49 # Prints the white space following things like =head1. This is normally a
50 # blank, unless BlackBox has told us otherwise.
51  
52 409 my ($self, $arg) = @_;
53 409 ▶ return unless $arg;
Branch: 1 branch
BranchTrueFalseTotal
unless $arg 22 387 409
54  
55 my $spacer = ($arg->{'~orig_spacer'})
56 387 ▶ ? $arg->{'~orig_spacer'}
Branch: 1 branch
BranchTrueFalseTotal
$arg->{'~orig_spacer'} ? : 17 370 387
57 : " ";
58 387 $self->handle_text($spacer);
59 }
60  
61 146 ▶sub _generic_start {
Subroutine _generic_start: called CC=1 SCAR=0.0
62  
63 # Called from tags like =head1, etc.
64  
65 146 my ($self, $text, $arg) = @_;
66 146 $self->check_that_all_is_closed();
67 146 $self->handle_text($text);
68 146 $self->spacer($arg);
69 }
70  
71 22 ▶sub start_Document { shift->_generic_start("=pod\n\n"); }
Subroutine start_Document: called CC=1 SCAR=0.0
Pod undocumented
72 59 ▶sub start_head1 { shift->_generic_start('=head1', @_); }
Subroutine start_head1: called CC=1 SCAR=0.0
Pod undocumented
73 53 ▶sub start_head2 { shift->_generic_start('=head2', @_); }
Subroutine start_head2: called CC=1 SCAR=0.0
Pod undocumented
74 2 ▶sub start_head3 { shift->_generic_start('=head3', @_); }
Subroutine start_head3: called CC=1 SCAR=0.0
Pod undocumented
75 2 ▶sub start_head4 { shift->_generic_start('=head4', @_); }
Subroutine start_head4: called CC=1 SCAR=0.0
Pod undocumented
76 2 ▶sub start_head5 { shift->_generic_start('=head5', @_); }
Subroutine start_head5: called CC=1 SCAR=0.0
Pod undocumented
77 2 ▶sub start_head6 { shift->_generic_start('=head6', @_); }
Subroutine start_head6: called CC=1 SCAR=0.0
Pod undocumented
78 4 ▶sub start_encoding { shift->_generic_start('=encoding', @_); }
Subroutine start_encoding: called CC=1 SCAR=0.0
Pod undocumented
79 # sub start_Para
80 # sub start_Verbatim
81  
82 35 ▶sub start_item_bullet { # Handle =item *
Subroutine start_item_bullet: called CC=3 SCAR=11.0
Pod undocumented
83 35 my ($self, $arg) = @_;
84 35 $self->check_that_all_is_closed();
85 35 $self->handle_text('=item');
86  
87 # It can be that they said simply '=item', and it is inferred that it is to
88 # be a bullet.
89 35 ▶ if (! $arg->{'~orig_content'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $arg->{'~orig_content'}) { } 2 33 35
90 2 $self->handle_text("\n\n");
91 }
92 else {
93 33 $self->spacer($arg);
94 33 ▶ if ($arg->{'~_freaky_para_hack'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{'~_freaky_para_hack'}) { } 23 10 33
95  
96 # See Message Id <87y3gtcwa2.fsf@hope.eyrie.org>
97 23 my $item_text = $arg->{'~orig_content'};
98 23 my $trailing = quotemeta $arg->{'~_freaky_para_hack'};
99 23 $item_text =~ s/$trailing$//;
100 23 $self->handle_text($item_text);
101 }
102 else {
103 10 $self->handle_text("*\n\n");
104 }
105 }
106 }
107  
108 4 ▶sub start_item_number { # Handle '=item 2'
Subroutine start_item_number: called CC=1 SCAR=0.0
Pod undocumented
109 4 my ($self, $arg) = @_;
110 4 $self->check_that_all_is_closed();
111 4 $self->handle_text("=item");
112 4 $self->spacer($arg);
113 4 $self->handle_text("$arg->{'~orig_content'}\n\n");
114 }
115  
116 197 ▶sub start_item_text { # Handle '=item foo bar baz'
Subroutine start_item_text: called CC=1 SCAR=0.0
Pod undocumented
117 197 my ($self, $arg) = @_;
118 197 $self->check_that_all_is_closed();
119 197 $self->handle_text('=item');
120 197 $self->spacer($arg);
121 }
122  
123 236 ▶sub _end_item {
Subroutine _end_item: called CC=1 SCAR=0.0
124 236 my $self = shift;
125 236 $self->check_that_all_is_closed();
126 236 $self->emit;
127 }
128  
129 5 *end_item_bullet = *_end_item;
130 5 *end_item_number = *_end_item;
131 5 *end_item_text = *_end_item;
132  
133 32 ▶sub _start_over { # Handle =over
Subroutine _start_over: called CC=2 SCAR=6.9
134 32 my ($self, $arg) = @_;
135 32 $self->check_that_all_is_closed();
136 32 $self->handle_text("=over");
137  
138 # The =over amount is optional
139 32 ▶ if ($arg->{'~orig_content'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{"~orig_content"}) 29 3 32
140 29 $self->spacer($arg);
141 29 $self->handle_text("$arg->{'~orig_content'}");
142 }
143 32 $self->handle_text("\n\n");
144 }
145  
146 5 *start_over_bullet = *_start_over;
147 5 *start_over_number = *_start_over;
148 5 *start_over_text = *_start_over;
149 5 *start_over_block = *_start_over;
150  
151 32 ▶sub _end_over {
Subroutine _end_over: called CC=1 SCAR=0.0
152 32 my $self = shift;
153 32 $self->check_that_all_is_closed();
154 32 $self->handle_text('=back');
155 32 $self->emit;
156 }
157  
158 5 *end_over_bullet = *_end_over;
159 5 *end_over_number = *_end_over;
160 5 *end_over_text = *_end_over;
161 5 *end_over_block = *_end_over;
162  
163 22 ▶sub end_Document {
Subroutine end_Document: called CC=1 SCAR=0.0
Pod undocumented
164 22 my $self = shift;
165 22 $self->emit; # Make sure buffer gets flushed
166 22 print {$self->{'output_fh'} } "=cut\n"
167 }
168  
169 716 ▶sub _end_generic {
Subroutine _end_generic: called CC=1 SCAR=0.0
170 716 my $self = shift;
171 716 $self->check_that_all_is_closed();
172 716 $self->emit;
173 }
174  
175 5 *end_head1 = *_end_generic;
176 5 *end_head2 = *_end_generic;
177 5 *end_head3 = *_end_generic;
178 5 *end_head4 = *_end_generic;
179 5 *end_head5 = *_end_generic;
180 5 *end_head6 = *_end_generic;
181 5 *end_encoding = *_end_generic;
182 5 *end_Para = *_end_generic;
183 5 *end_Verbatim = *_end_generic;
184  
185 676 ▶sub _start_fcode {
Subroutine _start_fcode: called CC=5 SCAR=16.1
186 676 my ($type, $self, $flags) = @_;
187  
188 # How many brackets is set by BlackBox unless the count is 1
189 my $bracket_count = (exists $flags->{'~bracket_count'})
190 676 ▶ ? $flags->{'~bracket_count'}
Branch: 1 branch
BranchTrueFalseTotal
exists $flags->{'~bracket_count'} ? : 18 658 676
191 : 1;
192 676 $self->handle_text($type . ( "<" x $bracket_count));
193  
194 676 my $rspacer = "";
195 676 ▶ if ($bracket_count > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bracket_count > 1) 18 658 676
196 my $lspacer = (exists $flags->{'~lspacer'})
197 18 ▶ ? $flags->{'~lspacer'}
Branch: 1 branch
BranchTrueFalseTotal
exists $flags->{'~lspacer'} ? : 2 16 18
198 : " ";
199 18 $self->handle_text($lspacer);
200  
201 $rspacer = (exists $flags->{'~rspacer'})
202 18 ▶ ? $flags->{'~rspacer'}
Branch: 1 branch
BranchTrueFalseTotal
exists $flags->{'~rspacer'} ? : 2 16 18
203 : " ";
204 }
205  
206 # BlackBox doesn't output things for for the ending code callbacks, so save
207 # what we need.
208 676 push @{$self->{'fcode_end'}}, [ $bracket_count, $rspacer ];
209 }
210  
211 60 ▶sub start_B { _start_fcode('B', @_); }
Subroutine start_B: called CC=1 SCAR=0.0
Pod undocumented
212 359 ▶sub start_C { _start_fcode('C', @_); }
Subroutine start_C: called CC=1 SCAR=0.0
Pod undocumented
213 22 ▶sub start_E { _start_fcode('E', @_); }
Subroutine start_E: called CC=1 SCAR=0.0
Pod undocumented
214 53 ▶sub start_F { _start_fcode('F', @_); }
Subroutine start_F: called CC=1 SCAR=0.0
Pod undocumented
215 85 ▶sub start_I { _start_fcode('I', @_); }
Subroutine start_I: called CC=1 SCAR=0.0
Pod undocumented
216 3 ▶sub start_S { _start_fcode('S', @_); }
Subroutine start_S: called CC=1 SCAR=0.0
Pod undocumented
217 0 ▶sub start_U { _start_fcode('U', @_); }
Subroutine start_U: not called CC=1 SCAR=6.9
Pod undocumented
218 1 ▶sub start_X { _start_fcode('X', @_); }
Subroutine start_X: called CC=1 SCAR=0.0
Pod undocumented
219 4 ▶sub start_Z { _start_fcode('Z', @_); }
Subroutine start_Z: called CC=1 SCAR=0.0
Pod undocumented
220  
221 676 ▶sub _end_fcode {
Subroutine _end_fcode: called CC=3 SCAR=11.1
222 676 my $self = shift;
223 676 my $fcode_end = pop @{$self->{'fcode_end'}};
224 676 my $bracket_count = 1;
225 676 my $rspacer = "";
226  
227 676 ▶ if (! defined $fcode_end) { # If BlackBox is working, this shouldn't
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $fcode_end) { } 0 676 676
228 # happen, but verify
229 0 $self->whine($self->{line_count}, "Extra '>'");
230 }
231 else {
232 676 $bracket_count = $fcode_end->[0];
233 676 $rspacer = $fcode_end->[1];
234 }
235  
236 676 ▶ $self->handle_text($rspacer) if $bracket_count > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $bracket_count > 1 18 658 676
237 676 $self->handle_text(">" x $bracket_count);
238 }
239  
240 5 *end_B = *_end_fcode;
241 5 *end_C = *_end_fcode;
242 5 *end_E = *_end_fcode;
243 5 *end_F = *_end_fcode;
244 5 *end_I = *_end_fcode;
245 5 *end_S = *_end_fcode;
246 5 *end_U = *_end_fcode;
247 5 *end_X = *_end_fcode;
248 5 *end_Z = *_end_fcode;
249  
250 89 ▶sub start_L {
Subroutine start_L: called CC=1 SCAR=0.0
Pod undocumented
251 89 _start_fcode('L', @_);
252 89 $_[0]->handle_text($_[1]->{raw});
253 89 $_[0]->{inL}++
254 }
255  
256 89 ▶sub end_L {
Subroutine end_L: called CC=2 SCAR=7.9
Pod undocumented
257 89 my $self = shift;
258 89 $self->{inL}--;
259 89 ▶ if ($self->{inL} < 0) { # If BlackBox is working, this shouldn't
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"inL"} < 0) 0 89 89
260 # happen, but verify
261 0 $self->whine($self->{line_count}, "Extra '>' ending L<>");
262 0 $self->{inL} = 0;
263 }
264  
265 89 $self->_end_fcode(@_);
266 }
267  
268 1006 ▶sub emit {
Subroutine emit: called CC=2 SCAR=6.9
Pod undocumented
269 1006 my $self = shift;
270  
271 1006 ▶ if ($self->{buffer} ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"buffer"} ne "") 984 22 1006
272 984 print { $self->{'output_fh'} } "",$self->{buffer} ,"\n\n";
273  
274 984 $self->{buffer} = "";
275 }
276  
277 1006 return;
278 }
279  
280 5 1;
281  
282 __END__
« Simple/PullParserToken.pm ↑ Summary Simple/Text.pm »