Perldoc/Parser.pm

filter: Statementstmt 82.2% 1008 / 1226 Branchbran 63.4% 241 / 380 Conditioncond 76.2% 173 / 227 MC/DCmcdc 65.0% 80 / 123 Subroutinesub 83.5% 168 / 201 Podpod 100% 1 / 1 totaltotal 77.4% 1671 / 2158 CC 290 SCAR 40.1
CC
290
Cov
78%
parse
217.4
_flatten_recursive
56.0
report_errors
30.0
CRAP 54.9
↑ Summary Perldoc/To/Xhtml.pm »
1 package Perl6::Perldoc::Parser;
2 #use Smart::Comments;
3 56 ▶use re 'eval';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 56 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 56 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 56 ▶use version; our $VERSION = qv('0.0.6');
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Regexes the parser needs...
11 56 my $LDAB = qq{\x{AB}};
12 56 my $RDAB = qq{\x{BB}};
13 56 my $LDAB_CJK = qq{\x{300A}};
14 56 my $RDAB_CJK = qq{\x{300B}};
15 56 my $LEFT_ANGLE = qr{ < | $LDAB | $LDAB_CJK }x;
16 56 my $RIGHT_ANGLE = qr{ > | $RDAB | $RDAB_CJK }x;
17  
18 56 my $FAIL = q{(?!)};
19  
20 56 my $BLANK_LINE = q{^ \\s* $};
21  
22 56 my $IDENT = qr{ [^\W\d]\w* }xms;
23 56 my $QUAL_IDENT = qr{ (?: $IDENT ::)* $IDENT }xms;
24 56 my $P6_QUAL_IDENT = qr{ $QUAL_IDENT (?: -\S+ )}xms;
25  
26 56 my $DIR_NC # DIRective but Not a Comment
27 = qr{ (?= ^ = (?! \s | (?:(?:begin|end|for) [^\S\n]+)? comment\b ))}xms;
28  
29 56 my $DIR_COMMENT_BLOCK # DIRective that is a COMMENT BLOCK
30 = qr{ ^ =begin \s+ comment \b }xms;
31  
32  
33 56 our $BALANCED_BRACKETS;
34 $BALANCED_BRACKETS = qr{ < (?: (??{$BALANCED_BRACKETS}) | . )*? >
35 | \[ (?: (??{$BALANCED_BRACKETS}) | . )*? \]
36 | \{ (?: (??{$BALANCED_BRACKETS}) | . )*? \}
37 | \( (?: (??{$BALANCED_BRACKETS}) | . )*? \)
38 | $LEFT_ANGLE
39 (?: (??{$BALANCED_BRACKETS}) | . )*?
40 $RIGHT_ANGLE
41 56 }xms;
42  
43 56 my $OPTION = qr{ : $IDENT $BALANCED_BRACKETS? | : ! $IDENT }xms;
44 56 my $OPTION_EXTRACT = qr{ :()($IDENT)($BALANCED_BRACKETS?) | :(!)($IDENT)() }xms;
45  
46 56 my $OPTIONS = qr{ (?: \s* $OPTION)+ }xms;
47  
48 56 my $FORMATTING_CODE = q{[BCDEIKLMNPRSTUVXZ]};
49  
50 56 my $PERMITS_IMPLICIT
51 = qr{\A (?: pod | (?! DATA ) [[:upper:]]+ ) \z}xms;
52  
53 56 my $PERMITS_IMPLICIT_IF_DELIMITED
54 = qr{ $PERMITS_IMPLICIT | \A (?: item | nested ) \z}xms;
55  
56 # Error handlers (push error messages to the correct queue: warnings or errors)
57  
58 # Format location nicely...
59 152 ▶sub _loc {
Subroutine _loc: called CC=2 SCAR=7.2
60 152 my ($range_ref) = @_;
61 return defined $range_ref->{file}
62 152 ▶ ? "$range_ref->{file} line $range_ref->{from}"
Branch: 1 branch
BranchTrueFalseTotal
defined $range_ref->{'file'} ? : 0 152 152
63 : "line $range_ref->{from}"
64 ;
65 }
66  
67 # Missing block terminators must be (at least) warned about...
68 291 ▶sub _err_no_closing_delim {
Subroutine _err_no_closing_delim: called CC=6 SCAR=18.3
69 291 my ($top, $errors_ref, $warnings_ref) = @_;
70  
71 # Paragraphed, parser-introduced, and magic blocks don't need terminators...
72 return if $top->{is_blank_terminated}
73 || $top->{is_implicit}
74 291 ▶ || $top->{typename} =~ m{\A (?: \(ambient\) | list | DATA | END ) }xms;
Branch: 1 branch
BranchTrueFalseTotal
if $top->{"is_blank_terminated"} or $top->{"is_implicit"} or $top->{"typename"} =~ /\A (?: \(ambient\) | list | DATA | END ) /msx 290 1 291
Condition100%6/6
$top->{"is_blank_terminated"} or $top->{"is_implicit"} or $top->{"typename"} =~ /\A (?: \(ambient\) | list | DATA | END ) /msx
l!l&&r!l&&!r
270201
$top->{"is_blank_terminated"} or $top->{"is_implicit"}
l!l&&r!l&&!r
14912121
MC/DC100%3/3
$top->{"is_blank_terminated"} or $top->{"is_implicit"} or $top->{"typename"} =~ /\A (?: \(ambient\) | list | DATA | END ) /msx
$top->{"is_blank_terminated"} $top->{"is_implicit"} $top->{"typename"} =~ /\A (?: \(ambient\) | list | DATA | END ) /msx
Truth table100%4/4
A or B or C
A= $top->{"is_blank_terminated"}B= $top->{"is_implicit"}C= $top->{"typename"} =~ /\A (?: \(ambient\) | list | DATA | END ) /msx
ABCresult
1XX1
01X1
0011
0000
75  
76 1 my $location = _loc( $top->{range} );
77 my $msg = 'No closing delimiter for '
78 1 ▶ . ( $top->{style} eq 'formatting'
Branch: 1 branch
BranchTrueFalseTotal
$top->{'style'} eq 'formatting' ? : 0 1 1
79 ? "$top->{typename}$top->{left_delim}..."
80 : "'$top->{typename}' block"
81 )
82 . " opened at $location";
83  
84 # Only a fatal problem if the block is missing an =end...
85 1 ▶ if ($top->{style} eq 'delimited') {
Branch: 1 branch
BranchTrueFalseTotal
if ($top->{'style'} eq 'delimited') { } 1 0 1
86 1 push @{$errors_ref}, $msg;
87 }
88 else {
89 0 push @{$warnings_ref}, $msg;
90 }
91 }
92  
93 # Nothing except options allowed after the block declarator...
94 1 ▶sub _err_trailing_junk {
Subroutine _err_trailing_junk: called CC=2 SCAR=7.0
95 1 my ($block_type, $range_ref, $junk, $errors_ref) = @_;
96 1 my $location = _loc($range_ref);
97  
98 1 ▶ push @{$errors_ref}, 'Trailing junk after '
Branch: 1 branch
BranchTrueFalseTotal
$block_type =~ /[ ]/ ? : 0 1 1
99 . ( $block_type =~ /[ ]/
100 ? $block_type
101 : "'$block_type' block specifier"
102 )
103 . " at $location: $junk"
104 ;
105 }
106  
107 # All lowercase and uppercase block names are reserved...
108 1 ▶sub _err_unknown_reserved_block {
Subroutine _err_unknown_reserved_block: called CC=1 SCAR=0.0
109 1 my ($block, $errors_ref) = @_;
110 1 my $location = _loc($block->{range});
111  
112 1 push @{$errors_ref}, "Unknown reserved block type ('$block->{typename}') "
113 . " at $location"
114 ;
115 }
116  
117 # No extra option lines after the content starts...
118 1 ▶sub _err_options_too_late {
Subroutine _err_options_too_late: called CC=1 SCAR=0.0
119 1 my ($top, $range_ref, $warnings_ref) = @_;
120 1 my $location = _loc($range_ref);
121
122 1 push @{$warnings_ref}, 'Possible attempt to specify extra options '
123 . "too late in '$top->{typename}' block at $location";
124 }
125  
126 # Unexpected block terminators often mean an typo on the opener...
127 1 ▶sub _err_closed_unopened_block {
Subroutine _err_closed_unopened_block: called CC=1 SCAR=0.0
128 1 my ($type, $range_ref, $errors_ref) = @_;
129 1 my $location = _loc($range_ref);
130  
131 1 push @{$errors_ref}, "Invalid '=end $type' (not in '$type' block) "
132 . "at $location";
133 }
134  
135 # A terminator on an END block is meaningless; report it...
136 2 ▶sub _err_closed_END_block {
Subroutine _err_closed_END_block: called CC=1 SCAR=0.0
137 2 my ($range_ref, $warnings_ref) = @_;
138 2 my $location = _loc($range_ref);
139  
140 2 push @{$warnings_ref}, q{Ignored explicit '=end END' }
141 . q{(END blocks run to end-of-file) }
142 . qq{at $location}
143 ;
144 }
145  
146 # No =itemN unless there's a preceding =item(N-1)...
147 2 ▶sub _err_missing_list_level {
Subroutine _err_missing_list_level: called CC=1 SCAR=0.0
148 2 my ($range_ref, $item_level, $errors_ref) = @_;
149 2 my $location = _loc($range_ref);
150  
151 2 push @{$errors_ref}, q{No =item} . ($item_level-1)
152 . qq{ before =item$item_level at $location};
153 }
154  
155  
156 # User-defined M<> code do have to be defined...
157 1 ▶sub _err_missing_M_scheme {
Subroutine _err_missing_M_scheme: called CC=1 SCAR=0.0
158 1 my ($range_ref, $errors_ref) = @_;
159 1 my $location = _loc($range_ref);
160  
161 1 push @{$errors_ref}, q{Missing scheme specifier in M<> formatting code }
162 . qq{at $location};
163 }
164  
165 # Link and =use targets actually have to point somewhere real...
166 1 ▶sub _err_bad_use_uri {
Subroutine _err_bad_use_uri: called CC=1 SCAR=0.0
167 1 my ($uri, $range_ref, $errors_ref) = @_;
168 1 my $location = _loc($range_ref);
169  
170 1 push @{$errors_ref}, qq{Unable to open URI in '=use $uri' }
171 . qq{at $location};
172 }
173  
174 # =use targets must be loadable
175 0 ▶sub _err_use_cant_load {
Subroutine _err_use_cant_load: not called CC=1 SCAR=6.9
176 0 my ($source, $range_ref, $errors_ref) = @_;
177 0 my $location = _loc($range_ref);
178  
179 0 push @{$errors_ref}, qq{Unable to load module in '=use $source' }
180 . qq{at $location};
181 }
182  
183 # Various places need to add content to the top of the stack...
184 1043 ▶sub _add_content {
Subroutine _add_content: called CC=3 SCAR=11.0
185 1043 my ($top, $content) = @_;
186  
187 1043 ▶ if (!$top->{content} || ref $top->{content}[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $top->{'content'} or ref $top->{'content'}[-1]) { } 329 714 1043
Condition100%3/3
not $top->{"content"} or ref $top->{"content"}[-1]
l!l&&r!l&&!r
26465714
MC/DC100%2/2
not $top->{"content"} or ref $top->{"content"}[-1]
not $top->{"content"} ref $top->{"content"}[-1]
Truth table100%3/3
not(A) or B
A= not $top->{"content"}B= ref $top->{"content"}[-1]
ABresult
1X1
011
000
188 329 push @{ $top->{content} }, $content;
189 }
190 else {
191 714 $top->{content}[-1] .= $content;
192 }
193 }
194  
195  
196 # Extract options in Perl 6 format...
197  
198 # Handled embedded quotes in <<>>
199 0 ▶sub _shell_split {
Subroutine _shell_split: not called CC=2 SCAR=17.9
200 0 my ($content) = @_;
201 0 my @components;
202 0 pos $content = 0;
203 0 ▶ while (pos $content < length $content) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $content < length $content) 0 0 0
204 0 $content =~ m{ \G \s*
205 (?: " ( [^"\\]* (?: \\. [^"\\]* )* ) "
206 | ' ( [^'\\]* (?: \\. [^'\\]* )* ) '
207 | ( \S+ )
208 )
209 \s*
210 }gcxms;
211 0 push @components, $+;
212 }
213 0 return @components;
214 }
215  
216 # Parse and convert Perl 6 style :key(value) and key=>value pairs...
217 71 ▶sub _extract_options {
Subroutine _extract_options: called CC=10 SCAR=23.7
218 71 my ($options) = @_;
219  
220 71 ▶ return {} if $options !~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $options =~ /\S/ 24 47 71
221  
222 47 my @components = grep { defined } $options =~ m{ $OPTION_EXTRACT }ogxms;
223  
224 47 my %options;
225 47 ▶ while (my ($neg, $key, $val) = splice @components, 0, 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@components, 0, 3)) 50 47 97
226 50 ▶ $options{$key} = $neg ? 0
Branch: 7 branches
BranchTrueFalseTotal
$neg ? : 3 47 50
!length($val) ? : 24 23 47
$val =~ /^ \((.*)\) $/msx ? : 6 17 23
$val =~ /^(\[ .* \])$/msx ? : 0 17 17
$val =~ /^(\{ .* \})$/msx ? : 0 17 17
$val =~ /^ \<\s*(.*?)\s*\> $/msx ? : 17 0 17
$val =~ /^ $LEFT_ANGLE\s*(.*?)\s*$RIGHT_ANGLE $/msx ? : 0 0 0
227 : !length $val ? 1
228 : $val =~ /^ \((.*)\) $/xms ? eval($1)
229 : $val =~ /^(\[ .* \])$/xms ? eval($1)
230 : $val =~ /^(\{ .* \})$/xms ? eval($1)
231 : $val =~ /^ \<\s*(.*?)\s*\> $/xms ? [split /\s+/, $1]
232 : $val =~ /^ $LEFT_ANGLE\s*(.*?)\s*$RIGHT_ANGLE $/xms
233 ? [_shell_split($1)]
234 : die "Internal error"
235 ;
236 }
237  
238 47 return \%options;
239 }
240  
241  
242 # Track hierarchical counters for numbered blocks...
243 46 ▶sub _next_number_for {
Subroutine _next_number_for: called CC=7 SCAR=19.5
244 46 my ($type, $depth, $disjoint, $state_ref) = @_;
245  
246 # Retrieve (or create) counter for this block type...
247 46 ▶ my $numbers = $state_ref->{numberer_for}{$type} ||= [];
Condition100%2/2
$state_ref->{"numberer_for"}{$type} ||= []
l!l
3115
MC/DC100%1/1
$state_ref->{"numberer_for"}{$type} ||= []
$state_ref->{"numberer_for"}{$type}
Truth table100%2/2
A
A= $state_ref->{"numberer_for"}{$type}
Aresult
11
00
248  
249 # Reset top-level item if disjoint from previous items...
250 46 ▶ if ($disjoint && $depth == 1 && $type eq 'item') {
Branch: 1 branch
BranchTrueFalseTotal
if ($disjoint and $depth == 1 and $type eq "item") 8 38 46
Condition66%4/6
$disjoint and $depth == 1 and $type eq "item"
!ll&&!rl&&r
3808
$disjoint and $depth == 1
!ll&&!rl&&r
3808
MC/DC33%1/3
$disjoint and $depth == 1 and $type eq "item"
$disjoint $depth == 1 $type eq "item"
Truth table50%2/4
A and B and C
A= $disjointB= $depth == 1C= $type eq "item"
ABCresult
0XX0
10X0
1100
1111
251 8 @{$numbers} = (0);
252 }
253  
254 # Update according to relative depth...
255 46 ▶ if ($depth > @{$numbers}) { # nesting increased -> extend
Branch: 2 branches
BranchTrueFalseTotal
if ($depth > @{$numbers;}) { } 13 33 46
elsif ($depth == @{$numbers;}) { } 30 3 33
256 13 push @{$numbers}, (1) x ($depth-@{$numbers});
257 }
258 33 elsif ($depth == @{$numbers}) { # nesting stays at same level
259 30 $numbers->[-1]++;
260 }
261 else { # nesting decreased -> truncate
262 3 @{$numbers} = @{$numbers}[0..$depth-1];
263 3 $numbers->[-1]++;
264 }
265
266 46 return join '.', @{$numbers};
267 }
268  
269 # Handle block numbering and formatting...
270 577 ▶sub _resolve_numbering {
Subroutine _resolve_numbering: called CC=16 SCAR=27.7
271 577 my ($data, $state_ref) = @_;
272  
273 # Handle :numbered set-up
274 577 ▶ if ($data->{typename} =~ m{\A (\w+?)(\d*) \Z}xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"typename"} =~ /\A (\w+?)(\d*) \Z/msx) 450 127 577
275 450 ▶ my ($type, $depth) = ($1, $2||1);
Condition100%2/2
$2 || 1
l!l
66384
MC/DC100%1/1
$2 || 1
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
276 450 my $content_ref = \($data->{content}[0]);
277  
278 # Is this block explicitly numbered?
279 450 my $explicitly_numbered = $data->{options}{numbered};
280 450 ▶ if (!defined $explicitly_numbered) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $explicitly_numbered) 430 20 450
281 430 $explicitly_numbered = $data->{config}{numbered};
282 }
283
284 # Otherwise, two types of block support implicit (#) numbering...
285 my $implicitly_numbered
286 = ($type eq 'head' || $type eq 'item')
287 && !defined($explicitly_numbered)
288 65 && !ref(${$content_ref})
289 62 && defined ${$content_ref}
290 450 ▶ && ${$content_ref} =~ m{ \A \s* [#] [^\S\n]+ }xms
Condition93%14/15
($type eq 'head' || $type eq 'item') && !defined($explicitly_numbered) && !ref(${$content_ref;}) && defined ${$content_ref;} && ${$content_ref;} =~ / \A \s* [#] [^\S\n]+ /msx
!ll&&!rl&&r
3883923
$type eq "head" || $type eq "item" and not defined $explicitly_numbered and not ref ${$content_ref;} and defined ${$content_ref;}
!ll&&!rl&&r
388062
$type eq "head" || $type eq "item" and not defined $explicitly_numbered and not ref ${$content_ref;}
!ll&&!rl&&r
385362
$type eq "head" || $type eq "item" and not defined $explicitly_numbered
!ll&&!rl&&r
3642165
$type eq "head" or $type eq "item"
l!l&&r!l&&!r
3650364
MC/DC83%5/6
($type eq 'head' || $type eq 'item') && !defined($explicitly_numbered) && !ref(${$content_ref;}) && defined ${$content_ref;} && ${$content_ref;} =~ / \A \s* [#] [^\S\n]+ /msx
$type eq "head" $type eq "item" not defined $explicitly_numbered not ref ${$content_ref;} defined ${$content_ref;} ${$content_ref;} =~ / \A \s* [#] [^\S\n]+ /msx
Truth table81%9/11
A or B and not(C) and not(D) and E && F
A= $type eq "head"B= $type eq "item"C= not defined $explicitly_numberedD= not ref ${$content_ref;}E= defined ${$content_ref;}F= ${$content_ref;} =~ / \A \s* [#] [^\S\n]+ /msx
ABCDEFresult
00XXXX0
1X0XXX0
010XXX0
1X10XX0
0110XX0
1X110X0
01110X0
1X11100
0111100
1X11111
0111111
291 ;
292  
293 # Number if necessary...
294 450 ▶ if ($explicitly_numbered || $implicitly_numbered) {
Branch: 1 branch
BranchTrueFalseTotal
if ($explicitly_numbered or $implicitly_numbered) 46 404 450
Condition100%3/3
$explicitly_numbered or $implicitly_numbered
l!l&&r!l&&!r
2323404
MC/DC100%2/2
$explicitly_numbered or $implicitly_numbered
$explicitly_numbered $implicitly_numbered
Truth table100%3/3
A or B
A= $explicitly_numberedB= $implicitly_numbered
ABresult
1X1
011
000
295 # Clean up the magic leading # if present...
296 46 ▶ if ($implicitly_numbered) {
Branch: 1 branch
BranchTrueFalseTotal
if ($implicitly_numbered) 23 23 46
297 23 ${$content_ref} =~ s{\A \s* [#] [^\S\n]+ }{}xms
298 }
299 my $disjoint = $data->{disjoint}
300 && !$data->{options}{continued}
301 46 ▶ && !$data->{config}{continued};
Condition83%5/6
$data->{'disjoint'} && !$data->{'options'}{'continued'} && !$data->{'config'}{'continued'}
!ll&&!rl&&r
3808
$data->{"disjoint"} and not $data->{"options"}{"continued"}
!ll&&!rl&&r
3718
MC/DC66%2/3
$data->{'disjoint'} && !$data->{'options'}{'continued'} && !$data->{'config'}{'continued'}
$data->{"disjoint"} not $data->{"options"}{"continued"} !$data->{'config'}{'continued'}
Truth table75%3/4
A and not(B) && not(C)
A= $data->{"disjoint"}B= not $data->{"options"}{"continued"}C= !$data->{'config'}{'continued'}
ABCresult
0XX0
10X0
1100
1111
302 $data->{number}
303 46 = _next_number_for($type, $depth, $disjoint, $state_ref);
304 }
305 }
306  
307 # Recurse to process contents...
308 577 for my $subtree ( @{ $data->{content} } ) {
309 798 ▶ next if !ref $subtree;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $subtree 348 450 798
310 450 _resolve_numbering($subtree, $state_ref);
311 }
312 }
313  
314  
315 # Create object tree from hash tree...
316 56 my $head_max = 4; # Maximum predefined =headN block
317  
318 577 ▶sub _create_objects {
Subroutine _create_objects: called CC=15 SCAR=27.1
319 577 my ($tree, $state_ref) = @_; # $state_ref tracks global numbering, etc.
320  
321 # Recursively create subtrees first...
322 577 ▶ for my $subtree ( @{ $tree->{content} || [] }) {
Condition50%1/2
$tree->{'content'} || []
l!l
5770
MC/DC0%0/1
$tree->{'content'} || []
$tree->{'content'}
Truth table50%1/2
A
A= $tree->{'content'}
Aresult
11
00
323 798 ▶ if (ref $subtree) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $subtree) 450 348 798
324 450 $subtree = _create_objects($subtree, $state_ref);
325 }
326 }
327  
328 # Translate block names to class names, tracking reserved blocks...
329 577 my $is_reserved;
330 577 my $classname = 'Perl6::Perldoc::';
331 577 my $typename = $tree->{typename};
332  
333 # Parenthesized name -> parser introduced (so its given its own name)
334 577 ▶ if ($typename =~ m{^\( (\w+) \)}xms) {
Branch: 4 branches
BranchTrueFalseTotal
if ($typename =~ /^\( (\w+) \)/msx) { } 127 450 577
elsif ($tree->{'style'} eq 'formatting') { } 66 384 450
elsif ($tree->{'style'} eq 'directive') { } 9 375 384
elsif ($typename =~ /[[:upper:]]/msx and $typename =~ /[[:lower:]]/msx) { } 7 368 375
335 127 $classname .= "\u$1";
336 }
337 # Formatting codes are all subclasses of FormattingCode...
338 elsif ($tree->{style} eq 'formatting') {
339 66 $classname .= "FormattingCode::$typename";
340 }
341 # Directives are all subclasses of Directive...
342 elsif ($tree->{style} eq 'directive') {
343 9 $classname .= "Directive::$typename";
344 }
345 # Mixed-class block names -> user-defined subclass of Named...
346 ▶ elsif ($typename =~ m{[[:upper:]]}xms && $typename =~ m{[[:lower:]]}xms) {
Condition100%3/3
$typename =~ /[[:upper:]]/msx and $typename =~ /[[:lower:]]/msx
!ll&&!rl&&r
35997
MC/DC100%2/2
$typename =~ /[[:upper:]]/msx and $typename =~ /[[:lower:]]/msx
$typename =~ /[[:upper:]]/msx $typename =~ /[[:lower:]]/msx
Truth table100%3/3
A and B
A= $typename =~ /[[:upper:]]/msxB= $typename =~ /[[:lower:]]/msx
ABresult
0X0
100
111
347 7 $classname .= "Block::Named::$tree->{typename}";
348 56 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
349 7 push @{$classname.'::ISA'}, 'Perl6::Perldoc::Block::Named';
350 }
351 # All upper or all lower case -> reserved block
352 else {
353 368 $tree->{is_semantic} = $typename =~ m{[[:upper:]]}xms;
354 368 $is_reserved = $typename !~ m{\A (?:head|item) \d+ \z }xms;
355 368 $classname .= "Block::$tree->{typename}";
356  
357 # Any non-existent headN classes inherit last defined headN class...
358 368 ▶ if ($classname =~ m{:: head (\d+) \z}xms) {
Branch: 2 branches
BranchTrueFalseTotal
if ($classname =~ /:: head (\d+) \z/msx) { } 36 332 368
elsif ($classname =~ /:: item (\d+) \z/msx) { } 30 302 332
359 36 my $head_level = $1;
360 36 $tree->{level} = $head_level;
361 36 ▶ if ($head_level > $head_max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head_level > $head_max) 3 33 36
362 56 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
363 3 @{ 'Perl6::Perldoc::Block::head'.$head_level.'::ISA' }
364 = 'Perl6::Perldoc::Block::head'.$head_max;
365 }
366 }
367  
368 # Any non-existent itemN classes act like existent itemN classes...
369 elsif ($classname =~ m{:: item (\d+) \z}xms) {
370 30 ▶ my $item_level = $1 || 1;
Condition50%1/2
$1 || 1
l!l
300
MC/DC0%0/1
$1 || 1
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
371 30 $tree->{level} = $item_level;
372  
373 56 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
374 30 @{ 'Perl6::Perldoc::Block::item'.$item_level.'::ISA' }
375 = 'Perl6::Perldoc::Block::item';
376 }
377 }
378  
379 # Construct corresponding object if possible...
380 return $classname->new($tree, { errors=>$state_ref->{errors}, })
381 577 ▶ if $classname->can('new');
Branch: 1 branch
BranchTrueFalseTotal
if $classname->can("new") 576 1 577
382  
383 # If a built-in but no constructor, must be unknown...
384 1 ▶ if ($is_reserved) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_reserved) 1 0 1
385 1 _err_unknown_reserved_block($tree, $state_ref->{errors});
386 }
387  
388 # Otherwise, bless the raw data itself as an object...
389 1 return bless $tree, $classname;
390 }
391  
392 # Create a new config frame for a =config directive...
393 9 ▶sub _extend_config {
Subroutine _extend_config: called CC=13 SCAR=27.8
394 9 my ($curr_config_ref, $target_block, $new_opts_ref) = @_;
395  
396 # Default new config to copy of old config...
397 9 my %config = %{$curr_config_ref};
398  
399 # Default new target block in config to copy of old target block...
400 $config{$target_block}
401 0 ▶ = $config{$target_block} ? {%{$config{$target_block}}} : {};
Branch: 1 branch
BranchTrueFalseTotal
$config{$target_block} ? : 0 9 9
402  
403 # Change basis of target if :like specified
404 9 my $likeness = $new_opts_ref->{like};
405 9 ▶ if ($likeness) {
Branch: 1 branch
BranchTrueFalseTotal
if ($likeness) 1 8 9
406 1 ▶ for my $alike (ref $likeness eq 'ARRAY' ? reverse @{$likeness} : $likeness) {
Branch: 1 branch
BranchTrueFalseTotal
ref $likeness eq 'ARRAY' ? : 1 0 1
407 1 my $like_config_ref = $curr_config_ref->{$alike};
408 1 for my $option (keys %{$like_config_ref}) {
409 1 unshift @{ $config{$target_block}{$option} },
410 1 ▶ @{$curr_config_ref->{$alike}{$option}||[]};
Condition50%1/2
$curr_config_ref->{$alike}{$option} || []
l!l
10
MC/DC0%0/1
$curr_config_ref->{$alike}{$option} || []
$curr_config_ref->{$alike}{$option}
Truth table50%1/2
A
A= $curr_config_ref->{$alike}{$option}
Aresult
11
00
411 }
412 }
413 }
414  
415 # Update all keys of target that appear in new options...
416 9 for my $opt (keys %{$new_opts_ref}) {
417 10 ▶ next if $opt eq 'like';
Branch: 1 branch
BranchTrueFalseTotal
if $opt eq "like" 1 9 10
418  
419 9 my $old_type = ref $config{$target_block}{$opt};
420 9 my $new_type = ref $new_opts_ref->{$opt};
421  
422 9 ▶ if (!$old_type) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $old_type) { } 8 1 9
elsif ($old_type ne $new_type) { } 0 1 1
elsif ($old_type eq 'ARRAY') { } 1 0 1
elsif ($old_type eq 'HASH') { } 0 0 0
423 8 $config{$target_block}{$opt} = $new_opts_ref->{$opt};
424 }
425 elsif ($old_type ne $new_type) {
426 0 die "Internal error: type mismatch on :$opt ($old_type vs $new_type)";
427 }
428 elsif ($old_type eq 'ARRAY') {
429 $config{$target_block}{$opt}
430 1 = [@{$config{$target_block}{$opt}}, @{$new_opts_ref->{$opt}}];
431 }
432 elsif ($old_type eq 'HASH') {
433 $config{$target_block}{$opt}
434 0 = { %{$config{$target_block}{$opt}}, %{$new_opts_ref->{$opt}}};
435 }
436 else {
437 0 die "Internal error: bad :$opt of type $new_type";
438 }
439 }
440  
441 9 return \%config;
442 }
443  
444 # Open or close implicit list blocks around item blocks
445  
446 1395 ▶sub _adjust_lists {
Subroutine _adjust_lists: called CC=12 SCAR=24.8
447 1395 my ($stack_ref, $line, $is_item, $is_comment,
448 $item_level, $range_ref, $warnings_ref) = @_;
449  
450 1395 my $parent_ref = $stack_ref->[-1];
451  
452 # Ignore blank lines and comments...
453 1395 ▶ return $parent_ref if $line !~ m{\S}xms || $is_comment;
Branch: 1 branch
BranchTrueFalseTotal
if not $line =~ /\S/msx or $is_comment 75 1320 1395
Condition100%3/3
not $line =~ /\S/msx or $is_comment
l!l&&r!l&&!r
7051320
MC/DC100%2/2
not $line =~ /\S/msx or $is_comment
not $line =~ /\S/msx $is_comment
Truth table100%3/3
not(A) or B
A= not $line =~ /\S/msxB= $is_comment
ABresult
1X1
011
000
454  
455 # Are we there yet?
456 1320 my $is_in_list = $parent_ref->{typename} eq 'list';
457 1320 ▶ my $list_level = $parent_ref->{level} || 0;
Condition100%2/2
$parent_ref->{'level'} || 0
l!l
371283
MC/DC100%1/1
$parent_ref->{'level'} || 0
$parent_ref->{'level'}
Truth table100%2/2
A
A= $parent_ref->{'level'}
Aresult
11
00
458  
459 # Ignore non-transition points...
460 1320 ▶ return $parent_ref
Branch: 1 branch
BranchTrueFalseTotal
if not $is_in_list || $is_item or $is_in_list and $is_item and $list_level == $item_level 1296 24 1320
Condition100%12/12
not $is_in_list || $is_item or $is_in_list and $is_item and $list_level == $item_level
l!l&&r!l&&!r
12672924
$is_in_list || $is_item
l!l&&r!l&&!r
37161267
$is_in_list and $is_item and $list_level == $item_level
!ll&&!rl&&r
19529
$is_in_list and $is_item
!ll&&!rl&&r
16334
MC/DC100%5/5
not $is_in_list || $is_item or $is_in_list and $is_item and $list_level == $item_level
$is_in_list $is_item $is_in_list $is_item $list_level == $item_level
Truth table55%5/9
not(A || B) or C and D and E
A= $is_in_listB= $is_itemC= $is_in_listD= $is_itemE= $list_level == $item_level
ABCDEresult
00XXX1
1X1111
011111
1X0XX0
1X10X0
1X1100
010XX0
0110X0
011100
461 if !$is_in_list && !$is_item
462 || $is_in_list && $is_item && $list_level == $item_level;
463  
464 # Detect missing items...
465 24 ▶ if ($list_level < $item_level-1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list_level < $item_level - 1) 2 22 24
466 2 _err_missing_list_level($range_ref, $item_level, $warnings_ref);
467 }
468  
469 # Add required number of additional implicit lists...
470 24 my %range = %{ $range_ref };
471 24 ▶ while ($list_level < $item_level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list_level < $item_level) 22 24 46
472 22 $list_level++;
473 22 push @{$stack_ref}, {
474 typename => 'list',
475 style => 'implicit',
476 range => \%range,
477 level => $list_level,
478 # terminator => $FAIL,
479 terminator => qr{ (?= $parent_ref->{terminator} ) }xms,
480 allow => $parent_ref->{allow},
481 22 };
482 }
483  
484 # Alternatively, close required number of nested lists...
485 24 ▶ while ($list_level > $item_level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list_level > $item_level) 4 24 28
486 4 my $list_block = pop @{$stack_ref};
487 4 $list_block->{range}{to} = $range{from}-1;
488 4 push @{ $stack_ref->[-1]{content} }, $list_block;
489 4 $list_level--;
490 }
491  
492 24 return $stack_ref->[-1];
493 }
494  
495 # Handle :like option (effectively prepending other defn to options)...
496 150 ▶sub _handle_likeness {
Subroutine _handle_likeness: called CC=7 SCAR=19.7
497 150 my ($top_ref, $config_ref) = @_;
498  
499 150 ▶ my %options = %{ $top_ref->{options} || {} };
Condition100%2/2
$top_ref->{'options'} || {}
l!l
6981
MC/DC100%1/1
$top_ref->{'options'} || {}
$top_ref->{'options'}
Truth table100%2/2
A
A= $top_ref->{'options'}
Aresult
11
00
500 150 ▶ if ( my $like = $options{like} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $like = $options{"like"}) 1 149 150
501 1 ▶ my @likenesses = (ref($like)||q{}) eq 'ARRAY' ? @{ $like } : $like;
Branch: 1 branch
BranchTrueFalseTotal
(ref $like || '') eq 'ARRAY' ? : 1 0 1
Condition50%1/2
ref $like || ''
l!l
10
MC/DC0%0/1
ref $like || ''
ref $like
Truth table50%1/2
A
A= ref $like
Aresult
11
00
502  
503 1 for my $likeness (reverse @likenesses) {
504 %options = (
505 1 ▶ %{ $config_ref->{$likeness} || {} },
Condition50%1/2
$config_ref->{$likeness} || {}
l!l
10
MC/DC0%0/1
$config_ref->{$likeness} || {}
$config_ref->{$likeness}
Truth table50%1/2
A
A= $config_ref->{$likeness}
Aresult
11
00
506 %options,
507 );
508 }
509 }
510  
511 150 return \%options;
512 }
513  
514  
515 # Handle any :formatted() options by imposing extra levels on stack...
516 141 ▶sub _handle_formatted {
Subroutine _handle_formatted: called CC=8 SCAR=22.7
517 141 my ($top, $range_ref, $config_ref, $errors_ref) = @_;
518 141 my $location = _loc($range_ref);
519  
520 # Locate formatted options (on block itself or in block type's config)...
521 my $formatted = $top->{options}{formatted}
522 141 ▶ || $config_ref->{$top->{typename}}{formatted};
Condition100%3/3
$top->{'options'}{'formatted'} || $$config_ref{$top->{'typename'}}{'formatted'}
l!l&&r!l&&!r
12138
MC/DC100%2/2
$top->{'options'}{'formatted'} || $$config_ref{$top->{'typename'}}{'formatted'}
$top->{'options'}{'formatted'} $$config_ref{$top->{'typename'}}{'formatted'}
Truth table100%3/3
A || B
A= $top->{'options'}{'formatted'}B= $$config_ref{$top->{'typename'}}{'formatted'}
ABresult
1X1
011
000
523 141 ▶ return if !$formatted;
Branch: 1 branch
BranchTrueFalseTotal
unless $formatted 138 3 141
524  
525 # Bad option! No biscuit!
526 3 ▶ if ((ref($formatted)||q{}) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ((ref $formatted || "") ne "ARRAY") 0 3 3
Condition50%1/2
ref $formatted || ''
l!l
30
MC/DC0%0/1
ref $formatted || ''
ref $formatted
Truth table50%1/2
A
A= ref $formatted
Aresult
11
00
527 0 push @{$errors_ref},
528 qq{Value of :formatted option not an array at $location};
529 0 return;
530 }
531  
532 3 my $terminator = "(?=$top->{terminator})";
533 3 my $verbatim = $top->{is_verbatim};
534  
535 3 my $permits_implicit_blocks = $top->{permits_implicit_blocks};
536  
537 # Work through specified formatting codes, adding nested block for each...
538 3 my @blocks;
539 3 my %range = %{$range_ref};
540 FCODE:
541 3 for my $fcode (@{ $formatted }) {
542 5 ▶ if ($fcode !~ $FORMATTING_CODE) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fcode =~ /$FORMATTING_CODE/) 0 5 5
543 0 push @{$errors_ref},
544 qq{Unknown formatting code ($fcode) in :formatted option at $location};
545 0 next FCODE;
546 }
547 5 ▶ $verbatim ||= $fcode =~ m{[VCMP]}xms;
Condition33%1/3
$verbatim ||= $fcode =~ /[VCMP]/msx
l!l&&r!l&&!r
005
MC/DC0%0/2
$verbatim ||= $fcode =~ /[VCMP]/msx
$verbatim $fcode =~ /[VCMP]/msx
Truth table33%1/3
A ||= B
A= $verbatimB= $fcode =~ /[VCMP]/msx
ABresult
1X1
011
000
548 push @blocks, {
549 typename => $fcode,
550 style => 'formatting',
551 5 config => $config_ref->{"$fcode<>"},
552 range => \%range,
553 initiator => '(?!)',
554 terminator => $terminator,
555 left_delim => q{},
556 right_delim => q{},
557 is_verbatim => $verbatim,
558 is_implicit => 1,
559 permits_implicit_blocks => $permits_implicit_blocks,
560 };
561 }
562 3 return @blocks;
563 }
564  
565 # Track which nested formatting codes are allowed for a given block...
566 434 ▶sub _update_allow {
Subroutine _update_allow: called CC=5 SCAR=16.2
567 434 my ($top, $config, $options) = @_;
568 434 ▶ my %new_allow = %{ $top->{allow} || {} };
Condition100%2/2
$top->{'allow'} || {}
l!l
306128
MC/DC100%1/1
$top->{'allow'} || {}
$top->{'allow'}
Truth table100%2/2
A
A= $top->{'allow'}
Aresult
11
00
569  
570 # If not explicit on block, try config...
571 434 ▶ if (my $src_ref = $options->{allow} || $config->{allow}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $src_ref = $options->{"allow"} || $config->{"allow"}) 10 424 434
Condition100%3/3
$options->{'allow'} || $config->{'allow'}
l!l&&r!l&&!r
73424
MC/DC100%2/2
$options->{'allow'} || $config->{'allow'}
$options->{'allow'} $config->{'allow'}
Truth table100%3/3
A || B
A= $options->{'allow'}B= $config->{'allow'}
ABresult
1X1
011
000
572 10 ▶ if (ref $src_ref eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $src_ref eq 'ARRAY') { } 10 0 10
573 10 @new_allow{ @{$src_ref} } = ();
574 }
575 else {
576 0 $new_allow{ $src_ref } = undef;
577 }
578 }
579  
580 434 return \%new_allow;
581 }
582  
583  
584 # Parse input from a filehandle or filename, extracting the Pod...
585 128 ▶sub parse {
Subroutine parse: called CC=110 SCAR=53.8
Pod documented
586 128 my ($classname, $filehandle, $opt_ref) = @_;
587 128 my $filename = $opt_ref->{filename};
588  
589 # Reset the id generator if asked to
590 128 ▶ Perl6::Perldoc::Root::_reset_id() if $opt_ref->{reset_id};
Branch: 1 branch
BranchTrueFalseTotal
if $opt_ref->{"reset_id"} 0 128 128
591  
592 # If filename passed, open it...
593 128 ▶ if (!ref $filehandle) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $filehandle) { } 1 127 128
elsif (ref $filehandle eq 'SCALAR') { } 1 126 127
594 1 $filename = $filehandle;
595 1 undef $filehandle;
596 1 ▶ open $filehandle, '<', $filename
Branch: 1 branch
BranchTrueFalseTotal
open $filehandle, "<", $filename or require Carp and Carp::croak("parse() can't open file $filename ($!)") 0 1 1
Condition40%2/5
open($filehandle, '<', $filename) || require Carp && Carp::croak("parse() can't open file $filename ($!)")
l!l&&r!l&&!r
010
require Carp and Carp::croak("parse() can't open file $filename ($!)")
!ll
01
MC/DC0%0/2
open($filehandle, '<', $filename) || require Carp && Carp::croak("parse() can't open file $filename ($!)")
open($filehandle, '<', $filename) require Carp
Truth table33%1/3
A || B
A= open($filehandle, '<', $filename)B= require Carp
ABresult
1X1
011
000
597 or require Carp
598 and Carp::croak("parse() can't open file $filename ($!)");
599  
600 0 ▶ if (!exists $opt_ref->{all_pod} || $opt_ref->{all_pod} =~ m{\A auto \z}ixms) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $opt_ref->{"all_pod"} or $opt_ref->{"all_pod"} =~ /\A auto \z/imsx) 0 0 0
Condition0%0/3
not exists $opt_ref->{"all_pod"} or $opt_ref->{"all_pod"} =~ /\A auto \z/imsx
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $opt_ref->{"all_pod"} or $opt_ref->{"all_pod"} =~ /\A auto \z/imsx
not exists $opt_ref->{"all_pod"} $opt_ref->{"all_pod"} =~ /\A auto \z/imsx
Truth table0%0/3
not(A) or B
A= not exists $opt_ref->{"all_pod"}B= $opt_ref->{"all_pod"} =~ /\A auto \z/imsx
ABresult
1X1
011
000
601 0 $opt_ref->{all_pod} = $filename =~ m{ [.] pod6? }xms;
602 }
603 }
604  
605 # If a reference to a scalar is passed, convert it to a filehandle...
606 elsif (ref($filehandle) eq 'SCALAR') {
607 1 my $data_source = $filehandle;
608 1 undef $filehandle;
609 1 ▶ open $filehandle, '<', $data_source
Branch: 1 branch
BranchTrueFalseTotal
open $filehandle, "<", $data_source or require Carp and Carp::croak("parse() can't parse from string ($!)") 1 0 1
Condition20%1/5
open($filehandle, '<', $data_source) || require Carp && Carp::croak("parse() can't parse from string ($!)")
l!l&&r!l&&!r
100
require Carp and Carp::croak("parse() can't parse from string ($!)")
!ll
00
MC/DC0%0/2
open($filehandle, '<', $data_source) || require Carp && Carp::croak("parse() can't parse from string ($!)")
open($filehandle, '<', $data_source) require Carp
Truth table33%1/3
A || B
A= open($filehandle, '<', $data_source)B= require Carp
ABresult
1X1
011
000
610 or require Carp
611 and Carp::croak("parse() can't parse from string ($!)");
612 }
613  
614 # Remember where we found this data...
615 127 my %range = ( file=>$filename, from => 0 );
616  
617 # Initialize stack representation of Pod...
618 127 my @stack = {
619 typename => '(document)',
620 terminator => $FAIL,
621 range => {%range},
622 };
623  
624 # Initialize configuration stack to track lexical =config directives
625 127 ▶ my @config_stack = $opt_ref->{config_stack} || {};
Condition100%2/2
$opt_ref->{'config_stack'} || {}
l!l
6364
MC/DC100%1/1
$opt_ref->{'config_stack'} || {}
$opt_ref->{'config_stack'}
Truth table100%2/2
A
A= $opt_ref->{'config_stack'}
Aresult
11
00
626  
627 # Track P<toc:...> requests...
628 127 my @toc_placements;
629  
630 # Add implicit =pod block if caller indicates it's all pod...
631 127 ▶ if ($opt_ref->{all_pod}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_ref->{"all_pod"}) 116 11 127
632 116 push @stack, {
633 typename => 'pod',
634 style => 'implicit',
635 config => {},
636 range => { %range },
637 terminator => $FAIL,
638 is_implicit => 1,
639 permits_implicit_blocks => 1,
640 };
641 }
642  
643 # Initialize look-up table of allowed formatting codes...
644 127 ▶ $stack[-1]{allow} = _update_allow($opt_ref||{},{},{});
Condition50%1/2
$opt_ref || {}
l!l
1270
MC/DC0%0/1
$opt_ref || {}
$opt_ref
Truth table50%1/2
A
A= $opt_ref
Aresult
11
00
645  
646 # Storage for reporting problems...
647 127 my (@errors, @warnings);
648  
649 # Is a block with options waiting for possible extra options?
650 127 my $has_options_pending;
651  
652  
653 # Parse input line-by-line...
654 LINE:
655 127 ▶ while (my $line = <$filehandle>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $filehandle)) 582 127 709
656 582 pos $line = 0;
657 582 $range{from} = $.;
658 582 my $is_directive = substr($line, 0, 1) eq '=';
659  
660 # Within line, parse out each token...
661 TOKEN:
662 582 ▶ while (pos $line < length $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $line < length $line) 1656 474 2130
663 ### AT: substr($line, pos $line)
664 1656 my $top = $stack[-1];
665  
666 # Check and process options pending...
667 1656 ▶ if ($has_options_pending) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_options_pending) 71 1585 1656
668 # Extra options on a line immediately after a block specifier...
669 71 ▶ if ($line =~ m{ \G ^ = (\s+ $OPTIONS) \s* $ }ogcxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ / \G ^ = (\s+ $OPTIONS) \s* $ /cgmosx) { } 2 69 71
670 2 my $options = $1;
671  
672 $top->{options} =
673 2 { %{ $top->{options} },
674 2 %{ _extract_options($options) },
675 };
676  
677 ### Adding more options: $stack[-1]
678 2 next LINE;
679 }
680  
681 # No extra options, then handle :like, :formatted options...
682 else {
683 69 my $config_ref = $config_stack[-1];
684 69 $top->{options} = _handle_likeness($top, $config_ref);
685  
686 69 ▶ if ($top->{style} =~ m{\A (?:delimited|paragraph) \z}xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($top->{"style"} =~ /\A (?:delimited|paragraph) \z/msx) 60 9 69
687 60 push @stack, _handle_formatted(
688 $top, \%range, $config_ref, \@errors
689 );
690 }
691 69 $has_options_pending = 0;
692  
693 $top->{allow}
694 = _update_allow( $stack[-2],
695 $config_ref->{$top->{typename}},
696 $top->{options}
697 69 );
698 }
699 }
700  
701 # A close marker for the innermost block or formatting code...
702 1654 ▶ if ($line =~ m{ \G ($top->{terminator}) }gcxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ / \G ($top->{"terminator"}) /cgmsx) 248 1406 1654
703 248 my $terminator = $1;
704  
705 # Is this an implicit close (i.e. an outer block closing)?
706 248 ▶ if (length($terminator) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $terminator == 0) 85 163 248
707 85 _err_no_closing_delim($top, \@errors, \@warnings);
708 85 pos $line = pos $line; # Workaround for bug in /gc :-(
709 }
710  
711 # Is this a nested close marker in a formatting code?
712 248 ▶ if ($top->{style} eq 'formatting' && $top->{delim_nesting}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($top->{'style'} eq 'formatting' and $top->{'delim_nesting'}) { } 7 241 248
Condition100%3/3
$top->{"style"} eq "formatting" and $top->{"delim_nesting"}
!ll&&!rl&&r
175667
MC/DC100%2/2
$top->{"style"} eq "formatting" and $top->{"delim_nesting"}
$top->{"style"} eq "formatting" $top->{"delim_nesting"}
Truth table100%3/3
A and B
A= $top->{"style"} eq "formatting"B= $top->{"delim_nesting"}
ABresult
0X0
100
111
713 # If so, decrease the nesting and treat as plain content...
714 7 $top->{delim_nesting}--;
715 7 _add_content($top, $terminator);
716 ### Added nested formatting code terminator
717 }
718 # If not nested formatting code delimiter, close the block...
719 else {
720 241 my $block = pop @stack;
721  
722 # Ignore attempts to terminate an END block...
723 241 ▶ if ($block->{typename} eq 'END') {
Branch: 1 branch
BranchTrueFalseTotal
if ($block->{"typename"} eq "END") 1 240 241
724 1 push @stack, $block;
725 1 next TOKEN;
726 }
727  
728 # Execute any use statement...
729 240 ▶ if ($block->{typename} eq '(use)') {
Branch: 1 branch
BranchTrueFalseTotal
if ($block->{"typename"} eq "(use)") 0 240 240
730 0 my $source = $block->{source};
731 0 ▶ if (eval "require $source") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require $source") { } 0 0 0
732 my %options = (
733 0 ▶ %{ $block->{config}{use}||{} },
Condition0%0/2
$block->{'config'}{'use'} || {}
l!l
00
MC/DC0%0/1
$block->{'config'}{'use'} || {}
$block->{'config'}{'use'}
Truth table0%0/2
A
A= $block->{'config'}{'use'}
Aresult
11
00
734 0 ▶ %{ $block->{options} || {} },
Condition0%0/2
$block->{'options'} || {}
l!l
00
MC/DC0%0/1
$block->{'options'} || {}
$block->{'options'}
Truth table0%0/2
A
A= $block->{'options'}
Aresult
11
00
735 );
736 0 $source->import(\%options);
737 }
738 else {
739 0 _err_use_cant_load($source, \%range, \@errors);
740 0 next TOKEN;
741 }
742 }
743  
744 # Syncronize config stack...
745 240 ▶ for (1..$block->{has_config}||0) {
Condition50%1/2
$block->{'has_config'} || 0
l!l
0240
MC/DC0%0/1
$block->{'has_config'} || 0
$block->{'has_config'}
Truth table50%1/2
A
A= $block->{'has_config'}
Aresult
11
00
746 0 pop @config_stack;
747 }
748
749 # Incorporate closed block into representation...
750 240 ▶ if ($block->{style} ne 'implicit' || $block->{content}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($block->{'style'} ne 'implicit' or $block->{'content'}) { } 240 0 240
Condition66%2/3
$block->{"style"} ne "implicit" or $block->{"content"}
l!l&&r!l&&!r
206340
MC/DC0%0/2
$block->{"style"} ne "implicit" or $block->{"content"}
$block->{"style"} ne "implicit" $block->{"content"}
Truth table66%2/3
A or B
A= $block->{"style"} ne "implicit"B= $block->{"content"}
ABresult
1X1
011
000
751 # Complete line range...
752 240 $block->{range}{to} = $range{from};
753  
754 # Remove parser-specific internal data...
755 240 delete @{$block}{qw<terminator initiator allow>};
756  
757 # Add block to parent...
758 240 push @{ $stack[-1]{content} }, $block;
759
760 ### Terminated block: $block
761 }
762 else {
763 ### Threw away empty implicit block: $block
764 }
765 }
766 247 next TOKEN;
767 }
768  
769 # Content of comments is appended raw...
770 1406 ▶ if ($top->{typename} eq 'comment' && $line !~ $DIR_COMMENT_BLOCK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($top->{"typename"} eq "comment" and not $line =~ /$DIR_COMMENT_BLOCK/) 7 1399 1406
Condition100%3/3
$top->{"typename"} eq "comment" and not $line =~ /$DIR_COMMENT_BLOCK/
!ll&&!rl&&r
139817
MC/DC100%2/2
$top->{"typename"} eq "comment" and not $line =~ /$DIR_COMMENT_BLOCK/
$top->{"typename"} eq "comment" not $line =~ /$DIR_COMMENT_BLOCK/
Truth table100%3/3
A and not(B)
A= $top->{"typename"} eq "comment"B= not $line =~ /$DIR_COMMENT_BLOCK/
ABresult
0X0
100
111
771 7 ▶ if (!$top->{content} || ref $top->{content}[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $top->{'content'} or ref $top->{'content'}[-1]) { } 6 1 7
Condition100%3/3
not $top->{"content"} or ref $top->{"content"}[-1]
l!l&&r!l&&!r
511
MC/DC100%2/2
not $top->{"content"} or ref $top->{"content"}[-1]
not $top->{"content"} ref $top->{"content"}[-1]
Truth table100%3/3
not(A) or B
A= not $top->{"content"}B= ref $top->{"content"}[-1]
ABresult
1X1
011
000
772 6 push @{ $top->{content} }, $line;
773 }
774 else {
775 1 $top->{content}[-1] .= $line;
776 }
777 7 next LINE;
778 }
779  
780 # All directives start with '=' on the line...
781 1399 ▶ if ($is_directive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_directive) 156 1243 1399
782 # Unexpected close marker for unopened block...
783 156 ▶ if ($line =~ m{\G ^ =end \s+ (\S+) }gcxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\G ^ =end \s+ (\S+) /cgmsx) 3 153 156
784 3 my $type = $1;
785 3 ▶ if ($type eq 'END') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'END') { } 2 1 3
786 2 _err_closed_END_block(\%range, \@warnings);
787 }
788 else {
789 1 _err_closed_unopened_block($type, \%range, \@errors);
790 }
791  
792 ### Unexpected =end $type: $line
793 3 next LINE;
794 }
795  
796 # Open marker for delimited block...
797 153 ▶ if ($line =~ m{\G ^ =begin \s+ ($IDENT) ($OPTIONS?) \s* (.*) $}ogcxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\G ^ =begin \s+ ($IDENT) ($OPTIONS?) \s* (.*) $/cgmosx) 35 118 153
798 35 my ($type, $options, $junk) = ($1, $2, $3);
799  
800 # Anything after last option is junk...
801 35 ▶ if ($junk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($junk) 0 35 35
802 0 _err_trailing_junk($type, \%range, $junk, \@errors);
803 }
804  
805 # Track level of =item blocks...
806 35 my ($is_item, $item_level)
807 = $type =~ m{\A (item)(\d+)? \Z}xms;
808 35 ▶ $item_level ||= $is_item ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$is_item ? : 2 32 34
Condition100%3/3
$item_level ||= $is_item ? 1 : 0
l!l&&r!l&&!r
1232
MC/DC100%2/2
$item_level ||= $is_item ? 1 : 0
$item_level $is_item ? 1 : 0
Truth table100%3/3
A ||= B
A= $item_levelB= $is_item ? 1 : 0
ABresult
1X1
011
000
809  
810 35 my $is_comment = $type eq 'comment';
811  
812 # Insert or close implicit list block if required...
813 35 $top = _adjust_lists(\@stack, $line, $is_item,
814 $is_comment, $item_level,
815 \%range, \@warnings
816 );
817 my $disjoint_item1
818 35 ▶ = $is_item && $item_level==1 && !$top->{content};
Condition83%5/6
$is_item && $item_level == 1 && !$top->{'content'}
!ll&&!rl&&r
3212
$is_item and $item_level == 1
!ll&&!rl&&r
3203
MC/DC66%2/3
$is_item && $item_level == 1 && !$top->{'content'}
$is_item $item_level == 1 !$top->{'content'}
Truth table75%3/4
A and B && not(C)
A= $is_itemB= $item_level == 1C= !$top->{'content'}
ABCresult
0XX0
10X0
1100
1111
819  
820 35 my $permits_implicit_blocks
821 = $type =~ m{$PERMITS_IMPLICIT_IF_DELIMITED}xms;
822  
823 35 $has_options_pending = 1;
824  
825 # Terminator is corresponding =end or parent's terminator...
826 35 ▶ my $terminator
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'END' ? : 2 33 35
827 = $type eq 'END' ? '(?!)'
828 : qr{^ =end \s+ \Q$type\E [^\n]* \n? $
829 | (?= $top->{terminator} )
830 }xms
831 ;
832  
833 35 $options = _extract_options($options);
834  
835 35 my $config = $config_stack[-1]{$type};
836 my @config_stack_entry
837 35 ▶ = $type eq 'table' ? (config_stack=>$config_stack[-1])
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'table' ? : 3 32 35
838 : ();
839  
840 35 my $verbatim = $type eq 'code';
841  
842 # Add to parsing stack (not yet in tree)...
843 push @stack, {
844 typename => $type,
845 style => 'delimited',
846 range => { %range },
847 options => $options,
848 config => $config,
849 @config_stack_entry,
850 terminator => $terminator,
851 is_verbatim => $verbatim || $top->{is_verbatim},
852 35 ▶ disjoint => $disjoint_item1,
Condition100%3/3
$verbatim || $top->{'is_verbatim'}
l!l&&r!l&&!r
6128
MC/DC100%2/2
$verbatim || $top->{'is_verbatim'}
$verbatim $top->{'is_verbatim'}
Truth table100%3/3
A || B
A= $verbatimB= $top->{'is_verbatim'}
ABresult
1X1
011
000
853 permits_implicit_blocks => $permits_implicit_blocks,
854 };
855  
856 ### Opened delimited block: $stack[-1]
857 35 next TOKEN;
858 }
859  
860 # Open marker for paragraph block...
861 118 ▶ if ($line =~ m{ \G ^ =for \s+ ($IDENT) ($OPTIONS?) \s* (.*) $ }ogcxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ / \G ^ =for \s+ ($IDENT) ($OPTIONS?) \s* (.*) $ /cgmosx) 25 93 118
862 25 my ($type, $options, $junk) = ($1, $2, $3);
863  
864 # Anything after last option is junk...
865 25 ▶ if ($junk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($junk) 1 24 25
866 1 _err_trailing_junk($type, \%range, $junk, \@errors);
867 }
868  
869 25 my $permits_implicit_blocks
870 = $type =~ m{$PERMITS_IMPLICIT}xms;
871  
872 # Track level of =item blocks...
873 25 my ($is_item, $item_level)
874 = $type =~ m{\A (item)(\d+)? \Z}xms;
875 25 ▶ $item_level ||= $is_item ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$is_item ? : 6 12 18
Condition100%3/3
$item_level ||= $is_item ? 1 : 0
l!l&&r!l&&!r
7612
MC/DC100%2/2
$item_level ||= $is_item ? 1 : 0
$item_level $is_item ? 1 : 0
Truth table100%3/3
A ||= B
A= $item_levelB= $is_item ? 1 : 0
ABresult
1X1
011
000
876
877 25 $has_options_pending = 1;
878  
879 25 my $is_comment = $type eq 'comment';
880  
881 # Insert or close implicit list block if required...
882 25 $top = _adjust_lists(\@stack, $line, $is_item,
883 $is_comment, $item_level,
884 \%range, \@warnings
885 );
886  
887 my $disjoint_item1
888 25 ▶ = $is_item && $item_level==1 && !$top->{content};
Condition100%6/6
$is_item && $item_level == 1 && !$top->{'content'}
!ll&&!rl&&r
1555
$is_item and $item_level == 1
!ll&&!rl&&r
12310
MC/DC100%3/3
$is_item && $item_level == 1 && !$top->{'content'}
$is_item $item_level == 1 !$top->{'content'}
Truth table100%4/4
A and B && not(C)
A= $is_itemB= $item_level == 1C= !$top->{'content'}
ABCresult
0XX0
10X0
1100
1111
889  
890 25 my $verbatim = $type eq 'code';
891  
892 25 $options = _extract_options($options);
893 25 my $config = $config_stack[-1]{$type};
894 my @config_stack_entry
895 25 ▶ = $type eq 'table' ? (config_stack=>$config_stack[-1])
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'table' ? : 1 24 25
896 : ();
897  
898 # Add to parsing stack (not yet in tree)...
899 push @stack, {
900 typename => $type,
901 style => 'paragraph',
902 range => { %range },
903 options => $options,
904 config => $config,
905 @config_stack_entry,
906 terminator => qr{ ^ \s* $
907 | $DIR_NC
908 | (?= $top->{terminator} )
909 }xms,
910 is_verbatim => $verbatim || $top->{is_verbatim},
911 25 ▶ is_blank_terminated => 1,
Condition33%1/3
$verbatim || $top->{'is_verbatim'}
l!l&&r!l&&!r
0025
MC/DC0%0/2
$verbatim || $top->{'is_verbatim'}
$verbatim $top->{'is_verbatim'}
Truth table33%1/3
A || B
A= $verbatimB= $top->{'is_verbatim'}
ABresult
1X1
011
000
912 disjoint => $disjoint_item1,
913 permits_implicit_blocks => $permits_implicit_blocks,
914 };
915  
916 ### Opened paragraph block: $stack[-1]
917 25 next TOKEN;
918 }
919  
920 # =use URI directive
921 93 ▶ if ($line =~ m{ \G ^ =use \s+ (\S+) ($OPTIONS?) \s* ([^\n]*) \n }ogcxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ / \G ^ =use \s+ (\S+) ($OPTIONS?) \s* ([^\n]*) \n /cgmosx) 1 92 93
922 1 my ($source, $options, $junk) = ($1, $2, $3);
923 1 my $orig_source = $source;
924  
925 # Anything after last option is junk...
926 1 ▶ if ($junk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($junk) 0 1 1
927 0 _err_trailing_junk('=use directive', \%range, $junk, \@errors);
928 }
929  
930 1 $has_options_pending = 1;
931  
932 # Insert or close implicit list block if required...
933 1 $top = _adjust_lists(\@stack, $line, 0, 0, 0, \%range, \@warnings);
934  
935 # Can use Perl 5 modules...
936 1 ▶ if ($source =~ m{\A (?:perl5:)? $QUAL_IDENT \Z}xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source =~ /\A (?:perl5:)? $QUAL_IDENT \Z/msx) 0 1 1
937 push @stack, {
938 typename => '(use)',
939 style => 'directive',
940 source => $source,
941 range => { %range },
942 terminator => qr{ ^ \s* $
943 | $DIR_NC
944 | (?= [^=] )
945 | (?= $top->{terminator} )
946 }xms,
947 options => _extract_options($options),
948 config => $config_stack[-1]{use},
949 0 is_blank_terminated => 1,
950 };
951  
952 ### =use directive: $stack[-1]
953 0 next TOKEN;
954 }
955  
956 # Otherwise, no options allowed (on direct inclusions)...
957 1 ▶ if ($options) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options) 0 1 1
958 0 _err_trailing_junk('=use directive', \%range,
959 $options, \@errors
960 );
961 }
962  
963 # Assume it's a Pod file; open it...
964 1 $source =~ s{\A file:}{}xms;
965 1 ▶ if (!-r $source) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $source) 1 0 1
966 1 _err_bad_use_uri($orig_source, \%range, \@errors);
967 next TOKEN
968 1 }
969  
970 0 my %opts;
971 0 ▶ if ($source =~ m{ [.]pod6 \Z }xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source =~ / [.]pod6 \Z /msx) 0 0 0
972 0 $opts{all_pod} = 1;
973 }
974  
975 # Then read, parse, and add in the result (recursively)...
976 0 my $result_ref
977 = Perl6::Perldoc::Parser->parse($source, \%opts);
978 0 ▶ if ($result_ref->{tree}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_ref->{"tree"}) 0 0 0
979 0 push @{$stack[-1]{content}}, {
980 typename => 'use',
981 style => 'directive',
982 uri => $orig_source,
983 range => { %range, to => $range{from} },
984 content => $result_ref->{tree}{content},
985 0 };
986 }
987  
988 # Propagate any warnings or errors...
989 0 ▶ if ($result_ref->{errors}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_ref->{"errors"}) 0 0 0
990 0 push @errors, @{ $result_ref->{errors} };
991 }
992 0 ▶ if ($result_ref->{warnings}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_ref->{"warnings"}) 0 0 0
993 0 push @warnings, @{ $result_ref->{warnings} };
994 }
995  
996 ### =use directive: $stack[-1]
997 0 next TOKEN;
998 }
999  
1000 # =encoding directive
1001 92 ▶ if ($line =~ m{ \G ^ =encoding \s+ (\S+) \s* ([^\n]*) \n }ogcxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ / \G ^ =encoding \s+ (\S+) \s* ([^\n]*) \n /cgmosx) 0 92 92
1002 0 my ($encoding, $junk) = ($1, $2);
1003  
1004 # =encoding takes no options...
1005 0 ▶ if ($junk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($junk) 0 0 0
1006 0 _err_trailing_junk('=encoding directive', \%range, $junk, \@errors);
1007 }
1008  
1009 # It also terminates any surrounding list...
1010 0 $top = _adjust_lists(\@stack, $line, 0, 0, 0, \%range, \@warnings);
1011  
1012 # Add it to the stack (not yet in the representation)...
1013 0 push @stack, {
1014 typename => 'encoding',
1015 style => 'directive',
1016 encoding => $encoding,
1017 range => { %range },
1018 terminator => qr{ ^ \s* $
1019 | $DIR_NC
1020 | (?= [^=] )
1021 | (?= $top->{terminator} )
1022 }xms,
1023 is_blank_terminated => 1,
1024 };
1025  
1026 ### =encoding directive: $stack[-1]
1027 0 next TOKEN;
1028 }
1029  
1030 # =config directive
1031 92 ▶ if ($line =~ m{ \G ^ =config \s+ ($FORMATTING_CODE<>|$IDENT) ($OPTIONS?) \s* ([^\n]*) \n }ogcxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ / \G ^ =config \s+ ($FORMATTING_CODE<>|$IDENT) ($OPTIONS?) \s* ([^\n]*) \n /cgmosx) 9 83 92
1032 9 my ($config_type, $options, $junk) = ($1, $2, $3);
1033  
1034 # Anything after last option is junk...
1035 9 ▶ if ($junk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($junk) 0 9 9
1036 0 _err_trailing_junk("=config directive", \%range, $junk, \@errors);
1037 }
1038  
1039 9 $has_options_pending = 1;
1040  
1041 9 my $parsed_opts_ref
1042 = _extract_options($options);
1043  
1044 # Record added config scope in parent...
1045 9 $stack[-1]{has_config}++;
1046  
1047 # Add new lexical config frame...
1048 9 push @config_stack, _extend_config(
1049 $config_stack[-1],
1050 $config_type,
1051 $parsed_opts_ref,
1052 );
1053  
1054 # Directive closes any surrounding list...
1055 9 $top = _adjust_lists(\@stack, $line, 0, 0, 0, \%range, \@warnings);
1056  
1057 # Save representation of =config directive...
1058 9 push @stack, {
1059 typename => 'config',
1060 style => 'directive',
1061 target => $config_type,
1062 options => $parsed_opts_ref,
1063 range => { %range },
1064 terminator => qr{ ^ \s* $
1065 | $DIR_NC
1066 | (?= [^=] )
1067 | (?= $top->{terminator} )
1068 }xms,
1069 is_blank_terminated => 1,
1070 };
1071  
1072 ### =config directive: $stack[-1]
1073 ### Config now: $config_stack[-1]
1074 9 next TOKEN;
1075 }
1076  
1077 # Open marker for abbreviated block...
1078 83 ▶ if ($line =~ m{ \G ^ = ($IDENT) \s* }ogcxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ / \G ^ = ($IDENT) \s* /cgmosx) 81 2 83
1079 81 my $type = $1;
1080  
1081 # Work out its nesting level if it's an item block...
1082 81 my ($is_item, $item_level)
1083 = $type =~ m{\A (item)(\d+)? \Z}xms;
1084 81 ▶ $item_level ||= $is_item ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$is_item ? : 12 47 59
Condition100%3/3
$item_level ||= $is_item ? 1 : 0
l!l&&r!l&&!r
221247
MC/DC100%2/2
$item_level ||= $is_item ? 1 : 0
$item_level $is_item ? 1 : 0
Truth table100%3/3
A ||= B
A= $item_levelB= $is_item ? 1 : 0
ABresult
1X1
011
000
1085  
1086 81 my $is_comment = $type eq 'comment';
1087  
1088 # Open or close implicit list if necessary...
1089 81 $top = _adjust_lists(\@stack, $line, $is_item, $is_comment,
1090 $item_level, \%range, \@warnings
1091 );
1092  
1093 my $disjoint_item1
1094 81 ▶ = $is_item && $item_level==1 && !$top->{content};
Condition100%6/6
$is_item && $item_level == 1 && !$top->{'content'}
!ll&&!rl&&r
60147
$is_item and $item_level == 1
!ll&&!rl&&r
471321
MC/DC100%3/3
$is_item && $item_level == 1 && !$top->{'content'}
$is_item $item_level == 1 !$top->{'content'}
Truth table100%4/4
A and B && not(C)
A= $is_itemB= $item_level == 1C= !$top->{'content'}
ABCresult
0XX0
10X0
1100
1111
1095  
1096 81 my $permits_implicit_blocks
1097 = $type =~ m{$PERMITS_IMPLICIT}xms;
1098  
1099 81 my $verbatim = $type eq 'code';
1100  
1101 81 my $config = $config_stack[-1]{$type};
1102 my @config_stack_entry
1103 81 ▶ = $type eq 'table' ? (config_stack=>$config_stack[-1])
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'table' ? : 3 78 81
1104 : ();
1105  
1106 # Copy allowed fcodes...
1107 81 my $allow_ref = _update_allow($top, $config, {});
1108  
1109 # Add it to the stack (not yet in the representation)...
1110 push @stack, {
1111 typename => $type,
1112 style => 'abbreviated',
1113 config => $config,
1114 @config_stack_entry,
1115 range => { %range },
1116 terminator => qr{ ^ \s* $
1117 | $DIR_NC
1118 | (?= $top->{terminator} )
1119 }xms,
1120 is_verbatim => $verbatim || $top->{is_verbatim},
1121 81 ▶ is_blank_terminated => 1,
Condition33%1/3
$verbatim || $top->{'is_verbatim'}
l!l&&r!l&&!r
0081
MC/DC0%0/2
$verbatim || $top->{'is_verbatim'}
$verbatim $top->{'is_verbatim'}
Truth table33%1/3
A || B
A= $verbatimB= $top->{'is_verbatim'}
ABresult
1X1
011
000
1122 allow => $allow_ref,
1123 disjoint => $disjoint_item1,
1124 permits_implicit_blocks => $permits_implicit_blocks,
1125 };
1126  
1127 # Handling configured implicit formatting, if any...
1128 $stack[-1]->{options}
1129 81 = _handle_likeness($stack[-1], $config_stack[-1]);
1130 81 push @stack, _handle_formatted(
1131 $stack[-1], \%range, $config_stack[-1], \@errors
1132 );
1133  
1134 # Finished with directive (may be trailing data)
1135 81 $is_directive = 0;
1136  
1137 ### Opened abbreviated block: $stack[-1]
1138 81 next TOKEN;
1139 }
1140  
1141 # Treat "late" option lines as content (with warning)...
1142 2 ▶ if ($line =~ m{ \G ^ = (\s+ $OPTIONS) \s* $ }ogcxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ / \G ^ = (\s+ $OPTIONS) \s* $ /cgmosx) 1 1 2
1143 1 _err_options_too_late($top, \%range, \@warnings);
1144  
1145 1 _add_content($top, $line);
1146  
1147 ### Added dubious raw content: $stack[-1]
1148 1 next LINE;
1149 }
1150 }
1151  
1152 # If not directive, must be ambient text, raw para or code block...
1153  
1154 # Close implicit item list if necessary...
1155 1244 $top = _adjust_lists(\@stack, $line, 0, 0, 0, \%range, \@warnings);
1156  
1157 # Deal with ambient text (i.e. non-Pod) and unprocessed blocks...
1158 1244 ▶ if (@stack == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack == 1) 0 1244 1244
1159 0 $top = {
1160 typename => '(ambient)',
1161 style => 'implicit',
1162 range => { %range },
1163 terminator => qr{(?= ^ = $IDENT) }xms,
1164 };
1165 0 push @stack, $top;
1166 }
1167 1244 ▶ if ($top->{typename} =~ m{^(?:\(ambient\)|table)$}xms
Branch: 1 branch
BranchTrueFalseTotal
if ($top->{"typename"} =~ /^(?:\(ambient\)|table)$/msx or $top->{"typename"} =~ /[[:upper:]]/ and $top->{"typename"} =~ /[[:lower:]]/) 46 1198 1244
Condition100%6/6
$top->{"typename"} =~ /^(?:\(ambient\)|table)$/msx or $top->{"typename"} =~ /[[:upper:]]/ and $top->{"typename"} =~ /[[:lower:]]/
l!l&&r!l&&!r
3971198
$top->{"typename"} =~ /[[:upper:]]/ and $top->{"typename"} =~ /[[:lower:]]/
!ll&&!rl&&r
9792197
MC/DC100%3/3
$top->{"typename"} =~ /^(?:\(ambient\)|table)$/msx or $top->{"typename"} =~ /[[:upper:]]/ and $top->{"typename"} =~ /[[:lower:]]/
$top->{"typename"} =~ /^(?:\(ambient\)|table)$/msx $top->{"typename"} =~ /[[:upper:]]/ $top->{"typename"} =~ /[[:lower:]]/
Truth table100%4/4
A or B and C
A= $top->{"typename"} =~ /^(?:\(ambient\)|table)$/msxB= $top->{"typename"} =~ /[[:upper:]]/C= $top->{"typename"} =~ /[[:lower:]]/
ABCresult
1XX1
0111
00X0
0100
1168 || $top->{typename} =~ m{[[:upper:]]}
1169 && $top->{typename} =~ m{[[:lower:]]}
1170 ) {
1171 46 ▶ if ($line =~ m{ \G (.*) }gcxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ / \G (.*) /cgmsx) 46 0 46
1172 46 _add_content($top, $1);
1173 ### Unprocessed text: $1
1174 }
1175  
1176 46 next LINE;
1177 }
1178  
1179 # Implicit code/para Pod block depends on indenting...
1180 1198 ▶ if (pos($line) == 0 && $top->{permits_implicit_blocks}) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $line == 0 and $top->{"permits_implicit_blocks"}) 143 1055 1198
Condition100%3/3
pos $line == 0 and $top->{"permits_implicit_blocks"}
!ll&&!rl&&r
833222143
MC/DC100%2/2
pos $line == 0 and $top->{"permits_implicit_blocks"}
pos $line == 0 $top->{"permits_implicit_blocks"}
Truth table100%3/3
A and B
A= pos $line == 0B= $top->{"permits_implicit_blocks"}
ABresult
0X0
100
111
1181 my $terminator
1182 143 ▶ = $top->{style} eq 'delimited' ? '^ \s* $' : '(?= ^ \s* $)';
Branch: 1 branch
BranchTrueFalseTotal
$top->{'style'} eq 'delimited' ? : 16 127 143
1183  
1184 # Indented block is code block...
1185 143 ▶ if ($line =~ m{ \G ^ (?= [^\S\n]+ \S [^\n]* $ ) }gcxms) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ / \G ^ (?= [^\S\n]+ \S [^\n]* $ ) /cgmsx) { } 2 141 143
elsif ($line =~ / \G (?= \S .* $ ) /cgmsx) { } 94 47 141
1186  
1187 2 my $config = $config_stack[-1]{'code'};
1188 2 my $allow_ref = _update_allow($top, $config, {});
1189  
1190 2 push @stack, {
1191 typename => 'code',
1192 style => 'implicit',
1193 config => $config,
1194 allow => $allow_ref,
1195 range => { %range },
1196 terminator => qr{ $terminator
1197 | $DIR_NC
1198 | (?= $top->{terminator} )
1199 }xms,
1200 is_verbatim => 1,
1201 is_blank_terminated => 1,
1202 };
1203  
1204 2 _add_content($stack[-1], $line);
1205  
1206 ### Opened implicit code block: $stack[-1]
1207 2 next LINE;
1208 }
1209 # Unindented block is para block...
1210 elsif ($line =~ m{ \G (?= \S .* $ ) }gcxms) {
1211  
1212 94 my $config = $config_stack[-1]{'para'};
1213 94 my $allow_ref = _update_allow($top, $config, {});
1214  
1215 push @stack, {
1216 typename => 'para',
1217 style => 'implicit',
1218 config => $config,
1219 allow => $allow_ref,
1220 range => { %range },
1221 terminator => qr{ $terminator
1222 | $DIR_NC
1223 | (?= $top->{terminator} )
1224 }xms,
1225 is_verbatim=> $top->{is_verbatim},
1226 94 is_blank_terminated => 1,
1227 };
1228  
1229 ### Opened implicit para block: $stack[-1]
1230 94 next TOKEN;
1231 }
1232 else { # Meaningless empty line
1233 47 next LINE;
1234 }
1235 }
1236  
1237 # Open marker for formatting code (only outside V<> and C<>)...
1238 1055 ▶ if ( ( !$top->{is_verbatim}
Branch: 1 branch
BranchTrueFalseTotal
if (!$top->{"is_verbatim"} || exists $top->{"allow"}{substr $line, pos $line, 1} and $line =~ / \G ($FORMATTING_CODE) ((?><+)|$LEFT_ANGLE) /cgmosx) 61 994 1055
Condition100%6/6
!$top->{"is_verbatim"} || exists $top->{"allow"}{substr $line, pos $line, 1} and $line =~ / \G ($FORMATTING_CODE) ((?><+)|$LEFT_ANGLE) /cgmosx
!ll&&!rl&&r
15084461
not $top->{"is_verbatim"} or exists $top->{"allow"}{substr $line, pos $line, 1}
l!l&&r!l&&!r
8996150
MC/DC100%3/3
!$top->{"is_verbatim"} || exists $top->{"allow"}{substr $line, pos $line, 1} and $line =~ / \G ($FORMATTING_CODE) ((?><+)|$LEFT_ANGLE) /cgmosx
not $top->{"is_verbatim"} exists $top->{"allow"}{substr $line, pos $line, 1} $line =~ / \G ($FORMATTING_CODE) ((?><+)|$LEFT_ANGLE) /cgmosx
Truth table80%4/5
not(A) or B and C
A= not $top->{"is_verbatim"}B= exists $top->{"allow"}{substr $line, pos $line, 1}C= $line =~ / \G ($FORMATTING_CODE) ((?><+)|$LEFT_ANGLE) /cgmosx
ABCresult
00X0
1X00
0100
1X11
0111
1239 || exists $top->{allow}{substr($line,pos $line,1)}
1240 )
1241 && $line =~ m{ \G ($FORMATTING_CODE) ((?><+)|$LEFT_ANGLE) }ogcxms
1242 ) {
1243 61 my ($type, $delim) = ($1, $2);
1244  
1245 # Generate right delimiter (and nested matcher) from left...
1246 61 my $rdelim = $delim;
1247 61 $rdelim =~ tr/</>/;
1248 61 $rdelim =~ s{$LDAB}{$RDAB}g;
1249 61 $rdelim =~ s{$LDAB_CJK}{$RDAB_CJK}g;
1250 61 ▶ my $initiator = $delim . ($delim =~ /</ ? '(?!<)' : q{});
Branch: 1 branch
BranchTrueFalseTotal
$delim =~ /</ ? : 59 2 61
1251 61 ▶ my $terminator = length($delim) == 1 ? $rdelim
Branch: 1 branch
BranchTrueFalseTotal
length $delim == 1 ? : 58 3 61
1252 : "$rdelim(?!>)"
1253 ;
1254  
1255 # Don't look up terminator stack if partial matches might
1256 # occur...
1257 61 ▶ if ($rdelim =~ />/ && $rdelim !~ $top->{terminator}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rdelim =~ />/ and not $rdelim =~ /$top->{"terminator"}/) 47 14 61
Condition100%3/3
$rdelim =~ />/ and not $rdelim =~ /$top->{"terminator"}/
!ll&&!rl&&r
21247
MC/DC100%2/2
$rdelim =~ />/ and not $rdelim =~ /$top->{"terminator"}/
$rdelim =~ />/ not $rdelim =~ /$top->{"terminator"}/
Truth table100%3/3
A and not(B)
A= $rdelim =~ />/B= not $rdelim =~ /$top->{"terminator"}/
ABresult
0X0
100
111
1258 47 $terminator .= "|(?=$top->{terminator})"
1259 }
1260  
1261 61 my $config_ref = $config_stack[-1]{"$type<>"};
1262 61 my $allow_ref = _update_allow($top, $config_ref, {});
1263  
1264 push @stack, {
1265 typename => $type,
1266 style => 'formatting',
1267 config => $config_ref,
1268 allow => $allow_ref,
1269 range => { %range },
1270 initiator => $initiator,
1271 terminator => $terminator,
1272 left_delim => $delim,
1273 right_delim => $rdelim,
1274 is_verbatim => ($type =~ m{[VCMP]}xms ? 1 : 0)
1275 || $top->{is_verbatim},
1276 permits_implicit_blocks
1277 => $top->{permits_implicit_blocks},
1278 61 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /[VCMP]/msx ? : 22 39 61
Condition100%3/3
($type =~ /[VCMP]/msx ? 1 : 0) || $top->{'is_verbatim'}
l!l&&r!l&&!r
22435
MC/DC100%2/2
($type =~ /[VCMP]/msx ? 1 : 0) || $top->{'is_verbatim'}
($type =~ /[VCMP]/msx ? 1 : 0) $top->{'is_verbatim'}
Truth table100%3/3
A || B
A= ($type =~ /[VCMP]/msx ? 1 : 0)B= $top->{'is_verbatim'}
ABresult
1X1
011
000
1279  
1280 # Track placement requests for table-of-contents...
1281 61 ▶ if ($type eq 'P') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "P") 2 59 61
1282 2 push @toc_placements, $stack[-1];
1283 }
1284  
1285 ### Opened formatting code: $stack[-1]
1286 61 next TOKEN;
1287 }
1288  
1289 # Balance nested delimiters inside a formatting code...
1290 994 ▶ if ( $top->{style} eq 'formatting'
Branch: 1 branch
BranchTrueFalseTotal
if ($top->{"style"} eq "formatting" and $line =~ / \G ($top->{"initiator"}) /cgmsx) 7 987 994
Condition100%3/3
$top->{"style"} eq "formatting" and $line =~ / \G ($top->{"initiator"}) /cgmsx
!ll&&!rl&&r
8081797
MC/DC100%2/2
$top->{"style"} eq "formatting" and $line =~ / \G ($top->{"initiator"}) /cgmsx
$top->{"style"} eq "formatting" $line =~ / \G ($top->{"initiator"}) /cgmsx
Truth table100%3/3
A and B
A= $top->{"style"} eq "formatting"B= $line =~ / \G ($top->{"initiator"}) /cgmsx
ABresult
0X0
100
111
1291 && $line =~ m{ \G ($top->{initiator}) }gcxms
1292 ) {
1293 7 my $delim = $1;
1294 7 $top->{delim_nesting}++;
1295 7 _add_content($top, $delim);
1296  
1297 ### Nested left delimiter in formatting code: $stack[-1]
1298 7 next TOKEN;
1299 }
1300  
1301 # Is there a separator in one of the "separable" codes?
1302 987 ▶ if ( $top->{style} eq 'formatting'
Branch: 1 branch
BranchTrueFalseTotal
if ($top->{"style"} eq "formatting" and $top->{"typename"} =~ /\A [DLX] \Z/msx and $line =~ / \G [|] /cgmsx) 4 983 987
Condition100%6/6
$top->{"style"} eq "formatting" and $top->{"typename"} =~ /\A [DLX] \Z/msx and $line =~ / \G [|] /cgmsx
!ll&&!rl&&r
97494
$top->{"style"} eq "formatting" and $top->{"typename"} =~ /\A [DLX] \Z/msx
!ll&&!rl&&r
80816613
MC/DC100%3/3
$top->{"style"} eq "formatting" and $top->{"typename"} =~ /\A [DLX] \Z/msx and $line =~ / \G [|] /cgmsx
$top->{"style"} eq "formatting" $top->{"typename"} =~ /\A [DLX] \Z/msx $line =~ / \G [|] /cgmsx
Truth table100%4/4
A and B and C
A= $top->{"style"} eq "formatting"B= $top->{"typename"} =~ /\A [DLX] \Z/msxC= $line =~ / \G [|] /cgmsx
ABCresult
0XX0
10X0
1100
1111
1303 && $top->{typename} =~ m{\A [DLX] \Z}xms
1304 && $line =~ m{ \G [|] }gcxms) {
1305 4 $top->{target} = "";
1306 }
1307  
1308 # Otherwise, it's raw content or target (eat *all* angles, if any)..
1309 987 ▶ if ($line =~ m{ \G ( [\xAB<]+ | [^A-Z|\n<>\xAB\xBB]+ | . ) }gcxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ / \G ( [\xAB<]+ | [^A-Z|\n<>\xAB\xBB]+ | . ) /cgmsx) 987 0 987
1310 # Are we in the "target" section yet?
1311 987 ▶ if (exists $top->{target}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $top->{'target'}) { } 7 980 987
1312 7 $top->{target} .= $1;
1313 ### Added target: $stack[-1]
1314 }
1315 # Otherwise, still in the "appearance" section
1316 else {
1317 980 _add_content($top, $1);
1318 ### Added raw content: $stack[-1]
1319 }
1320  
1321 987 next TOKEN;
1322 }
1323  
1324 # Should be impossible to get to here...
1325 0 die "Internal error near: ", substr($line, pos $line);
1326 }
1327 }
1328  
1329 # Close and nest any unclosed blocks at the end of the file...
1330 127 ▶ while (@stack > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack > 1) 206 127 333
1331 206 my $top = $stack[-1];
1332 206 my $line_num = $.;
1333  
1334 # Record the missing closing delimiter...
1335 206 _err_no_closing_delim($top, \@errors, \@warnings);
1336  
1337 # Finish line range and remove internal parsing data...
1338 206 my $block = pop @stack;
1339 206 $block->{range}{to} = $line_num;
1340 206 delete @{$block}{qw< terminator initiator has_config allow>};
1341  
1342 # Execute any use statement...
1343 206 ▶ if ($block->{typename} eq '(use)') {
Branch: 1 branch
BranchTrueFalseTotal
if ($block->{"typename"} eq "(use)") 0 206 206
1344 0 my $source = $block->{source};
1345 0 ▶ if (eval "require $source") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require $source") { } 0 0 0
1346 my %options = (
1347 0 ▶ %{ $block->{config}{use}||{} },
Condition0%0/2
$block->{'config'}{'use'} || {}
l!l
00
MC/DC0%0/1
$block->{'config'}{'use'} || {}
$block->{'config'}{'use'}
Truth table0%0/2
A
A= $block->{'config'}{'use'}
Aresult
11
00
1348 0 ▶ %{ $block->{options} || {} },
Condition0%0/2
$block->{'options'} || {}
l!l
00
MC/DC0%0/1
$block->{'options'} || {}
$block->{'options'}
Truth table0%0/2
A
A= $block->{'options'}
Aresult
11
00
1349 );
1350 0 $source->import(\%options);
1351 }
1352 else {
1353 0 _err_use_cant_load($source, $line_num, \@errors);
1354 0 next TOKEN;
1355 }
1356 }
1357  
1358 206 push @{ $stack[-1]{content} }, $block;
1359  
1360 ### Implicitly terminated block: $block
1361 }
1362  
1363 # Apply global processing to root of data structure...
1364 127 my $root = pop(@stack);
1365  
1366 # Number all numbered blocks...
1367 127 my $state_ref = { errors => \@errors };
1368 127 _resolve_numbering($root, $state_ref);
1369  
1370 # Convert internal hash-based representation to objects...
1371 127 my $tree = _create_objects($root, $state_ref);
1372  
1373 # Build and install any tables-of-content for P<toc:...> codes...
1374 TOC:
1375 127 for my $toc_placement_obj (@toc_placements) {
1376 2 ▶ next TOC if $toc_placement_obj->{content}[0] !~ m{\A \s* toc:}xms;
Branch: 1 branch
BranchTrueFalseTotal
unless $toc_placement_obj->{"content"}[0] =~ /\A \s* toc:/msx 1 1 2
1377  
1378 # Replace P<toc:...>'s contents with TOC...
1379 $toc_placement_obj->{content}
1380 1 = [ _build_toc($tree, $toc_placement_obj) ];
1381  
1382 # Set flag to ignore this node on subsequent TOC-building passes...
1383 1 $toc_placement_obj->{ignore_toc} = 1;
1384 }
1385  
1386 # Aggregrate and return information in an object...
1387 127 return bless {
1388 tree => $tree,
1389 errors => \@errors,
1390 warnings => \@warnings,
1391 }, 'Perl6::Perldoc::Parser::ReturnVal';
1392  
1393 }
1394  
1395 # Build the table of contents for a given P<toc:> request...
1396 1 ▶sub _build_toc {
Subroutine _build_toc: called CC=7 SCAR=23.2
1397 1 my ($data_structure, $placement_obj) = @_;
1398  
1399 # Work out what's in the TOC (including the =item/=item1 alias)...
1400 1 my $requested_types = $placement_obj->{target};
1401 1 $requested_types =~ s{\A \s* toc: \s*}{}xms;
1402 1 my %toc_wants;
1403 1 @toc_wants{ split m/\s+/, $requested_types } = ();
1404 1 ▶ if (exists $toc_wants{item} || exists $toc_wants{item1}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $toc_wants{"item"} or exists $toc_wants{"item1"}) 0 1 1
Condition33%1/3
exists $toc_wants{"item"} or exists $toc_wants{"item1"}
l!l&&r!l&&!r
001
MC/DC0%0/2
exists $toc_wants{"item"} or exists $toc_wants{"item1"}
exists $toc_wants{"item"} exists $toc_wants{"item1"}
Truth table33%1/3
A or B
A= exists $toc_wants{"item"}B= exists $toc_wants{"item1"}
ABresult
1X1
011
000
1405 0 @toc_wants{qw< item item1 >} = ();
1406 }
1407  
1408 # Build flat list of tocitems into nested toclists...
1409 1 my @toc_stack = [];
1410 1 for my $toc_entry ( _walk_toc($data_structure, \%toc_wants) ) {
1411 4 my $level = $toc_entry->{level};
1412  
1413 # Increase nesting for higher numbered items...
1414 4 ▶ while ($level > @toc_stack) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level > @toc_stack) 0 4 4
1415 0 push @toc_stack, [];
1416 }
1417 # Decrease nesting for lower numbered items...
1418 4 ▶ while ($level < @toc_stack) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level < @toc_stack) 0 4 4
1419 0 my $content = pop @toc_stack;
1420 0 push @{ $toc_stack[-1] }, Perl6::Perldoc::Block::toclist->new({
1421 typename => 'toclist',
1422 style => 'implicit',
1423 content => $content,
1424 range => {},
1425 });
1426 }
1427 # Insert the item into the hierarchy...
1428 4 push @{ $toc_stack[-1] }, $toc_entry;
1429 }
1430  
1431 # Nest any unclosed lists...
1432 1 ▶ while (@toc_stack > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@toc_stack > 1) 0 1 1
1433 0 my $content = pop @toc_stack;
1434 0 push @{ $toc_stack[-1] }, Perl6::Perldoc::Block::toclist->new({
1435 typename => 'toclist',
1436 style => 'implicit',
1437 content => $content,
1438 range => {},
1439 });
1440 }
1441  
1442 # Retrieve a flat list of tocitem blocks representing the TOC...
1443 1 return @{ $toc_stack[-1] };
1444 }
1445  
1446 # Blocks without an inherent nesting level default to this nesting...
1447 56 my $DEFAULT_LEVEL = 5;
1448  
1449 # Walk DOM tree extracting blocks specified to be part of TOC...
1450 56 ▶use Scalar::Util qw< reftype >;
Subroutine BEGIN: called CC=1 SCAR=0.0
1451 27 ▶sub _walk_toc {
Subroutine _walk_toc: called CC=10 SCAR=23.3
1452 27 my ($node, $wanted_ref) = @_;
1453  
1454 27 ▶ my $node_type = reftype($node) || q{};
Condition100%2/2
builtin::reftype($node) || ''
l!l
207
MC/DC100%1/1
builtin::reftype($node) || ''
builtin::reftype($node)
Truth table100%2/2
A
A= builtin::reftype($node)
Aresult
11
00
1455  
1456 # Hashes are nodes: check if this one (and its subnodes) should be included
1457 27 ▶ if ($node_type eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if ($node_type eq 'HASH') { } 10 17 27
elsif ($node_type eq 'ARRAY') { } 10 7 17
1458 10 ▶ return if $node->{ignore_toc};
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"ignore_toc"} 0 10 10
1459  
1460 10 my $node_class = $node->{typename};
1461 10 my @this_node;
1462  
1463 # Is this node part of the TOC?
1464 my $wanted = exists $wanted_ref->{$node_class}
1465 10 ▶ || $node->{is_semantic} && exists $wanted_ref->{'head1'};
Condition66%4/6
exists $wanted_ref->{$node_class} || $node->{'is_semantic'} && exists $wanted_ref->{'head1'}
l!l&&r!l&&!r
046
$node->{"is_semantic"} and exists $wanted_ref->{"head1"}
!ll&&!rl&&r
604
MC/DC33%1/3
exists $wanted_ref->{$node_class} || $node->{'is_semantic'} && exists $wanted_ref->{'head1'}
exists $wanted_ref->{$node_class} $node->{"is_semantic"} exists $wanted_ref->{"head1"}
Truth table50%2/4
A || B and C
A= exists $wanted_ref->{$node_class}B= $node->{"is_semantic"}C= exists $wanted_ref->{"head1"}
ABCresult
1XX1
0111
00X0
0100
1466 10 ▶ if ($wanted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted) 4 6 10
1467 my $level
1468 4 ▶ = $node->{is_semantic} ? 1
Branch: 2 branches
BranchTrueFalseTotal
$node->{'is_semantic'} ? : 4 0 4
$node_class =~ /\A head (\d+) \z/msx ? : 0 0 0
1469 : $node_class =~ m{\A head (\d+) \z}xms ? $1
1470 : $DEFAULT_LEVEL
1471 ;
1472  
1473 4 my $target = $node->id();
1474  
1475 # Create a TOC entry (a list item with a link inside it)...
1476 4 @this_node = bless {
1477 typename => "tocitem$level",
1478 style => 'implicit',
1479 level => $level,
1480 target => "#$target",
1481 content => [$node],
1482 range => {},
1483 }, "Perl6::Perldoc::Block::tocitem$level";
1484  
1485 # Install the TOC entry's class in the DOM...
1486 56 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1487 4 @{"Perl6::Perldoc::Block::tocitem${level}::ISA"}
1488 = 'Perl6::Perldoc::Block::tocitem';
1489 }
1490  
1491 # Does it have subnodes that are part of the TOC?
1492 10 my @sub_nodes = _walk_toc($node->{content}, $wanted_ref);
1493  
1494 # Return node's TOC entry (if any) and those of its contents...
1495 10 return @this_node, @sub_nodes;
1496 }
1497  
1498 # Arrays may contain nodes: check each element...
1499 elsif ($node_type eq 'ARRAY') {
1500 10 return map { _walk_toc($_, $wanted_ref) } @{$node};
1501 }
1502  
1503 # Ignore everything else...
1504 else {
1505 7 return;
1506 }
1507 }
1508  
1509  
1510 # Standard classes for Perldoc DOM...
1511  
1512 package Perl6::Perldoc::Parser::ReturnVal;
1513  
1514 0 ▶sub report_errors {
Subroutine report_errors: not called CC=5 SCAR=34.0
1515 0 my $self = shift;
1516  
1517 # Report warnings...
1518 0 ▶ if (@{$self->{warnings}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"warnings"};}) 0 0 0
1519 0 print {*STDERR} join "\n", @{$self->{warnings}}, "";
1520 }
1521  
1522 # Report errors and die...
1523 0 ▶ if (@{$self->{errors}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"errors"};}) 0 0 0
1524 0 print {*STDERR} join "\n", @{$self->{errors}}, "";
1525  
1526 # Die in context if a fatality message was specified...
1527 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1528 0 ▶ require Carp and Carp::croak(@_);
Branch: 1 branch
BranchTrueFalseTotal
require Carp and Carp::croak(@_) 0 0 0
1529 }
1530 # Otherwise die silently...
1531 else {
1532 0 die "\n";
1533 }
1534 }
1535  
1536 # On success, return self to allow for chaining...
1537 0 return $self;
1538 }
1539  
1540 package Perl6::Perldoc::Root;
1541 56 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1542 56 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1543  
1544 56 my $id = 1;
1545  
1546 # Reset the id in case someone wants reproducible results
1547 0 ▶sub _reset_id {
Subroutine _reset_id: not called CC=1 SCAR=6.9
1548 0 $id = 1;
1549 }
1550  
1551 # Root constructor just assigns id and blesses the data structure...
1552 576 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
1553 576 my ($classname, $data_ref) = @_;
1554  
1555 576 $data_ref->{id} = $id++;
1556 576 return bless $data_ref, $classname;
1557 }
1558  
1559 # Standard read-only accessor methods shared by all DOM components...
1560 4 ▶sub id { my ($self) = @_; return $self->{id}; }
Subroutine id: called CC=1 SCAR=0.0
1561 487 ▶sub typename { my ($self) = @_; return $self->{typename}; }
Subroutine typename: called CC=1 SCAR=0.0
1562 434 ▶sub style { my ($self) = @_; return $self->{style}; }
Subroutine style: called CC=1 SCAR=0.0
1563 11 ▶sub target { my ($self) = @_; return $self->{target}; }
Subroutine target: called CC=1 SCAR=0.0
1564 0 ▶sub range { my ($self) = @_; return $self->{range}; }
Subroutine range: not called CC=1 SCAR=6.9
1565 0 ▶sub config { my ($self) = @_; return $self->{config}; }
Subroutine config: not called CC=1 SCAR=6.9
1566 45 ▶sub number { my ($self) = @_; return $self->{number}; }
Subroutine number: called CC=1 SCAR=0.0
1567 0 ▶sub title { my ($self) = @_; return '[' . $self->typename . ']'; }
Subroutine title: not called CC=1 SCAR=6.9
1568 0 ▶sub is_verbatim { my ($self) = @_; return $self->{is_verbatim}; }
Subroutine is_verbatim: not called CC=1 SCAR=6.9
1569 0 ▶sub is_semantic { my ($self) = @_; return $self->{is_semantic}; }
Subroutine is_semantic: not called CC=1 SCAR=6.9
1570 0 ▶sub is_numbered { my ($self) = @_; return exists $self->{number}; }
Subroutine is_numbered: not called CC=1 SCAR=6.9
1571 0 ▶sub is_post_numbered { 0 }
Subroutine is_post_numbered: not called CC=1 SCAR=6.9
1572  
1573 487 ▶sub content {
Subroutine content: called CC=4 SCAR=13.9
1574 487 my ($self) = @_;
1575 487 my $vals_ref = $self->{content};
1576 487 ▶ if (!wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 2 485 487
1577 2 ▶ if (@{ $vals_ref } > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$vals_ref;} > 1) 1 1 2
1578 1 ▶ require Carp and Carp::carp(
Branch: 1 branch
BranchTrueFalseTotal
require Carp and Carp::carp("Multivalued accessor content() called in scalar context") 1 0 1
1579 "Multivalued accessor content() called in scalar context"
1580 );
1581 }
1582 2 return $vals_ref->[0];
1583 }
1584 485 return @{ $vals_ref };
1585 }
1586  
1587 # Asking for an option falls back to the config if necessary...
1588 0 ▶sub option {
Subroutine option: not called CC=3 SCAR=24.8
1589 0 my ($self, $opt_name) = @_;
1590 return $self->{options}{$opt_name}
1591 0 ▶ if defined $self->{options}{$opt_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"options"}{$opt_name} 0 0 0
1592 return $self->{config}{$opt_name}
1593 0 ▶ if defined $self->{config}{$opt_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"config"}{$opt_name} 0 0 0
1594 0 return;
1595 }
1596  
1597 # Return an object's term or caption...
1598  
1599 0 ▶sub _flatten_or_convert_option {
Subroutine _flatten_or_convert_option: not called CC=5 SCAR=34.0
1600 0 my ($self, $opt_ref, $option_name) = @_;
1601 0 my $value = $self->option($option_name);
1602  
1603 # Flatten if value specified as a list...
1604 0 ▶ if (ref($value) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY") 0 0 0
1605 0 $value = "@{$value}";
1606 }
1607  
1608 # Return raw if not requested as an object...
1609 0 ▶ return $value if !$opt_ref->{as_objects};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt_ref->{"as_objects"} 0 0 0
1610  
1611 0 my $cache_slot = "parsed_$option_name";
1612 # Otherwise, convert to Pod object and cache for reuse...
1613 0 ▶ if (!$self->{$cache_slot}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{$cache_slot}) 0 0 0
1614 0 ▶ open my $fh, '<', \$value
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", \$value or die "Internal error: can't parse :$option_name" 0 0 0
1615 or die "Internal error: can't parse :$option_name";
1616 $self->{$cache_slot}
1617 0 = Perl6::Perldoc::Parser->parse( $fh, { all_pod => 1 })->{tree};
1618 }
1619  
1620 0 return $self->{$cache_slot};
1621 }
1622  
1623 0 ▶sub term {
Subroutine term: not called CC=1 SCAR=6.9
1624 0 my ($self, $opt_ref) = @_;
1625 0 return _flatten_or_convert_option($self, $opt_ref, 'term');
1626 }
1627  
1628 0 ▶sub caption {
Subroutine caption: not called CC=1 SCAR=6.9
1629 0 my ($self, $opt_ref) = @_;
1630 0 return _flatten_or_convert_option($self, $opt_ref, 'caption');
1631 }
1632  
1633  
1634  
1635 # Representation of file itself...
1636 package Perl6::Perldoc::File;
1637 56 ▶ use base 'Perl6::Perldoc::Root';
Subroutine BEGIN: called CC=1 SCAR=0.0
1638  
1639 # Representation of document...
1640 package Perl6::Perldoc::Document;
1641 56 ▶ use base 'Perl6::Perldoc::Root';
Subroutine BEGIN: called CC=1 SCAR=0.0
1642  
1643 # Ambient text around the Pod...
1644 package Perl6::Perldoc::Ambient;
1645 56 ▶ use base 'Perl6::Perldoc::Root';
Subroutine BEGIN: called CC=1 SCAR=0.0
1646  
1647  
1648 # Pod directives...
1649 package Perl6::Perldoc::Directive;
1650 56 ▶ use base 'Perl6::Perldoc::Root';
Subroutine BEGIN: called CC=1 SCAR=0.0
1651  
1652 # Standard =use directive...
1653 package Perl6::Perldoc::Directive::use;
1654 56 ▶ use base 'Perl6::Perldoc::Directive';
Subroutine BEGIN: called CC=1 SCAR=0.0
1655  
1656 # Standard =config directive...
1657 package Perl6::Perldoc::Directive::config;
1658 56 ▶ use base 'Perl6::Perldoc::Directive';
Subroutine BEGIN: called CC=1 SCAR=0.0
1659  
1660 # Standard =encoding directive...
1661 package Perl6::Perldoc::Directive::encoding;
1662 56 ▶ use base 'Perl6::Perldoc::Directive';
Subroutine BEGIN: called CC=1 SCAR=0.0
1663  
1664  
1665 # Pod blocks...
1666 package Perl6::Perldoc::Block;
1667 56 ▶ use base 'Perl6::Perldoc::Root';
Subroutine BEGIN: called CC=1 SCAR=0.0
1668  
1669 # Base class for user-defined blocks...
1670 package Perl6::Perldoc::Block::Named;
1671 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1672  
1673 # Standard =pod block...
1674 package Perl6::Perldoc::Block::pod;
1675 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1676  
1677 # Standard =para block (may be implicit)...
1678 package Perl6::Perldoc::Block::para;
1679 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1680  
1681 # Standard =code block (may be implicit)...
1682 package Perl6::Perldoc::Block::code;
1683 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1684  
1685 # Standard =input block
1686 package Perl6::Perldoc::Block::input;
1687 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1688  
1689 # Standard =output block
1690 package Perl6::Perldoc::Block::output;
1691 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1692  
1693 # Base class for =headN classes
1694 package Perl6::Perldoc::Heading;
1695 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1696  
1697 # All headings have a title (which is just their contents)...
1698 0 ▶sub title {
Subroutine title: not called CC=5 SCAR=34.0
1699 0 my ($self) = @_;
1700  
1701 0 my $vals_ref = $self->{content};
1702  
1703 0 ▶ if (exists $self->{number}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"number"}) 0 0 0
1704 0 unshift @{$vals_ref}, "$self->{number}. ";
1705 }
1706  
1707 0 ▶ if (!wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 0 0 0
1708 0 ▶ if (@{ $vals_ref } > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$vals_ref;} > 1) 0 0 0
1709 0 ▶ require Carp and Carp::carp(
Branch: 1 branch
BranchTrueFalseTotal
require Carp and Carp::carp("Multivalued accessor title() called in scalar context") 0 0 0
1710 "Multivalued accessor title() called in scalar context"
1711 );
1712 }
1713 0 return $vals_ref->[0];
1714 }
1715 0 return @{ $vals_ref };
1716 }
1717  
1718 # Standard =head1 block...
1719 package Perl6::Perldoc::Block::head1;
1720 56 ▶ use base 'Perl6::Perldoc::Heading';
Subroutine BEGIN: called CC=1 SCAR=0.0
1721  
1722 # Standard =head2 block...
1723 package Perl6::Perldoc::Block::head2;
1724 56 ▶ use base 'Perl6::Perldoc::Heading';
Subroutine BEGIN: called CC=1 SCAR=0.0
1725  
1726 # Standard =head3 block...
1727 package Perl6::Perldoc::Block::head3;
1728 56 ▶ use base 'Perl6::Perldoc::Heading';
Subroutine BEGIN: called CC=1 SCAR=0.0
1729  
1730 # Standard =head4 block...
1731 package Perl6::Perldoc::Block::head4;
1732 56 ▶ use base 'Perl6::Perldoc::Heading';
Subroutine BEGIN: called CC=1 SCAR=0.0
1733  
1734 # Standard =item block...
1735 package Perl6::Perldoc::Block::item;
1736 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1737  
1738 # Standard =defn block...
1739 package Perl6::Perldoc::Block::defn;
1740 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1741  
1742 # Implicit =list block...
1743 package Perl6::Perldoc::Block::list;
1744 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1745  
1746 # Implicit =tocitem block...
1747 package Perl6::Perldoc::Block::tocitem;
1748 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1749  
1750 0 ▶sub title {
Subroutine title: not called CC=1 SCAR=6.9
1751 0 my ($self) = @_;
1752 0 my $content = $self->{content}[0];
1753 0 return $content->title();
1754 }
1755  
1756 # Implicit =toclist block...
1757 package Perl6::Perldoc::Block::toclist;
1758 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1759  
1760 # Standard =nested block...
1761 package Perl6::Perldoc::Block::nested;
1762 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1763  
1764 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
1765 2 my ($self, $data) = splice @_, 0, 2;
1766 2 ▶ $data->{nested} ||= 1;
Condition50%1/2
$data->{"nested"} ||= 1
l!l
02
MC/DC0%0/1
$data->{"nested"} ||= 1
$data->{"nested"}
Truth table50%1/2
A
A= $data->{"nested"}
Aresult
11
00
1767 2 return $self->SUPER::new($data, @_);
1768 }
1769  
1770 # Standard =comment block...
1771 package Perl6::Perldoc::Block::comment;
1772 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1773  
1774 # Standard =END block...
1775 package Perl6::Perldoc::Block::END;
1776 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1777  
1778 # Standard =DATA block...
1779 package Perl6::Perldoc::Block::DATA;
1780 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1781  
1782 # Standard SEMANTIC blocks...
1783 package Perl6::Perldoc::Semantic;
1784 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
1785
1786 # For most semantic blocks, their title is their name, suitably de-shouted...
1787 0 ▶sub title {
Subroutine title: not called CC=3 SCAR=24.8
1788 0 my ($self) = @_;
1789 0 my $title = ucfirst lc $self->{typename};
1790
1791 0 ▶ if (exists $self->{number}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"number"}) 0 0 0
1792 0 ▶ $title = $self->is_post_numbered ? "$title $self->{number}"
Branch: 1 branch
BranchTrueFalseTotal
$self->is_post_numbered ? : 0 0 0
1793 : "$self->{number}. $title"
1794 ;
1795 }
1796  
1797 0 return $title;
1798 };
1799  
1800 package Perl6::Perldoc::Block::ACKNOWLEDGEMENT;
1801 56 ▶ use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1802 package Perl6::Perldoc::Block::ACKNOWLEDGEMENTS;
1803 56 ▶ use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1804 56 ▶package Perl6::Perldoc::Block::APPENDICES; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1805 56 ▶package Perl6::Perldoc::Block::APPENDIX; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1806 0 ▶sub is_post_numbered {1}
Subroutine is_post_numbered: not called CC=1 SCAR=6.9
1807  
1808 56 ▶package Perl6::Perldoc::Block::APPENDIXES; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1809 56 ▶package Perl6::Perldoc::Block::AUTHOR; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1810 56 ▶package Perl6::Perldoc::Block::AUTHORS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1811 56 ▶package Perl6::Perldoc::Block::BUG; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1812 56 ▶package Perl6::Perldoc::Block::BUGS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1813 56 ▶package Perl6::Perldoc::Block::CHAPTER; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1814 0 ▶sub is_post_numbered {1}
Subroutine is_post_numbered: not called CC=1 SCAR=6.9
1815  
1816 56 ▶package Perl6::Perldoc::Block::CHAPTERS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1817 56 ▶package Perl6::Perldoc::Block::COPYRIGHT; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1818 56 ▶package Perl6::Perldoc::Block::COPYRIGHTS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1819 56 ▶package Perl6::Perldoc::Block::DEFAULT; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1820 package Perl6::Perldoc::Block::DEPENDENCIES;
1821 56 ▶ use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1822 56 ▶package Perl6::Perldoc::Block::DEPENDENCY; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1823 56 ▶package Perl6::Perldoc::Block::DESCRIPTION; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1824 package Perl6::Perldoc::Block::DESCRIPTIONS;
1825 56 ▶ use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1826 56 ▶package Perl6::Perldoc::Block::DIAGNOSTIC; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1827 56 ▶package Perl6::Perldoc::Block::DIAGNOSTICS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1828 56 ▶package Perl6::Perldoc::Block::DISCLAIMER; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1829 56 ▶package Perl6::Perldoc::Block::DISCLAIMERS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1830 56 ▶package Perl6::Perldoc::Block::ERROR; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1831 56 ▶package Perl6::Perldoc::Block::ERRORS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1832 56 ▶package Perl6::Perldoc::Block::FOREWORD; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1833 56 ▶package Perl6::Perldoc::Block::FOREWORDS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1834 56 ▶package Perl6::Perldoc::Block::INDEX; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1835 0 ▶sub is_post_numbered {1}
Subroutine is_post_numbered: not called CC=1 SCAR=6.9
1836  
1837 56 ▶package Perl6::Perldoc::Block::INDEXES; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1838 56 ▶package Perl6::Perldoc::Block::INDICES; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1839 56 ▶package Perl6::Perldoc::Block::INTERFACE; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1840 56 ▶package Perl6::Perldoc::Block::INTERFACES; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1841 56 ▶package Perl6::Perldoc::Block::LICENCE; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1842 56 ▶package Perl6::Perldoc::Block::LICENCES; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1843 56 ▶package Perl6::Perldoc::Block::LICENSE; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1844 56 ▶package Perl6::Perldoc::Block::LICENSES; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1845 56 ▶package Perl6::Perldoc::Block::METHOD; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1846 56 ▶package Perl6::Perldoc::Block::METHODS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1847 56 ▶package Perl6::Perldoc::Block::NAME; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1848 56 ▶package Perl6::Perldoc::Block::NAMES; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1849 56 ▶package Perl6::Perldoc::Block::OPTION; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1850 56 ▶package Perl6::Perldoc::Block::OPTIONS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1851 56 ▶package Perl6::Perldoc::Block::PURPOSE; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1852 56 ▶package Perl6::Perldoc::Block::SECTION; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1853 0 ▶sub is_post_numbered {1}
Subroutine is_post_numbered: not called CC=1 SCAR=6.9
1854  
1855 56 ▶package Perl6::Perldoc::Block::SECTIONS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1856 56 ▶package Perl6::Perldoc::Block::SUBROUTINE; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1857 56 ▶package Perl6::Perldoc::Block::SUBROUTINES; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1858 56 ▶package Perl6::Perldoc::Block::SUMMARIES; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1859 56 ▶package Perl6::Perldoc::Block::SUMMARY; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1860 56 ▶package Perl6::Perldoc::Block::SYNOPSES; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1861 56 ▶package Perl6::Perldoc::Block::SYNOPSIS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1862 56 ▶package Perl6::Perldoc::Block::TITLE; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1863 56 ▶package Perl6::Perldoc::Block::TITLES; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1864 56 ▶package Perl6::Perldoc::Block::USAGE; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1865 56 ▶package Perl6::Perldoc::Block::USAGES; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1866 56 ▶package Perl6::Perldoc::Block::VERSION; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1867 56 ▶package Perl6::Perldoc::Block::VERSIONS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1868 56 ▶package Perl6::Perldoc::Block::WARNING; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1869 56 ▶package Perl6::Perldoc::Block::WARNINGS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1870  
1871 # A few semantic classes need to translate their titles...
1872 56 ▶package Perl6::Perldoc::Block::TOC; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1873 0 ▶sub title { return 'Table of Contents'; }
Subroutine title: not called CC=1 SCAR=6.9
1874  
1875 56 ▶package Perl6::Perldoc::Block::TOCS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1876 0 ▶sub title { return 'Tables of Contents'; }
Subroutine title: not called CC=1 SCAR=6.9
1877  
1878 56 ▶package Perl6::Perldoc::Block::SEEALSO; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1879 0 ▶sub title { return 'See Also'; }
Subroutine title: not called CC=1 SCAR=6.9
1880  
1881 56 ▶package Perl6::Perldoc::Block::SEEALSOS; use base 'Perl6::Perldoc::Semantic';
Subroutine BEGIN: called CC=1 SCAR=0.0
1882 0 ▶sub title { return 'See Also'; }
Subroutine title: not called CC=1 SCAR=6.9
1883  
1884 # Base class for formatting codes...
1885 package Perl6::Perldoc::FormattingCode;
1886 56 ▶ use base 'Perl6::Perldoc::Root';
Subroutine BEGIN: called CC=1 SCAR=0.0
1887  
1888 # Basis text formatter...
1889 package Perl6::Perldoc::FormattingCode::B;
1890 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
1891  
1892 # Code formatter...
1893 package Perl6::Perldoc::FormattingCode::C;
1894 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
1895  
1896 # Definition formatter...
1897 package Perl6::Perldoc::FormattingCode::D;
1898 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
1899  
1900 # The "definition" formatting code must extract its synonyms...
1901 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
1902 2 my ($classname, $data_ref) = @_;
1903  
1904 2 ▶ if (my $synonyms = delete $data_ref->{target}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $synonyms = delete $data_ref->{"target"}) 2 0 2
1905 2 $data_ref->{synonyms} = [split /;/, $synonyms];
1906 }
1907  
1908 2 return $classname->SUPER::new($data_ref);
1909 }
1910  
1911 0 ▶sub synonyms {
Subroutine synonyms: not called CC=4 SCAR=30.0
1912 0 my ($self) = @_;
1913 0 my $vals_ref = $self->{synonyms};
1914 0 ▶ if (!wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 0 0 0
1915 0 ▶ if (@{ $vals_ref } > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$vals_ref;} > 1) 0 0 0
1916 0 ▶ require Carp and Carp::carp(
Branch: 1 branch
BranchTrueFalseTotal
require Carp and Carp::carp("Multivalued accessor synonyms() called in scalar context") 0 0 0
1917 "Multivalued accessor synonyms() called in scalar context"
1918 );
1919 }
1920 0 return $vals_ref->[0];
1921 }
1922 0 return @{ $vals_ref };
1923 }
1924  
1925  
1926 # Entity formatter...
1927 package Perl6::Perldoc::FormattingCode::E;
1928 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
1929  
1930 # Important text formatter...
1931 package Perl6::Perldoc::FormattingCode::I;
1932 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
1933  
1934 # Keyboard input formatter...
1935 package Perl6::Perldoc::FormattingCode::K;
1936 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
1937  
1938 # Link formatter...
1939 package Perl6::Perldoc::FormattingCode::L;
1940 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
1941  
1942 # Flatten a hierarchical data structure into a suitable link target...
1943 56 ▶use Scalar::Util qw< reftype >;
Subroutine BEGIN: called CC=1 SCAR=0.0
1944 0 ▶sub _flatten {
Subroutine _flatten: not called CC=1 SCAR=6.9
1945 0 my $flat_version = _flatten_recursive(@_);
1946 0 $flat_version =~ s{\n}{ }gxms;
1947 0 $flat_version =~ s{\A \s+ | \s+ \z}{}gxms;
1948 0 return $flat_version;
1949 }
1950  
1951 0 ▶sub _flatten_recursive {
Subroutine _flatten_recursive: not called CC=7 SCAR=40.3
1952 0 my ($data) = @_;
1953 0 ▶ my $class = ref($data) || q{};
Condition0%0/2
ref $data || ''
l!l
00
MC/DC0%0/1
ref $data || ''
ref $data
Truth table0%0/2
A
A= ref $data
Aresult
11
00
1954 0 $class =~ s{.*::}{}xms;
1955 0 ▶ my $type = reftype($data) || q{};
Condition0%0/2
builtin::reftype($data) || ''
l!l
00
MC/DC0%0/1
builtin::reftype($data) || ''
builtin::reftype($data)
Truth table0%0/2
A
A= builtin::reftype($data)
Aresult
11
00
1956 0 ▶ if ($type eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'HASH') { } 0 0 0
elsif ($type eq 'ARRAY') { } 0 0 0
1957 0 ▶ return q{} if $data->{ignore_toc};
Branch: 1 branch
BranchTrueFalseTotal
if $data->{"ignore_toc"} 0 0 0
1958 0 return "$class<" . _flatten_recursive($data->{content}) . '>';
1959 }
1960 elsif ($type eq 'ARRAY') {
1961 0 return join q{}, map {_flatten_recursive($_)} @{$data};
1962 }
1963 else {
1964 0 ▶ return $data || q{};
Condition0%0/2
$data || ''
l!l
00
MC/DC0%0/1
$data || ''
$data
Truth table0%0/2
A
A= $data
Aresult
11
00
1965 }
1966 }
1967  
1968 # The content of a link is its default target...
1969 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.9
1970 1 my ($classname, $data_ref) = @_;
1971 1 my $self = $classname->SUPER::new($data_ref);
1972  
1973 1 ▶ if (!$self->{target}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"target"}) 0 1 1
1974 0 $self->{target} = _flatten($self->{content});
1975 0 $self->{has_no_text} = 1;
1976 }
1977  
1978 1 return $self;
1979 }
1980  
1981 0 ▶sub has_distinct_text {
Subroutine has_distinct_text: not called CC=1 SCAR=6.9
1982 0 my ($self) = @_;
1983 0 return !$self->{has_no_text};
1984 }
1985  
1986 # Meta-formatter...
1987 package Perl6::Perldoc::FormattingCode::Named;
1988 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
1989  
1990 package Perl6::Perldoc::FormattingCode::M;
1991 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
1992  
1993 # The user-defined formatting code is open ended...
1994 2 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
1995 2 my ($classname, $data_ref, $opt_ref) = @_;
1996
1997 my $content_ref
1998 2 ▶ = defined $data_ref->{content} ? $data_ref->{content} : q{};
Branch: 1 branch
BranchTrueFalseTotal
defined $data_ref->{'content'} ? : 2 0 2
1999
2000 # Install the necessary class to support this user-defined code...
2001 2 ▶ if ($content_ref->[0] =~ s{\A \s* ($QUAL_IDENT) \s* :}{}xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content_ref->[0] =~ s/\A \s* ($QUAL_IDENT) \s* ://msx) { } 1 1 2
2002 1 $classname = "Perl6::Perldoc::FormattingCode::Named::$1";
2003 56 ▶ no strict qw< refs >;
Subroutine BEGIN: called CC=1 SCAR=0.0
2004 1 push @{"${classname}::ISA"}, "Perl6::Perldoc::FormattingCode::Named";
2005 }
2006 # If there's no class specified, it's an error...
2007 else {
2008 Perl6::Perldoc::Parser::_err_missing_M_scheme(
2009 $data_ref->{range}, $opt_ref->{errors}
2010 1 );
2011 }
2012 2 return $classname->SUPER::new($data_ref);
2013 }
2014  
2015 # Note formatter...
2016 package Perl6::Perldoc::FormattingCode::N;
2017 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
2018  
2019 # Placement link formatter...
2020 package Perl6::Perldoc::FormattingCode::P;
2021 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
2022  
2023 # The content of a link is always its target...
2024 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
2025 2 my ($classname, $data_ref) = @_;
2026 2 my $self = $classname->SUPER::new($data_ref);
2027  
2028 2 $self->{target} = join q{}, @{$self->{content}};
2029  
2030 2 return $self;
2031 }
2032  
2033  
2034 # Replacable item formatter...
2035 package Perl6::Perldoc::FormattingCode::R;
2036 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
2037  
2038 # Space-preserving formatter...
2039 package Perl6::Perldoc::FormattingCode::S;
2040 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
2041  
2042 # Terminal output formatter...
2043 package Perl6::Perldoc::FormattingCode::T;
2044 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
2045  
2046 # Unusual text formatter...
2047 package Perl6::Perldoc::FormattingCode::U;
2048 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
2049  
2050 # Verbatim formatter...
2051 package Perl6::Perldoc::FormattingCode::V;
2052 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
2053  
2054 # indeX formatter...
2055 package Perl6::Perldoc::FormattingCode::X;
2056 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
2057  
2058 # Index entries have to be extracted from the index target (or index content)...
2059 1 ▶sub new {
Subroutine new: called CC=4 SCAR=20.4
2060 1 my ($classname, $data_ref) = @_;
2061  
2062 1 ▶ if (my $entries = delete $data_ref->{target}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $entries = delete $data_ref->{'target'}) { } 1 0 1
2063 1 $data_ref->{entries} = [split /;/, $entries];
2064 }
2065 else { # No target --> content is target...
2066 0 ▶ $data_ref->{entries} = @{ $data_ref->{content} || [] } <= 1
Condition0%0/2
$data_ref->{'content'} || []
l!l
00
MC/DC0%0/1
$data_ref->{'content'} || []
$data_ref->{'content'}
Truth table0%0/2
A
A= $data_ref->{'content'}
Aresult
11
00
2067 ? [ $data_ref->{content}[0] ]
2068 0 ▶ : [ [ @{ $data_ref->{content} } ] ]
Branch: 1 branch
BranchTrueFalseTotal
@{$data_ref->{'content'} or [];} <= 1 ? : 0 0 0
2069 }
2070  
2071 1 return $classname->SUPER::new($data_ref);
2072 }
2073  
2074 0 ▶sub entries {
Subroutine entries: not called CC=4 SCAR=30.0
2075 0 my ($self) = @_;
2076 0 my $vals_ref = $self->{entries};
2077 0 ▶ if (!wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 0 0 0
2078 0 ▶ if (@{ $vals_ref } > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$vals_ref;} > 1) 0 0 0
2079 0 ▶ require Carp and Carp::carp(
Branch: 1 branch
BranchTrueFalseTotal
require Carp and Carp::carp("Multivalued accessor entries() called in scalar context") 0 0 0
2080 "Multivalued accessor entries() called in scalar context"
2081 );
2082 }
2083 0 return $vals_ref->[0];
2084 }
2085 0 return @{ $vals_ref };
2086 }
2087  
2088  
2089 # Zero-width formatter...
2090 package Perl6::Perldoc::FormattingCode::Z;
2091 56 ▶ use base 'Perl6::Perldoc::FormattingCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
2092  
2093  
2094 # Standard =table block...
2095 package Perl6::Perldoc::Block::table;
2096 56 ▶ use base 'Perl6::Perldoc::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
2097  
2098 # A table's caption is its title...
2099 0 ▶sub title {
Subroutine title: not called CC=2 SCAR=17.9
2100 0 my ($self) = @_;
2101 0 ▶ if (my $title = $self->caption({ as_objects => 1 })) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $title = $self->caption({"as_objects", 1})) 0 0 0
2102 0 return $title;
2103 }
2104 0 return;
2105 }
2106  
2107 # Rows accessor...
2108 7 ▶sub rows {
Subroutine rows: called CC=4 SCAR=20.1
2109 7 my ($self) = @_;
2110 7 my $vals_ref = $self->{rows};
2111 7 ▶ if (!wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 0 7 7
2112 0 ▶ if (@{ $vals_ref } > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$vals_ref;} > 1) 0 0 0
2113 0 ▶ require Carp and Carp::carp(
Branch: 1 branch
BranchTrueFalseTotal
require Carp and Carp::carp("Multivalued accessor rows() called in scalar context") 0 0 0
2114 "Multivalued accessor rows() called in scalar context"
2115 );
2116 }
2117 0 return $vals_ref->[0];
2118 }
2119 7 return @{ $vals_ref };
2120 }
2121  
2122 # Ctor needs to build table by parsing raw contents of block...
2123 7 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
2124 7 my ($classname, $data, $opt_ref) = @_;
2125 $data->{rows} = _build_table(
2126 $data->{content}[0],
2127 $data->{allow},
2128 $data->{config_stack},
2129 7 );
2130  
2131 7 return $classname->SUPER::new($data);
2132 }
2133  
2134 # Regexes to help with table parsing...
2135 56 my $HWS = qr{ [ \t] }xms;
2136 56 my $ROW_SEP_LINE = qr{ ^ [-=_ \t|+]* \n }xms;
2137 56 my $NWS_ROW_SEP = qr{ [-=_+] }xms;
2138  
2139 # Utility maximum routine:
2140  
2141 7 ▶sub _max {
Subroutine _max: called CC=3 SCAR=11.0
2142 7 my $max = shift;
2143  
2144 7 for my $next (@_) {
2145 28 ▶ if ($next > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next > $max) 7 21 28
2146 7 $max = $next;
2147 }
2148 }
2149  
2150 7 return $max;
2151 }
2152  
2153 # Build an unpack template of the table column layout...
2154 7 ▶sub _column_template {
Subroutine _column_template: called CC=7 SCAR=19.5
2155 7 my @lines = split /\n/, shift;
2156  
2157 7 my $max_width = _max(map {length} @lines);
2158  
2159 # Compute the vector of column separator positions
2160 7 my $zvec = pack("b*", 0 x $max_width);
2161 7 my $rvec = pack("b*", 1 x $max_width);
2162 7 for my $line (@lines) {
2163 # Skip row separators...
2164 35 ▶ next if $line =~ /^[\s\-=_+|]*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^[\s\-=_+|]*$/ 5 30 35
2165 30 $line .= q{ } x ($max_width - length $line);
2166 30 my $lvec = $zvec;
2167 # Mark column separators
2168 30 ▶ while ($line =~ /(\s+[+|\s]\s+)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /(\s+[+|\s]\s+)/g) 80 30 110
2169 80 my $pos = pos($line)--;
2170 80 for my $p ($pos - length($1) .. $pos - 1) {
2171 797 vec($lvec, $p, 1) = 1;
2172 }
2173 }
2174 # The result vector must match the line vector
2175 30 $rvec &= $lvec;
2176 }
2177 7 my $template = substr(join("", unpack("b*", $rvec)), 0, $max_width);
2178  
2179 # Add any missing external boundaries...
2180 7 ▶ my $prefix = $template =~ /^0/ ? 'A0' : q{};
Branch: 1 branch
BranchTrueFalseTotal
$template =~ /^0/ ? : 2 5 7
2181 7 ▶ my $postfix = $template =~ /0$/ ? 'A0' : q{};
Branch: 1 branch
BranchTrueFalseTotal
$template =~ /0$/ ? : 3 4 7
2182  
2183 # Convert bitmap to an 'unpack' extractor...
2184 7 $template =~ s{ (1+ | 0+) }{ 'A'.length($1) }egxms;
2185  
2186 # Return extractor...
2187 7 return $prefix.$template.$postfix;
2188 }
2189  
2190 # Build list of individual table rows for given separators...
2191 7 ▶sub _build_table_rows {
Subroutine _build_table_rows: called CC=9 SCAR=22.0
2192 7 my ($text, $has_head, $cells_ref, $seps_ref, $allow_ref, $config_stack_ref)
2193 = @_;
2194  
2195 # Get extract template and subdivide cells:
2196 7 my $extractor = _column_template($text);
2197  
2198 # Parse rows and build representations...
2199 7 my @rows;
2200 7 for my $row_index (0..$#{$cells_ref}) {
2201 # Extract top and bottom row separators...
2202 my ($pre_sep, $post_sep)
2203 50 = map { [ unpack $extractor, $_ ] }
2204 25 @{$seps_ref}[$row_index, $row_index+1];
2205  
2206 # Extract cells themselves...
2207 25 my @cells;
2208 25 for my $line (split /\n/, $cells_ref->[$row_index]) {
2209 30 my @cols = unpack $extractor, $line;
2210 30 for my $col_index (0..$#cols) {
2211 186 push @{$cells[$col_index]}, $cols[$col_index];
2212 }
2213 }
2214  
2215 # Recombine the cells...
2216 25 my @cell_objs;
2217 25 my $left_sep = shift @cells;
2218 25 shift @{$pre_sep};
2219 25 shift @{$post_sep};
2220  
2221 CELL:
2222 25 ▶ while (@cells) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cells) 63 25 88
2223 63 my ($cell, $right_sep) = splice(@cells, 0, 2);
2224  
2225 63 ▶ next CELL if @{$cell} == grep /\A (\s* \|) \s* \Z/xms, @{$cell};
Branch: 1 branch
BranchTrueFalseTotal
if @{$cell;} == grep(/\A (\s* \|) \s* \Z/msx, @{$cell;}) 0 63 63
2226  
2227 63 my ($top) = splice(@{$pre_sep}, 0, 2);
2228 63 my ($bottom) = splice(@{$post_sep}, 0, 2);
2229  
2230 63 my $content = join("\n", @{$cell});
2231  
2232 # Remove common horizontal whitespace prefix...
2233 63 ▶ if ($content =~ m{\A ([^\S\n]+)}xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /\A ([^\S\n]+)/msx) 0 63 63
2234 0 my $prefix = $1;
2235 0 $content =~ s{^$prefix}{}gms; # No /x so whitespace significant
2236 }
2237  
2238 63 ▶ open my $fh, '<', \$content
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", \$content or die "Internal error: could not parse table content" 63 0 63
2239 or die "Internal error: could not parse table content";
2240  
2241 # Recursively parse content as Pod...
2242 $content
2243 = Perl6::Perldoc::Parser->parse($fh, {
2244 all_pod=>1,
2245 allow=>$allow_ref,
2246 config_stack=>$config_stack_ref,
2247 63 })->{tree}->{content};
2248  
2249 # Add cell to list for row...
2250 push @cell_objs, bless {
2251 content => $content,
2252 63 left => join("\n", @{$left_sep}),
2253 63 ▶ right => join("\n", @{$right_sep}),
Condition100%3/3
$has_head && $row_index == 0
!ll&&!rl&&r
45126
MC/DC100%2/2
$has_head && $row_index == 0
$has_head $row_index == 0
Truth table100%3/3
A && B
A= $has_headB= $row_index == 0
ABresult
0X0
100
111
2254 top => $top,
2255 bottom => $bottom,
2256 header => $has_head && $row_index == 0,
2257 }, 'Perl6::Perldoc::Block::table::Cell';
2258  
2259 # Move left (right separator becomes left separator)
2260 63 $left_sep = $right_sep;
2261 }
2262  
2263 # Add the new row object...
2264 25 push @rows, bless {
2265 cells => \@cell_objs,
2266 }, 'Perl6::Perldoc::Block::table::Row';
2267  
2268 # Move downwards...
2269 25 $pre_sep = $post_sep;
2270 }
2271  
2272 7 return \@rows;
2273 }
2274  
2275 # Build entire table...
2276 7 ▶sub _build_table {
Subroutine _build_table: called CC=7 SCAR=19.5
2277 7 my ($text, $allow_ref, $config_stack_ref) = @_;
2278  
2279 # Remove surrounding blank lines...
2280 7 $text =~ s{\A ($HWS* \n)+ | (^ $HWS* \n?)+ \z}{}gxms;
2281  
2282 # Remove top/bottom border...
2283 7 ▶ $text =~ s{\A ($ROW_SEP_LINE)}{}xms; my $top_sep = $1 || q{};
Condition50%1/2
$1 || ''
l!l
07
MC/DC0%0/1
$1 || ''
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
2284 7 ▶ $text =~ s{\n ($ROW_SEP_LINE) \Z}{}xms; my $bottom_sep = $1 || q{};
Condition50%1/2
$1 || ''
l!l
07
MC/DC0%0/1
$1 || ''
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
2285  
2286 # Decompose into separated rows...
2287 7 my ($first_row, $first_sep, @rest) = split m{($ROW_SEP_LINE)}xms, $text;
2288 7 ▶ my $has_head = @rest != 0 && $first_sep =~ $NWS_ROW_SEP;
Condition100%3/3
@rest != 0 && $first_sep =~ /$NWS_ROW_SEP/
!ll&&!rl&&r
412
MC/DC100%2/2
@rest != 0 && $first_sep =~ /$NWS_ROW_SEP/
@rest != 0 $first_sep =~ /$NWS_ROW_SEP/
Truth table100%3/3
A && B
A= @rest != 0B= $first_sep =~ /$NWS_ROW_SEP/
ABresult
0X0
100
111
2289  
2290 7 ▶ my @rows = @rest == 0 ? (split m{(\n)}xms, $text)
Branch: 2 branches
BranchTrueFalseTotal
@rest == 0 ? : 4 3 7
@rest == 1 && !$bottom_sep ? : 1 2 3
Condition66%2/3
@rest == 1 and not $bottom_sep
!ll&&!rl&&r
201
MC/DC50%1/2
@rest == 1 and not $bottom_sep
@rest == 1 not $bottom_sep
Truth table66%2/3
A and not(B)
A= @rest == 1B= not $bottom_sep
ABresult
0X0
100
111
2291 : @rest == 1 && !$bottom_sep ?
2292 ($first_row, $first_sep, split m{(\n)}xms, $rest[0])
2293 : ($first_row, $first_sep, @rest)
2294 ;
2295  
2296 7 my @separators = ($top_sep, @rows[grep {$_%2!=0} 0..$#rows], $bottom_sep);
2297 7 my @cells = @rows[grep {$_%2==0} 0..$#rows];
2298  
2299 7 return _build_table_rows(
2300 $text, $has_head, \@cells, \@separators, $allow_ref, $config_stack_ref
2301 );
2302 }
2303  
2304 # Class to represent individual table row...
2305 package Perl6::Perldoc::Block::table::Row;
2306  
2307 # Read-only accessor for individual cells...
2308 25 ▶sub cells {
Subroutine cells: called CC=4 SCAR=20.1
2309 25 my ($self) = @_;
2310 25 my $vals_ref = $self->{cells};
2311 25 ▶ if (!wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 0 25 25
2312 0 ▶ if (@{ $vals_ref } > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$vals_ref;} > 1) 0 0 0
2313 0 ▶ require Carp and Carp::carp(
Branch: 1 branch
BranchTrueFalseTotal
require Carp and Carp::carp("Multivalued accessor cells() called in scalar context") 0 0 0
2314 "Multivalued accessor cells() called in scalar context"
2315 );
2316 }
2317 0 return $vals_ref->[0];
2318 }
2319 25 return @{ $vals_ref };
2320 }
2321  
2322 # Class to represent individual table cell...
2323 package Perl6::Perldoc::Block::table::Cell;
2324  
2325 # Read-only content accessor...
2326 63 ▶sub content {
Subroutine content: called CC=4 SCAR=20.1
2327 63 my ($self) = @_;
2328 63 my $vals_ref = $self->{content};
2329 63 ▶ if (!wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 0 63 63
2330 0 ▶ if (@{ $vals_ref } > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$vals_ref;} > 1) 0 0 0
2331 0 ▶ require Carp and Carp::carp(
Branch: 1 branch
BranchTrueFalseTotal
require Carp and Carp::carp("Multivalued accessor content() called in scalar context") 0 0 0
2332 "Multivalued accessor content() called in scalar context"
2333 );
2334 }
2335 0 return $vals_ref->[0];
2336 }
2337 63 return @{ $vals_ref };
2338 }
2339  
2340 # Is this a header row?
2341 0 ▶sub is_header {
Subroutine is_header: not called CC=1 SCAR=6.9
2342 0 my ($self) = @_;
2343 0 return $self->{header};
2344 }
2345  
2346  
2347 56 1;
2348  
2349 __END__
↑ Summary Perldoc/To/Xhtml.pm »