Man.pm

filter: Statementstmt 83.7% 180 / 215 Branchbran 80.5% 29 / 36 Conditioncond 85.7% 6 / 7 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 78.2% 54 / 69 Podpod 2.6% 1 / 38 totaltotal 73.9% 273 / 369 CC 24 SCAR 7.4
CC
24
Cov
83%
from_file
6.0
parse_directive_RS
6.0
parse_escape
5.0
CRAP 2.1
↑ Summary Man/DOM.pm »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2011-2022 -- leonerd@leonerd.org.uk
5  
6 package Parse::Man 0.03;
7  
8 14 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 14 ▶use base qw( Parser::MGC );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 14 ▶use constant pattern_ws => qr/[ \t]+/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =head1 NAME
17  
18 C<Parse::Man> - parse nroff-formatted manpages
19  
20 =head1 DESCRIPTION
21  
22 This abstract subclass of L<Parser::MGC> recognises F<nroff> grammar from a
23 file or string value. It invokes methods when various F<nroff> directives are
24 encountered. It is intended that this class be used as a base class, with
25 methods provided to handle the various directives and formatting options.
26 Typically a subclass will store intermediate results in a data structure,
27 building it as directed by these method invocations.
28  
29 =cut
30  
31 sub from_file
32 0 ▶{
Subroutine from_file: not called CC=2 SCAR=17.9
Pod documented
33 0 my $self = shift;
34 0 my ( $file ) = @_;
35  
36 0 ▶ if( $file =~ m/\.gz$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.gz$/u) { } 0 0 0
37 0 return $self->SUPER::from_file( $file, binmode => ":gzip" );
38 }
39 else {
40 0 return $self->SUPER::from_file( $file );
41 }
42 }
43  
44 sub parse
45 45 ▶{
Subroutine parse: called CC=1 SCAR=0.0
Pod undocumented
46 45 my $self = shift;
47  
48 45 $self->_change_para_options(
49 mode => "P",
50 filling => 1,
51 indent => 0,
52 );
53 45 $self->{para_flushed} = 0;
54  
55 45 $self->sequence_of( \&parse_line );
56 }
57  
58 sub token_nl
59 52 ▶{
Subroutine token_nl: called CC=1 SCAR=0.0
Pod undocumented
60 52 my $self = shift;
61 52 $self->expect( "\n" );
62 }
63  
64 sub token_chunk
65 72 ▶{
Subroutine token_chunk: called CC=1 SCAR=0.0
Pod undocumented
66 72 my $self = shift;
67  
68 72 $self->skip_ws;
69  
70 # A single chunk is either "quoted sequence" or whitespace-separated
71 return $self->any_of(
72 72 ▶ sub { $self->committed_scope_of( '"', "_escaped", qr/"|$/m ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
73 66 ▶ sub { $self->_escaped( 1 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
74 72 );
75 }
76  
77 sub _escaped
78 72 ▶{
Subroutine _escaped: called CC=3 SCAR=11.0
79 72 my $self = shift;
80 72 my ( $break_on_space ) = @_;
81 72 my $ret = "";
82  
83 72 my $consumed = 0;
84  
85 $consumed++ while $self->any_of(
86 120 ▶ sub { my $esc = ( $self->expect( qr/\\(?|\((..)|(.))/ ) )[1];
Subroutine __ANON__: called CC=1 SCAR=0.0
87 1 $self->commit;
88 1 $ret .= $self->parse_escape( $esc );
89 1 1;
90 },
91 119 ▶ sub { length( my $more = $self->substring_before( $break_on_space ? qr/[\\\n\s]/ : qr/[\\\n]/ ) ) or return 0;
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
length(my $more = $self->substring_before($break_on_space ? qr/[\\\n\s]/u : qr/[\\\n]/u)) or return 0 47 72 119
$break_on_space ? : 107 12 119
92 47 $ret .= $more;
93 47 1 },
94 0 ▶ sub { 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 72 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$self->any_of(sub { my $esc = ($self->expect(qr/\\(?|\((..)|(.))/u))[1]; $self->commit; $ret .= $self->parse_escape($esc); 1; } , sub { length(my $more = $self->substring_before($break_on_space ? qr/[\\\n\s]/u : qr/[\\\n]/u)) or return 0; $ret .= $more; 1; } , sub { 0; } ) and do { ++$consumed } 48 72 120
96  
97 72 ▶ $consumed or $self->fail( "Expected a chunk" );
Branch: 1 branch
BranchTrueFalseTotal
$consumed or $self->fail("Expected a chunk") 48 24 72
98  
99 48 return $ret;
100 }
101  
102 sub parse_chunks
103 22 ▶{
Subroutine parse_chunks: called CC=1 SCAR=0.0
Pod undocumented
104 22 my $self = shift;
105 22 @{ $self->sequence_of( \&token_chunk ) };
106 }
107  
108 sub parse_chunks_flat
109 12 ▶{
Subroutine parse_chunks_flat: called CC=1 SCAR=0.0
Pod undocumented
110 12 my $self = shift;
111 12 return join " ", $self->parse_chunks;
112 }
113  
114 sub parse_line
115 100 ▶{
Subroutine parse_line: called CC=1 SCAR=0.0
Pod undocumented
116 100 my $self = shift;
117  
118 100 $self->commit;
119  
120 $self->any_of(
121 100 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
122 100 my $directive = ( $self->expect( qr/\.([A-Z]+)/i ) )[1];
123 52 $self->commit;
124 52 $self->${\"parse_directive_$directive"}( $self );
125 52 $self->token_nl;
126 },
127 48 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
128 # comments
129 48 $self->expect( qr/\.\\".*?\n/ );
130 },
131 48 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
132 48 $self->commit;
133 48 ▶ $self->scope_of( undef, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
134 48 $self->{fonts} = [ "R" ];
135 48 $self->parse_plaintext;
136 48 }, "\n" );
137 },
138 100 );
139 }
140  
141 =head1 TEXT CHUNK FORMATTING METHOD
142  
143 The following method is used to handle formatted text. Each call is passed a
144 plain string value from the input content.
145  
146 =cut
147  
148 =head2 chunk
149  
150 $parser->chunk( $text, %opts )
151  
152 The C<%opts> hash contains the following options:
153  
154 =over 4
155  
156 =item font => STRING
157  
158 The name of the current font (C<R>, C<B>, etc..)
159  
160 =item size => INT
161  
162 The current text size, relative to a paragraph base of 0.
163  
164 =back
165  
166 =cut
167  
168 sub parse_directive_B
169 4 ▶{
Subroutine parse_directive_B: called CC=1 SCAR=0.0
Pod undocumented
170 4 my $self = shift;
171 4 $self->_flush_para;
172 4 $self->chunk( $self->parse_chunks_flat, font => "B", size => 0 );
173 }
174  
175 sub parse_directive_I
176 2 ▶{
Subroutine parse_directive_I: called CC=1 SCAR=0.0
Pod undocumented
177 2 my $self = shift;
178 2 $self->_flush_para;
179 2 $self->chunk( $self->parse_chunks_flat, font => "I", size => 0 );
180 }
181  
182 sub parse_directive_R
183 2 ▶{
Subroutine parse_directive_R: called CC=1 SCAR=0.0
Pod undocumented
184 2 my $self = shift;
185 2 $self->_flush_para;
186 2 $self->chunk( $self->parse_chunks_flat, font => "R", size => 0 );
187 }
188  
189 sub parse_directive_SM
190 3 ▶{
Subroutine parse_directive_SM: called CC=3 SCAR=11.0
Pod undocumented
191 3 my $self = shift;
192 3 $self->_flush_para;
193  
194 3 my @chunks = $self->parse_chunks;
195  
196 3 ▶ $self->chunk( shift @chunks, font => "R", size => 0 ) if @chunks > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @chunks > 2 1 2 3
197 3 $self->chunk( shift @chunks, font => "R", size => -1 );
198 3 ▶ $self->chunk( shift @chunks, font => "R", size => 0 ) if @chunks;
Branch: 1 branch
BranchTrueFalseTotal
if @chunks 2 1 3
199 }
200  
201 sub _parse_directive_alternate
202 4 ▶{
Subroutine _parse_directive_alternate: called CC=2 SCAR=6.9
203 4 my $self = shift;
204 4 my ( $first, $second ) = @_;
205 4 $self->_flush_para;
206 4 my $i = 0;
207 4 ▶ map { $self->chunk( $_, font => ( ++$i % 2 ? $first : $second ), size => 0 ) } $self->parse_chunks;
Branch: 1 branch
BranchTrueFalseTotal
++$i % 2 ? : 8 4 12
208 }
209  
210 sub parse_directive_BI
211 0 ▶{
Subroutine parse_directive_BI: not called CC=1 SCAR=6.9
Pod undocumented
212 0 my $self = shift;
213 0 $self->_parse_directive_alternate( "B", "I" );
214 }
215  
216 sub parse_directive_IB
217 0 ▶{
Subroutine parse_directive_IB: not called CC=1 SCAR=6.9
Pod undocumented
218 0 my $self = shift;
219 0 $self->_parse_directive_alternate( "I", "B" );
220 }
221  
222 sub parse_directive_RB
223 4 ▶{
Subroutine parse_directive_RB: called CC=1 SCAR=0.0
Pod undocumented
224 4 my $self = shift;
225 4 $self->_parse_directive_alternate( "R", "B" );
226 }
227  
228 sub parse_directive_BR
229 0 ▶{
Subroutine parse_directive_BR: not called CC=1 SCAR=6.9
Pod undocumented
230 0 my $self = shift;
231 0 $self->_parse_directive_alternate( "B", "R" );
232 }
233  
234 sub parse_directive_RI
235 0 ▶{
Subroutine parse_directive_RI: not called CC=1 SCAR=6.9
Pod undocumented
236 0 my $self = shift;
237 0 $self->_parse_directive_alternate( "R", "I" );
238 }
239  
240 sub parse_directive_IR
241 0 ▶{
Subroutine parse_directive_IR: not called CC=1 SCAR=6.9
Pod undocumented
242 0 my $self = shift;
243 0 $self->_parse_directive_alternate( "I", "R" );
244 }
245  
246 =pod
247  
248 Other font requests that are found in C<\fX> or C<\f(AB> requests are handled
249 by similarly-named methods.
250  
251 =cut
252  
253 =head1 PARAGRAPH HANDLING METHODS
254  
255 The following methods are used to form paragraphs out of formatted text
256 chunks. Their return values are ignored.
257  
258 =cut
259  
260 =head2 para_TH
261  
262 $parser->para_TH( $name, $section )
263  
264 Handles the C<.TH> paragraph which gives the page title and section number.
265  
266 =cut
267  
268 sub parse_directive_TH
269 3 ▶{
Subroutine parse_directive_TH: called CC=1 SCAR=0.0
Pod undocumented
270 3 my $self = shift;
271 3 $self->_change_para( "P" ),
272 $self->para_TH( $self->parse_chunks );
273 }
274  
275 =head2 para_SH
276  
277 $parser->para_SH( $title )
278  
279 Handles the C<.SH> paragraph, which gives a section header.
280  
281 =cut
282  
283 sub parse_directive_SH
284 4 ▶{
Subroutine parse_directive_SH: called CC=1 SCAR=0.0
Pod undocumented
285 4 my $self = shift;
286 4 $self->_change_para( "P" ),
287 $self->para_SH( $self->parse_chunks_flat );
288 }
289  
290 =head2 para_SS
291  
292 $parser->para_SS( $title )
293  
294 Handles the C<.SS> paragraph, which gives a sub-section header.
295  
296 =cut
297  
298 sub parse_directive_SS
299 0 ▶{
Subroutine parse_directive_SS: not called CC=1 SCAR=6.9
Pod undocumented
300 0 my $self = shift;
301 0 $self->_change_para( "P" ),
302 $self->para_SS( $self->parse_chunks_flat );
303 }
304  
305 =head2 para_TP
306  
307 $parser->para_TP( $opts )
308  
309 Handles a C<.TP> paragraph, which gives a term definition.
310  
311 =cut
312  
313 sub parse_directive_TP
314 4 ▶{
Subroutine parse_directive_TP: called CC=1 SCAR=0.0
Pod undocumented
315 4 my $self = shift;
316 4 $self->_change_para( "TP" );
317 }
318  
319 =head2 para_IP
320  
321 $parser->para_IP( $opts )
322  
323 Handles a C<.IP> paragraph, which is indented like the definition part of a
324 C<.TP> paragraph.
325  
326 =cut
327  
328 sub parse_directive_IP
329 3 ▶{
Subroutine parse_directive_IP: called CC=3 SCAR=11.0
Pod undocumented
330 3 my $self = shift;
331 3 $self->_change_para( "IP" );
332  
333 3 ▶ if( defined( my $marker = $self->maybe( "token_chunk" ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $marker = $self->maybe("token_chunk"))) 2 1 3
334 2 $self->_change_para_options( marker => $marker );
335 }
336 3 ▶ if( defined( my $indent = $self->maybe( "token_chunk" ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $indent = $self->maybe("token_chunk"))) 2 1 3
337 2 $self->_change_para_options( indent => $indent );
338 }
339 }
340  
341 =head2 para_P
342  
343 $parser->para_P( $opts )
344  
345 Handles the C<.P>, C<.PP> or C<.LP> paragraphs, which are all synonyms for a
346 plain paragraph content.
347  
348 =cut
349  
350 sub parse_directive_P
351 11 ▶{
Subroutine parse_directive_P: called CC=1 SCAR=0.0
Pod undocumented
352 11 my $self = shift;
353 11 $self->_change_para( "P" );
354 }
355  
356 {
357 14 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
358 14 *parse_directive_PP = *parse_directive_LP = \&parse_directive_P;
359 }
360  
361 =head2 para_EX
362  
363 $parser->para_EX( $opts )
364  
365 Handles the C<.EX> paragraph, which is example text; intended to be rendered
366 in a fixed-width font without filling.
367  
368 =cut
369  
370 sub parse_directive_EX
371 2 ▶{
Subroutine parse_directive_EX: called CC=1 SCAR=0.0
Pod undocumented
372 2 my $self = shift;
373 2 $self->_push_para( "EX" );
374 }
375  
376 sub parse_directive_EE
377 2 ▶{
Subroutine parse_directive_EE: called CC=1 SCAR=0.0
Pod undocumented
378 2 my $self = shift;
379 2 $self->_pop_para( "EX" );
380 }
381  
382 sub parse_directive_RS
383 0 ▶{
Subroutine parse_directive_RS: not called CC=2 SCAR=17.9
Pod undocumented
384 0 my $self = shift;
385 0 ▶ if( defined( my $indent = $self->maybe( "token_chunk" ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $indent = $self->maybe('token_chunk'))) { } 0 0 0
386 0 $self->_change_para_options( indent => $indent );
387 }
388 else {
389 0 $self->_change_para_options( indent => "4n" );
390 }
391 }
392  
393 sub parse_directive_RE
394 0 ▶{
Subroutine parse_directive_RE: not called CC=1 SCAR=6.9
Pod undocumented
395 0 my $self = shift;
396 0 $self->_change_para_options( indent => "0" );
397 }
398  
399 sub parse_directive_br
400 0 ▶{
Subroutine parse_directive_br: not called CC=1 SCAR=6.9
Pod undocumented
401 0 my $self = shift;
402 0 $self->entity_br;
403 }
404  
405 sub parse_directive_fi
406 2 ▶{
Subroutine parse_directive_fi: called CC=1 SCAR=0.0
Pod undocumented
407 2 my $self = shift;
408 2 $self->_change_para_options( filling => 1 );
409 }
410  
411 sub parse_directive_in
412 0 ▶{
Subroutine parse_directive_in: not called CC=1 SCAR=6.9
Pod undocumented
413 0 my $self = shift;
414  
415 0 my @ret;
416 0 my $indent = 0;
417  
418 0 ▶ $self->maybe( sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
419 0 $indent = $self->expect( qr/[+-]?\d+[n]?/ );
420 0 } );
421  
422 0 $self->_change_para_options( indent => $indent );
423 }
424  
425 sub parse_directive_nf
426 5 ▶{
Subroutine parse_directive_nf: called CC=1 SCAR=0.0
Pod undocumented
427 5 my $self = shift;
428 5 $self->_change_para_options( filling => 0 );
429 }
430  
431 sub parse_directive_sp
432 1 ▶{
Subroutine parse_directive_sp: called CC=1 SCAR=0.0
Pod undocumented
433 1 my $self = shift;
434 1 $self->entity_sp;
435 }
436  
437 sub parse_plaintext
438 48 ▶{
Subroutine parse_plaintext: called CC=1 SCAR=0.0
Pod undocumented
439 48 my $self = shift;
440  
441 48 $self->_flush_para;
442  
443 $self->sequence_of(
444 69 ▶ sub { $self->any_of(
Subroutine __ANON__: called CC=1 SCAR=0.0
445 69 ▶ sub { my $esc = ( $self->expect( qr/\\(?|\((..)|(.))/ ) )[1];
Subroutine __ANON__: called CC=2 SCAR=6.9
446 15 $self->commit;
447 15 my @chunks = $self->parse_escape( $esc );
448 15 $self->chunk( $_, font => $self->{fonts}[-1], size => 0 ) for @chunks;
449 },
450 54 ▶ sub { $self->chunk( $self->substring_before( qr/[\\\n]/ ), font => $self->{fonts}[-1], size => 0 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
451 69 ); }
452 48 );
453 }
454  
455 sub parse_escape
456 16 ▶{
Subroutine parse_escape: called CC=5 SCAR=16.1
Pod undocumented
457 16 my $self = shift;
458 16 my ( $esc ) = @_;
459  
460 16 my $meth = "parse_escape_$esc";
461 16 ▶ $meth = sprintf "parse_escape_x%v02X", $esc if length($esc) == 1 and $esc =~ m/[^A-Za-z0-9]/;
Branch: 1 branch
BranchTrueFalseTotal
if length $esc == 1 and $esc =~ /[^A-Za-z0-9]/u 2 14 16
Condition100%3/3
length $esc == 1 and $esc =~ /[^A-Za-z0-9]/u
!ll&&!rl&&r
3112
MC/DC100%2/2
length $esc == 1 and $esc =~ /[^A-Za-z0-9]/u
length $esc == 1 $esc =~ /[^A-Za-z0-9]/u
Truth table100%3/3
A and B
A= length $esc == 1B= $esc =~ /[^A-Za-z0-9]/u
ABresult
0X0
100
111
462 16 ▶ $meth = "parse_escape_char" if length($esc) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if length $esc > 1 3 13 16
463 16 ▶ $meth = $self->can( $meth ) or
Branch: 1 branch
BranchTrueFalseTotal
$meth = $self->can($meth) or $self->fail("Unrecognised escape sequence \\$esc") 16 0 16
464 $self->fail( "Unrecognised escape sequence \\$esc" );
465 16 return $self->$meth( $esc );
466 }
467  
468 sub parse_escape_x2D # \-
469 1 ▶{
Subroutine parse_escape_x2D: called CC=1 SCAR=0.0
Pod undocumented
470 1 my $self = shift;
471  
472 # TODO: Unicode minus sign?
473 1 return "-";
474 }
475  
476 # Ignore the "italic corrections" for now
477 *parse_escape_x2C = # \,
478 *parse_escape_x2F = # \/
479 0 ▶ sub { return };
Subroutine __ANON__: not called CC=1 SCAR=1.2
480  
481 # The "empty" character
482 sub parse_escape_x26 # \&
483 1 ▶{
Subroutine parse_escape_x26: called CC=1 SCAR=0.0
Pod undocumented
484 1 my $self = shift;
485  
486 1 return "";
487 }
488  
489 0 ▶*parse_escape_e = *parse_escape_E = *parse_escape_x5C = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
490 0 my $self = shift;
491  
492 0 return "\\";
493 14 };
494  
495 sub parse_escape_f
496 11 ▶{
Subroutine parse_escape_f: called CC=1 SCAR=0.0
Pod undocumented
497 11 my $self = shift;
498  
499 $self->any_of(
500 11 ▶ sub { $self->expect( qr/P/ );
Subroutine __ANON__: called CC=2 SCAR=7.0
501 2 $self->commit;
502 2 ▶ @{ $self->{fonts} } > 1 or $self->fail( "Cannot \\fP without a \\f font defined" );
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{"fonts"};} > 1 or $self->fail("Cannot \\fP without a \\f font defined") 2 0 2
503 2 pop @{ $self->{fonts} }; },
504 9 ▶ sub { push @{ $self->{fonts} }, ( $self->expect( qr/([A-Z])/ ) )[1]; },
Subroutine __ANON__: called CC=1 SCAR=0.0
505 1 ▶ sub { push @{ $self->{fonts} }, ( $self->expect( qr/\((..)/ ) )[1]; },
Subroutine __ANON__: called CC=1 SCAR=0.0
506 11 );
507  
508 11 return; # empty
509 }
510  
511 # TODO: Vastly expand this table
512 14 my %chars = (
513 'aq' => q('),
514 'bu' => '•',
515 'co' => '©',
516 );
517  
518 sub parse_escape_char
519 3 ▶{
Subroutine parse_escape_char: called CC=2 SCAR=7.0
Pod undocumented
520 3 my $self = shift;
521 3 my ( $name ) = @_;
522  
523 3 ▶ my $char = $chars{$name} // "<char $name>";
Condition50%1/2
$chars{$name} // "<char $name>"
l!l
30
MC/DC0%0/1
$chars{$name} // "<char $name>"
$chars{$name}
Truth table50%1/2
A
A= $chars{$name}
Aresult
11
00
524  
525 3 return $char;
526 }
527  
528 sub _change_para
529 27 ▶{
Subroutine _change_para: called CC=1 SCAR=0.0
530 27 my $self = shift;
531 27 my ( $mode ) = @_;
532 27 $self->_change_para_options( mode => $mode );
533 27 $self->{para_flushed} = 0;
534 }
535  
536 sub _change_para_options
537 83 ▶{
Subroutine _change_para_options: called CC=4 SCAR=13.9
538 83 my $self = shift;
539 83 my %opts = @_;
540  
541 83 ▶ if( grep { ($self->{para_options}{$_}//"") ne $opts{$_} } keys %opts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {($self->{"para_options"}{$_} // "") ne $opts{$_};} keys %opts) 35 48 83
Condition100%2/2
$self->{"para_options"}{$_} // ""
l!l
13241
MC/DC100%1/1
$self->{"para_options"}{$_} // ""
$self->{"para_options"}{$_}
Truth table100%2/2
A
A= $self->{"para_options"}{$_}
Aresult
11
00
542 35 $self->{para_flushed} = 0;
543 }
544  
545 83 $self->{para_options}{$_} = $opts{$_} for keys %opts;
546 }
547  
548 sub _flush_para
549 65 ▶{
Subroutine _flush_para: called CC=2 SCAR=6.9
550 65 my $self = shift;
551 65 ▶ if( !$self->{para_flushed} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'para_flushed'}) { } 50 15 65
552 50 my $mode = $self->{para_options}{mode};
553 50 $self->${\"para_$mode"}( $self->{para_options} );
554 50 $self->{para_flushed}++;
555 }
556 else {
557 15 $self->join_para;
558 }
559 }
560  
561 sub _push_para
562 2 ▶{
Subroutine _push_para: called CC=1 SCAR=0.0
563 2 my $self = shift;
564 2 my ( $new_mode ) = @_;
565  
566 # Shallow clone
567 2 push @{ $self->{para_stack} }, { %{ $self->{para_options} } };
568 2 $self->_change_para( $new_mode );
569 }
570  
571 sub _pop_para
572 2 ▶{
Subroutine _pop_para: called CC=2 SCAR=7.0
573 2 my $self = shift;
574 2 my ( $expect_mode ) = @_;
575  
576 2 ▶ $self->{para_options}{mode} eq $expect_mode or
Branch: 1 branch
BranchTrueFalseTotal
$self->{"para_options"}{"mode"} eq $expect_mode or $self->fail("Expected current paragraph mode of $expect_mode") 2 0 2
577 $self->fail( "Expected current paragraph mode of $expect_mode" );
578  
579 2 $self->{para_options} = pop @{ $self->{para_stack} };
580  
581 2 $self->_flush_para;
582 2 $self->{para_flushed} = 0;
583 }
584  
585 =head1 AUTHOR
586  
587 Paul Evans <leonerd@leonerd.org.uk>
588  
589 =cut
590  
591 14 0x55AA;
↑ Summary Man/DOM.pm »