lib/Text/AsciidocDown/Parser.pm

filter: Statementstmt 86.7% 414 / 477 Branchbran 68.9% 193 / 280 Conditioncond 54.2% 89 / 164 MC/DCmcdc 33.3% 29 / 87 Subroutinesub 96.3% 26 / 27 Podpod 100% 1 / 1 totaltotal 72.5% 752 / 1036 CC 220 SCAR 44.2
CC
220
Cov
76%
_emit_delimited_block
348.0
_outdent_lines
72.0
_convert_text
67.8
CRAP 82.9
↑ Summary lib/Text/AsciidocDown/Include.pm »
1 package Text::AsciidocDown::Parser;
2  
3 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 18 our $VERSION = '0.1.3';
7  
8 18 ▶use Text::AsciidocDown::Subs ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 18 ▶use Text::AsciidocDown::Refs ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 18 my %THEMATIC_BREAKS = map { $_ => 1 } (q{'''}, '***', '---');
12 18 my %DELIMITERS = map { $_ => 1 } qw(---- .... ++++ ____ ==== **** --);
13 18 my %ADMON_TYPES = map { $_ => 1 } qw(NOTE TIP IMPORTANT WARNING CAUTION);
14  
15 18 my $ATTR_ENTRY_RX = qr/^:([^:-][^:]*):(?:\s(.*))?$/;
16 18 my $AUTHOR_LINE_RX = qr/^(?:[[:alnum:]_]+(?: +[[:alnum:]_]+){0,2}(?: +<[^>]+>)?(?:; |$))+$/;
17 18 my $REVISION_LINE_RX = qr/^v(\d+(?:[-.]\w+)*)(?:, (\d+-\d+-\d+))?$|^(\d+-\d+-\d+)$/;
18  
19 sub convert
20 99 ▶{
Subroutine convert: called CC=4 SCAR=14.0
Pod documented
21 99 my ($text, $opts) = @_;
22  
23 99 ▶ $text = '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 99 99
24 99 ▶ $opts ||= {};
Condition50%1/2
$opts ||= {}
l!l
990
MC/DC0%0/1
$opts ||= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
25  
26 99 my $attributes = $opts->{attributes};
27 99 ▶ $attributes = {} unless ref($attributes) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attributes eq "HASH" 92 7 99
28  
29 99 my $ctx = {
30 attributes => Text::AsciidocDown::Subs::build_attributes($attributes),
31 refs => Text::AsciidocDown::Refs::new_index(),
32 };
33  
34 99 return _convert_text($text, $ctx);
35 }
36  
37 sub _convert_text
38 99 ▶{
Subroutine _convert_text: called CC=63 SCAR=42.2
39 99 my ($text, $ctx) = @_;
40  
41 99 $text = _normalize_input($text);
42 99 ▶ return '' unless length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless length $text 1 98 99
43  
44 98 my @lines = split /\n/, $text, -1;
45 98 ▶ pop @lines if @lines && $lines[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if @lines and $lines[-1] eq "" 54 44 98
Condition66%2/3
@lines and $lines[-1] eq ""
!ll&&!rl&&r
04454
MC/DC50%1/2
@lines and $lines[-1] eq ""
@lines $lines[-1] eq ""
Truth table66%2/3
A and B
A= @linesB= $lines[-1] eq ""
ABresult
0X0
100
111
46 98 @lines = _preprocess_conditionals(\@lines, $ctx->{attributes});
47  
48 98 my @out;
49 98 my $attrs = $ctx->{attributes};
50 98 ▶ my $list_indent = int($attrs->{'markdown-list-indent'} || 2) || 2;
Condition50%2/4
int($attrs->{'markdown-list-indent'} || 2) || 2
l!l
980
$attrs->{'markdown-list-indent'} || 2
l!l
098
MC/DC0%0/1
int($attrs->{'markdown-list-indent'} || 2) || 2
$attrs->{'markdown-list-indent'}
Truth table50%1/2
A
A= $attrs->{'markdown-list-indent'}
Aresult
11
00
51  
52 98 ▶ my $in_header = (@lines && $lines[0] =~ /^=\s+/) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@lines && $lines[0] =~ /^=\s+/ ? : 20 78 98
Condition100%3/3
@lines and $lines[0] =~ /^=\s+/
!ll&&!rl&&r
17720
MC/DC100%2/2
@lines and $lines[0] =~ /^=\s+/
@lines $lines[0] =~ /^=\s+/
Truth table100%3/3
A and B
A= @linesB= $lines[0] =~ /^=\s+/
ABresult
0X0
100
111
53 98 my $had_doctitle = 0;
54  
55 98 my ($pending_title, $pending_attr);
56 98 my @list_stack;
57 98 my ($qanda_mode, $qanda_counter) = (0, 0);
58 98 my $continuation_prefix;
59  
60 LINE:
61 98 ▶ for (my $i = 0; $i <= $#lines; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#lines) 216 98 314
62 {
63 216 my $line = $lines[$i];
64  
65 216 ▶ if (!$had_doctitle && $line =~ /^=\s+(\S.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if (not $had_doctitle and $line =~ /^=\s+(\S.*)$/) 20 196 216
Condition100%3/3
not $had_doctitle and $line =~ /^=\s+(\S.*)$/
!ll&&!rl&&r
6712920
MC/DC100%2/2
not $had_doctitle and $line =~ /^=\s+(\S.*)$/
not $had_doctitle $line =~ /^=\s+(\S.*)$/
Truth table100%3/3
not(A) and B
A= not $had_doctitleB= $line =~ /^=\s+(\S.*)$/
ABresult
0X0
100
111
66 {
67 20 my $title = _apply_normal_subs($1, $attrs);
68 20 push @out, '# ' . $title;
69 20 $attrs->{doctitle} = $title;
70 20 Text::AsciidocDown::Refs::register_heading($ctx->{refs}, $attrs, $title, $pending_attr->{id}, $pending_attr->{reftext});
71 20 $had_doctitle = 1;
72 20 $pending_attr = undef;
73 20 next LINE;
74 }
75  
76 196 ▶ if ($in_header)
Branch: 1 branch
BranchTrueFalseTotal
if ($in_header) 22 174 196
77 {
78 22 ▶ if ($line =~ /^\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*$/) 19 3 22
79 {
80 19 $in_header = 0;
81 19 push @out, '';
82 19 next LINE;
83 }
84  
85 3 ▶ if (_consume_header_line($line, $attrs))
Branch: 1 branch
BranchTrueFalseTotal
if (_consume_header_line($line, $attrs)) 3 0 3
86 {
87 3 next LINE;
88 }
89  
90 0 $in_header = 0;
91  
92 # fall through to normal body processing for this line
93 }
94  
95 174 ▶ if (defined $continuation_prefix)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $continuation_prefix) 1 173 174
96 {
97 1 ▶ if ($line =~ /^\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*$/) 0 1 1
98 {
99 0 push @out, '';
100 0 $continuation_prefix = undef;
101 0 next LINE;
102 }
103 1 ▶ if (_list_item_info($line, $list_indent))
Branch: 2 branches
BranchTrueFalseTotal
if (_list_item_info($line, $list_indent)) { } 0 1 1
elsif (exists $DELIMITERS{$line} or $line =~ /^\s/) { } 0 1 1
104 {
105 0 $continuation_prefix = undef;
106 }
107 ▶ elsif (exists $DELIMITERS{$line} || ($line =~ /^\s/))
Condition33%1/3
exists $DELIMITERS{$line} or $line =~ /^\s/
l!l&&r!l&&!r
001
MC/DC0%0/2
exists $DELIMITERS{$line} or $line =~ /^\s/
exists $DELIMITERS{$line} $line =~ /^\s/
Truth table33%1/3
A or B
A= exists $DELIMITERS{$line}B= $line =~ /^\s/
ABresult
1X1
011
000
108 {
109 # allow block handlers below to consume with current continuation context
110 }
111 else
112 {
113 1 push @out, $continuation_prefix . _apply_normal_subs($line, $attrs);
114 1 next LINE;
115 }
116 }
117  
118 173 ▶ if ($line =~ $ATTR_ENTRY_RX)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$ATTR_ENTRY_RX/) 17 156 173
119 {
120 17 ▶ my ($name, $value) = ($1, defined($2) ? $2 : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 15 2 17
121 17 $attrs->{$name} = Text::AsciidocDown::Subs::substitute_attributes($value, $attrs);
122 17 next LINE;
123 }
124  
125 156 ▶ if ($line =~ /^\\(ifn?def::[^[]+\[.*\]|include::[^[]+\[.*\]|endif::\[\])$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\\(ifn?def::[^[]+\[.*\]|include::[^[]+\[.*\]|endif::\[\])$/) 2 154 156
126 {
127 2 push @out, $1;
128 2 next LINE;
129 }
130  
131 154 ▶ if ($line =~ /^\[(.+)\]$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\[(.+)\]$/) 6 148 154
132 {
133 6 $pending_attr = _parse_attrlist($1, $attrs);
134 6 next LINE;
135 }
136  
137 148 ▶ if ($line =~ /^\.(?!\.)(\S.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\.(?!\.)(\S.*)$/) 1 147 148
138 {
139 1 $pending_title = $1;
140 1 next LINE;
141 }
142  
143 147 ▶ if (_in_list_context(\@list_stack) && $line eq '+')
Branch: 1 branch
BranchTrueFalseTotal
if (_in_list_context(\@list_stack) and $line eq "+") 1 146 147
Condition100%3/3
_in_list_context(\@list_stack) and $line eq "+"
!ll&&!rl&&r
14241
MC/DC100%2/2
_in_list_context(\@list_stack) and $line eq "+"
_in_list_context(\@list_stack) $line eq "+"
Truth table100%3/3
A and B
A= _in_list_context(\@list_stack)B= $line eq "+"
ABresult
0X0
100
111
144 {
145 1 my $depth = scalar @list_stack;
146 1 $continuation_prefix = ' ' x ($depth * $list_indent);
147 1 next LINE;
148 }
149  
150 146 ▶ if ($line =~ /^include::[^[]+\[.*\]$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^include::[^[]+\[.*\]$/) 3 143 146
151 {
152 3 next LINE;
153 }
154  
155 143 ▶ if (exists $THEMATIC_BREAKS{$line})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $THEMATIC_BREAKS{$line}) 1 142 143
156 {
157 1 _emit_pending_title(\@out, \$pending_title, \$pending_attr, $attrs);
158 1 push @out, '---';
159 1 @list_stack = ();
160 1 $qanda_mode = 0;
161 1 next LINE;
162 }
163  
164 142 ▶ if ($line eq 'toc::[]' || $line eq '<<<')
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "toc::[]" or $line eq "<<<") 2 140 142
Condition100%3/3
$line eq "toc::[]" or $line eq "<<<"
l!l&&r!l&&!r
11140
MC/DC100%2/2
$line eq "toc::[]" or $line eq "<<<"
$line eq "toc::[]" $line eq "<<<"
Truth table100%3/3
A or B
A= $line eq "toc::[]"B= $line eq "<<<"
ABresult
1X1
011
000
165 {
166 2 next LINE;
167 }
168  
169 140 ▶ if (my $block_img = Text::AsciidocDown::Subs::block_image_to_markdown($line, $attrs))
Branch: 1 branch
BranchTrueFalseTotal
if (my $block_img = Text::AsciidocDown::Subs::block_image_to_markdown($line, $attrs)) 1 139 140
170 {
171 1 _emit_pending_title(\@out, \$pending_title, \$pending_attr, $attrs);
172 1 push @out, $block_img;
173 1 next LINE;
174 }
175  
176 139 ▶ if (exists $DELIMITERS{$line})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $DELIMITERS{$line}) 3 136 139
177 {
178 3 my $delim = $line;
179 3 my @content;
180 3 my $j = $i + 1;
181 3 ▶ while ($j <= $#lines && $lines[$j] ne $delim)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#lines and $lines[$j] ne $delim) 5 3 8
Condition66%2/3
$j <= $#lines and $lines[$j] ne $delim
!ll&&!rl&&r
035
MC/DC50%1/2
$j <= $#lines and $lines[$j] ne $delim
$j <= $#lines $lines[$j] ne $delim
Truth table66%2/3
A and B
A= $j <= $#linesB= $lines[$j] ne $delim
ABresult
0X0
100
111
182 {
183 5 push @content, $lines[$j];
184 5 $j++;
185 }
186 3 ▶ $i = $j <= $#lines ? $j : $#lines;
Branch: 1 branch
BranchTrueFalseTotal
$j <= $#lines ? : 3 0 3
187 3 _emit_pending_title(\@out, \$pending_title, \$pending_attr, $attrs);
188 3 _emit_delimited_block(\@out, $delim, \@content, $pending_attr, $attrs, $continuation_prefix);
189 3 $pending_attr = undef;
190 3 next LINE;
191 }
192  
193 136 ▶ if ($line eq '|===')
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "|===") 3 133 136
194 {
195 3 my @content;
196 3 my $j = $i + 1;
197 3 ▶ while ($j <= $#lines && $lines[$j] ne '|===')
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#lines and $lines[$j] ne "|===") 8 3 11
Condition66%2/3
$j <= $#lines and $lines[$j] ne "|==="
!ll&&!rl&&r
038
MC/DC50%1/2
$j <= $#lines and $lines[$j] ne "|==="
$j <= $#lines $lines[$j] ne "|==="
Truth table66%2/3
A and B
A= $j <= $#linesB= $lines[$j] ne "|==="
ABresult
0X0
100
111
198 {
199 8 push @content, $lines[$j];
200 8 $j++;
201 }
202 3 ▶ $i = $j <= $#lines ? $j : $#lines;
Branch: 1 branch
BranchTrueFalseTotal
$j <= $#lines ? : 3 0 3
203 3 _emit_pending_title(\@out, \$pending_title, \$pending_attr, $attrs);
204 3 _emit_table(\@out, \@content, $pending_attr, $attrs, $continuation_prefix);
205 3 $pending_attr = undef;
206 3 next LINE;
207 }
208  
209 133 ▶ if ($line =~ /^\s/ && $line !~ /^\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s/ and not $line =~ /^\s*$/) 2 131 133
Condition66%2/3
$line =~ /^\s/ and not $line =~ /^\s*$/
!ll&&!rl&&r
13102
MC/DC50%1/2
$line =~ /^\s/ and not $line =~ /^\s*$/
$line =~ /^\s/ not $line =~ /^\s*$/
Truth table66%2/3
A and not(B)
A= $line =~ /^\s/B= not $line =~ /^\s*$/
ABresult
0X0
100
111
210 {
211 2 my @content = ($line);
212 2 my $j = $i + 1;
213 2 ▶ while ($j <= $#lines && $lines[$j] =~ /^\s/ && $lines[$j] !~ /^\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#lines and $lines[$j] =~ /^\s/ and not $lines[$j] =~ /^\s*$/) 1 2 3
Condition66%4/6
$j <= $#lines and $lines[$j] =~ /^\s/ and not $lines[$j] =~ /^\s*$/
!ll&&!rl&&r
201
$j <= $#lines and $lines[$j] =~ /^\s/
!ll&&!rl&&r
201
MC/DC33%1/3
$j <= $#lines and $lines[$j] =~ /^\s/ and not $lines[$j] =~ /^\s*$/
$j <= $#lines $lines[$j] =~ /^\s/ not $lines[$j] =~ /^\s*$/
Truth table50%2/4
A and B and not(C)
A= $j <= $#linesB= $lines[$j] =~ /^\s/C= not $lines[$j] =~ /^\s*$/
ABCresult
0XX0
10X0
1100
1111
214 {
215 1 push @content, $lines[$j];
216 1 $j++;
217 }
218 2 $i = $j - 1;
219 2 _emit_pending_title(\@out, \$pending_title, \$pending_attr, $attrs);
220 2 _emit_literal_paragraph(\@out, \@content, $pending_attr, $attrs, $continuation_prefix);
221 2 $pending_attr = undef;
222 2 next LINE;
223 }
224  
225 131 ▶ if (my $item = _list_item_info($line, $list_indent))
Branch: 1 branch
BranchTrueFalseTotal
if (my $item = _list_item_info($line, $list_indent)) { } 9 122 131
226 {
227 9 _emit_pending_title(\@out, \$pending_title, \$pending_attr, $attrs);
228 9 ▶ if ($item->{type} ne 'dl')
Branch: 2 branches
BranchTrueFalseTotal
if ($item->{'type'} ne 'dl') { } 6 3 9
elsif ($pending_attr and ($pending_attr->{'style'} || '') eq 'qanda' or $qanda_mode) { } 2 1 3
229 {
230 6 $qanda_mode = 0;
231 }
232 ▶ elsif (($pending_attr && (($pending_attr->{style} || '') eq 'qanda')) || $qanda_mode)
Condition75%6/8
$pending_attr and ($pending_attr->{"style"} || "") eq "qanda" or $qanda_mode
l!l&&r!l&&!r
111
$pending_attr and ($pending_attr->{"style"} || "") eq "qanda"
!ll&&!rl&&r
201
$pending_attr->{'style'} || ''
l!l
10
MC/DC66%2/3
$pending_attr and ($pending_attr->{"style"} || "") eq "qanda" or $qanda_mode
$pending_attr $pending_attr->{'style'} $qanda_mode
Truth table60%3/5
A and B or C
A= $pending_attrB= $pending_attr->{'style'}C= $qanda_mode
ABCresult
11X1
0X11
1011
0X00
1000
233 {
234 2 $qanda_mode = 1;
235 }
236  
237 9 _update_list_stack(\@list_stack, $item->{depth}, $item->{type});
238 9 my $indent = ' ' x (($item->{depth} - 1) * $list_indent);
239 9 my $text = _apply_normal_subs($item->{text}, $attrs);
240  
241 9 ▶ if ($item->{type} eq 'ul')
Branch: 3 branches
BranchTrueFalseTotal
if ($item->{'type'} eq 'ul') { } 5 4 9
elsif ($item->{'type'} eq 'ol') { } 1 3 4
elsif ($item->{'type'} eq 'dl') { } 3 0 3
242 {
243 5 ▶ if ($text =~ /^\[(x|\*| )\]\s*(.*)$/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^\[(x|\*| )\]\s*(.*)$/i) { } 2 3 5
244 {
245 2 ▶ my $mark = (lc($1) eq ' ') ? ' ' : 'x';
Branch: 1 branch
BranchTrueFalseTotal
lc $1 eq ' ' ? : 1 1 2
246 2 push @out, $indent . '* [' . $mark . '] ' . $2;
247 }
248 else
249 {
250 3 push @out, $indent . '* ' . $text;
251 }
252 }
253 elsif ($item->{type} eq 'ol')
254 {
255 1 push @out, $indent . '1. ' . $text;
256 }
257 elsif ($item->{type} eq 'dl')
258 {
259 3 my $term = _apply_normal_subs($item->{term}, $attrs);
260 3 ▶ if ($qanda_mode)
Branch: 1 branch
BranchTrueFalseTotal
if ($qanda_mode) { } 2 1 3
261 {
262 2 $qanda_counter++;
263 2 push @out, $indent . '1. _' . $term . '_';
264 }
265 else
266 {
267 1 push @out, $indent . '* **' . $term . '**';
268 }
269 3 ▶ if (defined $item->{desc} && $item->{desc} ne '')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $item->{"desc"} and $item->{"desc"} ne "") 3 0 3
Condition33%1/3
defined $item->{"desc"} and $item->{"desc"} ne ""
!ll&&!rl&&r
003
MC/DC0%0/2
defined $item->{"desc"} and $item->{"desc"} ne ""
defined $item->{"desc"} $item->{"desc"} ne ""
Truth table33%1/3
A and B
A= defined $item->{"desc"}B= $item->{"desc"} ne ""
ABresult
0X0
100
111
270 {
271 3 my $desc = _apply_normal_subs($item->{desc}, $attrs);
272 3 push @out, $indent . ' ' . $desc;
273 }
274 }
275 9 $pending_attr = undef;
276 9 next LINE;
277 }
278 else
279 {
280 122 ▶ @list_stack = () if @list_stack && $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if @list_stack and $line =~ /^\s*$/ 0 122 122
Condition33%1/3
@list_stack and $line =~ /^\s*$/
!ll&&!rl&&r
12200
MC/DC0%0/2
@list_stack and $line =~ /^\s*$/
@list_stack $line =~ /^\s*$/
Truth table33%1/3
A and B
A= @list_stackB= $line =~ /^\s*$/
ABresult
0X0
100
111
281 }
282  
283 122 ▶ if ($line =~ /^(={2,6})\s+(\S.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(={2,6})\s+(\S.*)$/) 16 106 122
284 {
285 16 _emit_pending_title(\@out, \$pending_title, \$pending_attr, $attrs);
286 16 my $level = length($1);
287 16 my $title = _apply_normal_subs($2, $attrs);
288 16 push @out, ('#' x $level) . ' ' . $title;
289 16 Text::AsciidocDown::Refs::register_heading($ctx->{refs}, $attrs, $title, $pending_attr->{id}, $pending_attr->{reftext});
290 16 $pending_attr = undef;
291 16 next LINE;
292 }
293  
294 106 ▶ if ($line =~ /^(.*) \+$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(.*) \+$/) 1 105 106
295 {
296 1 _emit_pending_title(\@out, \$pending_title, \$pending_attr, $attrs);
297 1 ▶ my $mark = exists $attrs->{'markdown-line-break'} ? $attrs->{'markdown-line-break'} : q{\\};
Branch: 1 branch
BranchTrueFalseTotal
exists $attrs->{'markdown-line-break'} ? : 1 0 1
298 1 my $base = _apply_normal_subs($1, $attrs);
299 1 push @out, $base . $mark;
300 1 $pending_attr = undef;
301 1 next LINE;
302 }
303  
304 105 _emit_pending_title(\@out, \$pending_title, \$pending_attr, $attrs);
305 105 push @out, _apply_normal_subs($line, $attrs);
306 }
307  
308 98 my $output = _normalize_output(join("\n", @out), $ctx);
309 98 return Text::AsciidocDown::Refs::rewrite_links($ctx->{refs}, $output);
310 }
311  
312 sub _preprocess_conditionals
313 98 ▶{
Subroutine _preprocess_conditionals: called CC=15 SCAR=27.1
314 98 my ($lines, $attrs) = @_;
315 98 my @out;
316 my @stack;
317  
318 98 for my $line (@{$lines})
319 {
320 243 ▶ if (!_stack_blocks(\@stack) && $line =~ $ATTR_ENTRY_RX)
Branch: 1 branch
BranchTrueFalseTotal
if (not _stack_blocks(\@stack) and $line =~ /$ATTR_ENTRY_RX/) 19 224 243
Condition100%3/3
not _stack_blocks(\@stack) and $line =~ /$ATTR_ENTRY_RX/
!ll&&!rl&&r
222219
MC/DC100%2/2
not _stack_blocks(\@stack) and $line =~ /$ATTR_ENTRY_RX/
not _stack_blocks(\@stack) $line =~ /$ATTR_ENTRY_RX/
Truth table100%3/3
not(A) and B
A= not _stack_blocks(\@stack)B= $line =~ /$ATTR_ENTRY_RX/
ABresult
0X0
100
111
321 {
322 19 ▶ my ($name, $value) = ($1, defined($2) ? $2 : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 17 2 19
323 19 $attrs->{$name} = Text::AsciidocDown::Subs::substitute_attributes($value, $attrs);
324 }
325  
326 243 ▶ if ($line =~ /^\\(ifn?def::[^[]+\[.*\]|include::[^[]+\[.*\]|endif::\[\])$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\\(ifn?def::[^[]+\[.*\]|include::[^[]+\[.*\]|endif::\[\])$/) 2 241 243
327 {
328 2 push @out, $line;
329 2 next;
330 }
331  
332 241 ▶ if ($line =~ /^if(n)?def::([^[]+)\[(.*)\]$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^if(n)?def::([^[]+)\[(.*)\]$/) 6 235 241
333 {
334 6 my ($neg, $name, $body) = ($1, $2, $3);
335 6 my $is_set = exists $attrs->{$name};
336 6 ▶ my $take = $neg ? !$is_set : $is_set;
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 2 4 6
337 6 ▶ if ($body ne '')
Branch: 1 branch
BranchTrueFalseTotal
if ($body ne '') { } 4 2 6
338 {
339 4 ▶ push @out, $body if $take && !_stack_blocks(\@stack);
Branch: 1 branch
BranchTrueFalseTotal
if $take and not _stack_blocks(\@stack) 2 2 4
Condition66%2/3
$take and not _stack_blocks(\@stack)
!ll&&!rl&&r
202
MC/DC50%1/2
$take and not _stack_blocks(\@stack)
$take not _stack_blocks(\@stack)
Truth table66%2/3
A and not(B)
A= $takeB= not _stack_blocks(\@stack)
ABresult
0X0
100
111
340 }
341 else
342 {
343 2 ▶ push @stack, $take ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$take ? : 1 1 2
344 }
345 6 next;
346 }
347  
348 235 ▶ if ($line eq 'endif::[]')
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "endif::[]") 2 233 235
349 {
350 2 ▶ if (@stack)
Branch: 1 branch
BranchTrueFalseTotal
if (@stack) { } 2 0 2
351 {
352 2 pop @stack;
353 }
354 else
355 {
356 0 push @out, $line;
357 }
358 2 next;
359 }
360  
361 233 ▶ next if _stack_blocks(\@stack);
Branch: 1 branch
BranchTrueFalseTotal
if _stack_blocks(\@stack) 1 232 233
362 232 push @out, $line;
363 }
364  
365 98 return @out;
366 }
367  
368 sub _stack_blocks
369 478 ▶{
Subroutine _stack_blocks: called CC=3 SCAR=11.0
370 478 my ($stack) = @_;
371 478 for my $flag (@{$stack})
372 {
373 10 ▶ return 1 unless $flag;
Branch: 1 branch
BranchTrueFalseTotal
unless $flag 3 7 10
374 }
375 475 return 0;
376 }
377  
378 sub _emit_delimited_block
379 3 ▶{
Subroutine _emit_delimited_block: called CC=37 SCAR=58.5
380 3 my ($out, $delim, $content, $meta, $attrs, $prefix) = @_;
381 3 ▶ $meta ||= {};
Condition100%2/2
$meta ||= {}
l!l
21
MC/DC100%1/1
$meta ||= {}
$meta
Truth table100%2/2
A
A= $meta
Aresult
11
00
382  
383 3 ▶ if ($delim eq '++++')
Branch: 1 branch
BranchTrueFalseTotal
if ($delim eq "++++") 0 3 3
384 {
385 0 for my $line (@{$content})
386 {
387 0 ▶ push @{$out}, defined($prefix) ? ($prefix . $line) : $line;
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 0 0
388 }
389 0 return;
390 }
391  
392 3 ▶ if ($delim eq '____')
Branch: 1 branch
BranchTrueFalseTotal
if ($delim eq "____") 0 3 3
393 {
394 0 for my $line (@{$content})
395 {
396 0 ▶ my $txt = $line eq '' ? '' : _apply_normal_subs($line, $attrs);
Branch: 1 branch
BranchTrueFalseTotal
$line eq '' ? : 0 0 0
397 0 ▶ push @{$out}, (defined($prefix) ? $prefix : '') . '> ' . $txt;
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 0 0
398 }
399 0 return;
400 }
401  
402 3 ▶ if ($delim eq '====' && exists $ADMON_TYPES{uc($meta->{style} || '')})
Branch: 1 branch
BranchTrueFalseTotal
if ($delim eq "====" and exists $ADMON_TYPES{uc($meta->{"style"} || "")}) 0 3 3
Condition20%1/5
$delim eq "====" and exists $ADMON_TYPES{uc($meta->{"style"} || "")}
!ll&&!rl&&r
300
$meta->{'style'} || ''
l!l
00
MC/DC0%0/2
$delim eq "====" and exists $ADMON_TYPES{uc($meta->{"style"} || "")}
$delim eq "====" exists $ADMON_TYPES{uc($meta->{"style"} || "")}
MC/DC0%0/1
$meta->{'style'} || ''
$meta->{'style'}
Truth table33%1/3
A and B
A= $delim eq "===="B= exists $ADMON_TYPES{uc($meta->{"style"} || "")}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $meta->{'style'}
Aresult
11
00
403 {
404 0 my $kind = uc($meta->{style});
405 0 ▶ if (@{$content})
Branch: 1 branch
BranchTrueFalseTotal
if (@{$content;}) { } 0 0 0
406 {
407 0 my $first = _apply_normal_subs($content->[0], $attrs);
408 0 ▶ push @{$out}, (defined($prefix) ? $prefix : '') . '**' . $kind . ':** ' . $first;
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 0 0
409 0 for my $i (1 .. $#{$content})
410 {
411 0 ▶ push @{$out}, (defined($prefix) ? $prefix : '') . _apply_normal_subs($content->[$i], $attrs);
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 0 0
412 }
413 }
414 else
415 {
416 0 ▶ push @{$out}, (defined($prefix) ? $prefix : '') . '**' . $kind . ':**';
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 0 0
417 }
418 0 return;
419 }
420  
421 3 ▶ if ($delim eq '----' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($delim eq "----" or $delim eq "...." or ($meta->{"style"} || "") eq "source" or ($meta->{"style"} || "") eq "listing" or ($meta->{"style"} || "") eq "literal") 3 0 3
Condition27%5/18
$delim eq "----" or $delim eq "...." or ($meta->{"style"} || "") eq "source" or ($meta->{"style"} || "") eq "listing" or ($meta->{"style"} || "") eq "literal"
l!l&&r!l&&!r
300
$delim eq "----" or $delim eq "...." or ($meta->{"style"} || "") eq "source" or ($meta->{"style"} || "") eq "listing"
l!l&&r!l&&!r
300
$delim eq "----" or $delim eq "...." or ($meta->{"style"} || "") eq "source"
l!l&&r!l&&!r
300
$delim eq "----" or $delim eq "...."
l!l&&r!l&&!r
210
$meta->{'style'} || ''
l!l
00
$meta->{'style'} || ''
l!l
00
$meta->{'style'} || ''
l!l
00
MC/DC0%0/5
$delim eq "----" or $delim eq "...." or ($meta->{"style"} || "") eq "source" or ($meta->{"style"} || "") eq "listing" or ($meta->{"style"} || "") eq "literal"
$delim eq "----" $delim eq "...." $meta->{'style'} $meta->{'style'} $meta->{'style'}
Truth table33%2/6
A or B or C or D or E
A= $delim eq "----"B= $delim eq "...."C= $meta->{'style'}D= $meta->{'style'}E= $meta->{'style'}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
422 $delim eq '....' ||
423 (($meta->{style} || '') eq 'source') ||
424 (($meta->{style} || '') eq 'listing') ||
425 (($meta->{style} || '') eq 'literal'))
426 {
427 3 my $lang = '';
428 3 ▶ if (($meta->{style} || '') eq 'source')
Branch: 1 branch
BranchTrueFalseTotal
if (($meta->{"style"} || "") eq "source") 2 1 3
Condition100%2/2
$meta->{'style'} || ''
l!l
21
MC/DC100%1/1
$meta->{'style'} || ''
$meta->{'style'}
Truth table100%2/2
A
A= $meta->{'style'}
Aresult
11
00
429 {
430 2 ▶ $lang = $meta->{lang} || ($attrs->{'source-language'} || '');
Condition60%3/5
$meta->{'lang'} || ($attrs->{'source-language'} || '')
l!l&&r!l&&!r
101
$attrs->{"source-language"} or ""
l!l
01
MC/DC50%1/2
$meta->{'lang'} || ($attrs->{'source-language'} || '')
$meta->{'lang'} $attrs->{"source-language"}
Truth table66%2/3
A || B
A= $meta->{'lang'}B= $attrs->{"source-language"}
ABresult
1X1
011
000
431 }
432 3 my $seq = 1;
433 3 my @lines = @{$content};
434 3 ▶ @lines = _outdent_lines(\@lines) if (($meta->{indent} || '') eq '0');
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{"indent"} || "") eq 0 0 3 3
Condition50%1/2
$meta->{'indent'} || ''
l!l
03
MC/DC0%0/1
$meta->{'indent'} || ''
$meta->{'indent'}
Truth table50%1/2
A
A= $meta->{'indent'}
Aresult
11
00
435 3 ▶ push @{$out}, (defined($prefix) ? $prefix : '') . '```' . $lang;
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 3 3
436 3 for my $line (@lines)
437 {
438 5 my $txt = _apply_verbatim_subs($line, $meta, $attrs, \$seq);
439 5 ▶ push @{$out}, (defined($prefix) ? $prefix : '') . $txt;
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 5 5
440 }
441 3 ▶ push @{$out}, (defined($prefix) ? $prefix : '') . '```';
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 3 3
442 3 return;
443 }
444  
445 # Open/example/sidebar and unknown container: unwrap delimiters and keep content.
446 0 for my $line (@{$content})
447 {
448 0 ▶ push @{$out}, (defined($prefix) ? $prefix : '') . _apply_normal_subs($line, $attrs);
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 0 0
449 }
450 }
451  
452 sub _emit_literal_paragraph
453 2 ▶{
Subroutine _emit_literal_paragraph: called CC=10 SCAR=23.6
454 2 my ($out, $content, $meta, $attrs, $prefix) = @_;
455 2 ▶ $meta ||= {};
Condition100%2/2
$meta ||= {}
l!l
11
MC/DC100%1/1
$meta ||= {}
$meta
Truth table100%2/2
A
A= $meta
Aresult
11
00
456 2 my @lines = map { my $x = $_; $x =~ s/^\s//; $x } @{$content};
457 2 ▶ @lines = _outdent_lines(\@lines) if (($meta->{indent} || '') eq '0');
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{"indent"} || "") eq 0 0 2 2
Condition50%1/2
$meta->{'indent'} || ''
l!l
02
MC/DC0%0/1
$meta->{'indent'} || ''
$meta->{'indent'}
Truth table50%1/2
A
A= $meta->{'indent'}
Aresult
11
00
458 2 ▶ my $lang = ($lines[0] // '') =~ /^\$\s/ ? 'console' : '';
Branch: 1 branch
BranchTrueFalseTotal
($lines[0] // '') =~ /^\$\s/ ? : 1 1 2
Condition50%1/2
$lines[0] // ""
l!l
20
MC/DC0%0/1
$lines[0] // ""
$lines[0]
Truth table50%1/2
A
A= $lines[0]
Aresult
11
00
459 2 my $seq = 1;
460  
461 2 ▶ push @{$out}, (defined($prefix) ? $prefix : '') . '```' . $lang;
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 2 2
462 2 for my $line (@lines)
463 {
464 3 my $txt = _apply_verbatim_subs($line, $meta, $attrs, \$seq);
465 3 ▶ push @{$out}, (defined($prefix) ? $prefix : '') . $txt;
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 3 3
466 }
467 2 ▶ push @{$out}, (defined($prefix) ? $prefix : '') . '```';
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 2 2
468 }
469  
470 sub _apply_verbatim_subs
471 8 ▶{
Subroutine _apply_verbatim_subs: called CC=2 SCAR=7.0
472 8 my ($line, $meta, $attrs, $seq_ref) = @_;
473 $line = Text::AsciidocDown::Subs::substitute_attributes($line, $attrs)
474 8 ▶ if $meta->{subs_attributes};
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"subs_attributes"} 0 8 8
475 8 $line =~ s/<([.]|1?\d)>/_render_conum($1, $seq_ref)/ge;
476 8 return $line;
477 }
478  
479 sub _render_conum
480 2 ▶{
Subroutine _render_conum: called CC=2 SCAR=6.9
481 2 my ($token, $seq_ref) = @_;
482 2 ▶ my $n = $token eq '.' ? $$seq_ref++ : int($token);
Branch: 1 branch
BranchTrueFalseTotal
$token eq '.' ? : 1 1 2
483 2 return _circled_num($n);
484 }
485  
486 sub _circled_num
487 2 ▶{
Subroutine _circled_num: called CC=3 SCAR=12.5
488 2 my ($n) = @_;
489 2 ▶ return '(' . $n . ')' if $n < 1 || $n > 20;
Branch: 1 branch
BranchTrueFalseTotal
if $n < 1 or $n > 20 0 2 2
Condition33%1/3
$n < 1 or $n > 20
l!l&&r!l&&!r
002
MC/DC0%0/2
$n < 1 or $n > 20
$n < 1 $n > 20
Truth table33%1/3
A or B
A= $n < 1B= $n > 20
ABresult
1X1
011
000
490 2 return chr(0x2460 + ($n - 1));
491 }
492  
493 sub _outdent_lines
494 0 ▶{
Subroutine _outdent_lines: not called CC=8 SCAR=42.8
495 0 my ($lines) = @_;
496 0 my $min = undef;
497 0 for my $line (@{$lines})
498 {
499 0 ▶ next if $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 0 0
500 0 my ($lead) = $line =~ /^(\s*)/;
501 0 ▶ my $len = length($lead || '');
Condition0%0/2
$lead || ''
l!l
00
MC/DC0%0/1
$lead || ''
$lead
Truth table0%0/2
A
A= $lead
Aresult
11
00
502 0 ▶ $min = $len if !defined($min) || $len < $min;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $min or $len < $min 0 0 0
Condition0%0/3
not defined $min or $len < $min
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $min or $len < $min
not defined $min $len < $min
Truth table0%0/3
not(A) or B
A= not defined $minB= $len < $min
ABresult
1X1
011
000
503 }
504 0 ▶ return @{$lines} unless defined $min && $min > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min and $min > 0 0 0 0
Condition0%0/3
defined $min and $min > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $min and $min > 0
defined $min $min > 0
Truth table0%0/3
A and B
A= defined $minB= $min > 0
ABresult
0X0
100
111
505 0 return map { my $x = $_; $x =~ s/^\s{0,$min}//; $x } @{$lines};
506 }
507  
508 sub _emit_pending_title
509 141 ▶{
Subroutine _emit_pending_title: called CC=6 SCAR=18.6
510 141 my ($out, $title_ref, $meta_ref, $attrs) = @_;
511 141 ▶ return unless defined $$title_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$title_ref 140 1 141
512 1 ▶ my $meta = $$meta_ref || {};
Condition50%1/2
$$meta_ref || {}
l!l
10
MC/DC0%0/1
$$meta_ref || {}
$$meta_ref
Truth table50%1/2
A
A= $$meta_ref
Aresult
11
00
513 1 my $title = _apply_normal_subs($$title_ref, $attrs);
514 1 ▶ my $anchor = defined($meta->{id}) ? '<a name="' . $meta->{id} . '"></a>' : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $meta->{'id'} ? : 1 0 1
515 1 push @{$out}, $anchor . '**' . $title . '**';
516 1 ▶ push @{$out}, '' if @{$out} && $out->[-1] ne '';
Branch: 1 branch
BranchTrueFalseTotal
if @{$out;} and $out->[-1] ne "" 1 0 1
Condition33%1/3
@{$out;} and $out->[-1] ne ""
!ll&&!rl&&r
001
MC/DC0%0/2
@{$out;} and $out->[-1] ne ""
@{$out;} $out->[-1] ne ""
Truth table33%1/3
A and B
A= @{$out;}B= $out->[-1] ne ""
ABresult
0X0
100
111
517 1 $$title_ref = undef;
518 }
519  
520 sub _emit_table
521 3 ▶{
Subroutine _emit_table: called CC=26 SCAR=34.8
522 3 my ($out, $content, $meta, $attrs, $prefix) = @_;
523 3 ▶ $meta ||= {};
Condition100%2/2
$meta ||= {}
l!l
21
MC/DC100%1/1
$meta ||= {}
$meta
Truth table100%2/2
A
A= $meta
Aresult
11
00
524 3 my ($cols, $aligns) = _parse_cols_spec($meta->{cols});
525  
526 3 my @rows;
527 my @pending_cells;
528 3 for my $line (@{$content})
529 {
530 8 ▶ next if $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 8 8
531 8 ▶ if ($line =~ /^\|/)
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^\|/) { } 8 0 8
elsif (@rows) { } 0 0 0
532 {
533 8 my @cells = split /\|/, $line;
534 8 shift @cells;
535 8 @cells = map { _normalize_cell($_) } @cells;
536 8 ▶ if ($cols)
Branch: 1 branch
BranchTrueFalseTotal
if ($cols) { } 6 2 8
537 {
538 6 push @pending_cells, @cells;
539 6 ▶ while (@pending_cells >= $cols)
Branch: 1 branch
BranchTrueFalseTotal
if (@pending_cells >= $cols) 4 6 10
540 {
541 4 my @row = splice @pending_cells, 0, $cols;
542 4 push @rows, \@row;
543 }
544 }
545 else
546 {
547 2 push @rows, \@cells;
548 }
549 }
550 elsif (@rows)
551 {
552 0 $rows[-1][-1] .= ' ' . _normalize_cell($line);
553 }
554 }
555  
556 3 ▶ if ($cols && @pending_cells)
Branch: 1 branch
BranchTrueFalseTotal
if ($cols and @pending_cells) 0 3 3
Condition66%2/3
$cols and @pending_cells
!ll&&!rl&&r
120
MC/DC0%0/2
$cols and @pending_cells
$cols @pending_cells
Truth table66%2/3
A and B
A= $colsB= @pending_cells
ABresult
0X0
100
111
557 {
558 0 ▶ push @pending_cells, ('') x ($cols - @pending_cells) if @pending_cells < $cols;
Branch: 1 branch
BranchTrueFalseTotal
if @pending_cells < $cols 0 0 0
559 0 push @rows, [splice @pending_cells, 0, $cols];
560 }
561 3 ▶ return unless @rows;
Branch: 1 branch
BranchTrueFalseTotal
unless @rows 0 3 3
562  
563 3 ▶ $cols ||= _max_cols(\@rows);
Condition66%2/3
$cols ||= _max_cols(\@rows)
l!l&&r!l&&!r
210
MC/DC0%0/2
$cols ||= _max_cols(\@rows)
$cols _max_cols(\@rows)
Truth table66%2/3
A ||= B
A= $colsB= _max_cols(\@rows)
ABresult
1X1
011
000
564 3 for my $r (@rows)
565 {
566 0 ▶ push @{$r}, ('') x ($cols - @{$r}) if @{$r} < $cols;
Branch: 1 branch
BranchTrueFalseTotal
if @{$r;} < $cols 0 6 6
567 6 ▶ $#$r = $cols - 1 if @{$r} > $cols;
Branch: 1 branch
BranchTrueFalseTotal
if @{$r;} > $cols 0 6 6
568 }
569  
570 3 ▶ my $header = $meta->{'header-option'} ? 1 : ($meta->{'noheader-option'} ? 0 : 1);
Branch: 2 branches
BranchTrueFalseTotal
$meta->{'header-option'} ? : 1 2 3
$meta->{'noheader-option'} ? : 0 2 2
571 3 my @body = @rows;
572 3 ▶ my @head = $header ? @{shift @body} : (('') x $cols);
Branch: 1 branch
BranchTrueFalseTotal
$header ? : 3 0 3
573  
574 3 my @div;
575 3 for my $i (0 .. $cols - 1)
576 {
577 7 ▶ my $al = ($aligns->[$i] // '');
Condition100%2/2
$aligns->[$i] // ""
l!l
52
MC/DC100%1/1
$aligns->[$i] // ""
$aligns->[$i]
Truth table100%2/2
A
A= $aligns->[$i]
Aresult
11
00
578 7 ▶ push @div, $al eq '<' ? ':--' : $al eq '^' ? ':-:' : $al eq '>' ? '--:' : '---';
Branch: 3 branches
BranchTrueFalseTotal
$al eq '<' ? : 1 6 7
$al eq '^' ? : 1 5 6
$al eq '>' ? : 1 4 5
579 }
580  
581 3 ▶ my $p = defined($prefix) ? $prefix : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 3 3
582 3 push @{$out}, $p . '| ' . join(' | ', map { _apply_normal_subs($_, $attrs) } @head) . ' |';
583 3 push @{$out}, $p . '| ' . join(' | ', @div) . ' |';
584 3 for my $r (@body)
585 {
586 3 push @{$out}, $p . '| ' . join(' | ', map { _apply_normal_subs($_, $attrs) } @{$r}) . ' |';
587 }
588 }
589  
590 sub _normalize_cell
591 14 ▶{
Subroutine _normalize_cell: called CC=2 SCAR=7.0
592 14 my ($cell) = @_;
593 14 ▶ $cell //= '';
Condition50%1/2
$cell //= ""
l!l
140
MC/DC0%0/1
$cell //= ""
$cell
Truth table50%1/2
A
A= $cell
Aresult
11
00
594 14 $cell =~ s/^\s+|\s+$//g;
595 14 $cell =~ s/^[<>^.]?[a-z]?\|?\s*//;
596 14 return $cell;
597 }
598  
599 sub _max_cols
600 1 ▶{
Subroutine _max_cols: called CC=4 SCAR=13.9
601 1 my ($rows) = @_;
602 1 my $max = 0;
603 1 for my $r (@{$rows})
604 {
605 2 ▶ $max = @{$r} if @{$r} > $max;
Branch: 1 branch
BranchTrueFalseTotal
if @{$r;} > $max 1 1 2
606 }
607 1 ▶ return $max || 1;
Condition50%1/2
$max || 1
l!l
10
MC/DC0%0/1
$max || 1
$max
Truth table50%1/2
A
A= $max
Aresult
11
00
608 }
609  
610 sub _parse_cols_spec
611 3 ▶{
Subroutine _parse_cols_spec: called CC=7 SCAR=19.5
612 3 my ($raw) = @_;
613 3 ▶ return (0, []) unless defined $raw && $raw ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw and $raw ne "" 1 2 3
Condition66%2/3
defined $raw and $raw ne ""
!ll&&!rl&&r
102
MC/DC50%1/2
defined $raw and $raw ne ""
defined $raw $raw ne ""
Truth table66%2/3
A and B
A= defined $rawB= $raw ne ""
ABresult
0X0
100
111
614  
615 2 my @tokens = split /[,;]/, $raw;
616 2 my @aligns;
617 2 for my $tok (@tokens)
618 {
619 4 $tok =~ s/^\s+|\s+$//g;
620 4 ▶ next if $tok eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $tok eq "" 0 4 4
621 4 my $rep = 1;
622 4 ▶ if ($tok =~ /^(\d+)\*(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($tok =~ /^(\d+)\*(.*)$/) 1 3 4
623 {
624 1 $rep = int($1);
625 1 $tok = $2;
626 }
627 4 my ($al) = $tok =~ /([<>^])/;
628 4 ▶ $al ||= '';
Condition100%2/2
$al ||= ""
l!l
31
MC/DC100%1/1
$al ||= ""
$al
Truth table100%2/2
A
A= $al
Aresult
11
00
629 4 push @aligns, (($al) x $rep);
630 }
631  
632 2 return (scalar(@aligns), \@aligns);
633 }
634  
635 sub _parse_attrlist
636 6 ▶{
Subroutine _parse_attrlist: called CC=19 SCAR=30.0
637 6 my ($raw, $attrs) = @_;
638 6 my %meta;
639  
640 6 ▶ if ($raw =~ /cols="([^"]+)"/)
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /cols="([^"]+)"/) 1 5 6
641 {
642 1 $meta{cols} = Text::AsciidocDown::Subs::substitute_attributes($1, $attrs);
643 }
644 6 ▶ if ($raw =~ /reftext="([^"]+)"/)
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /reftext="([^"]+)"/) 0 6 6
645 {
646 0 $meta{reftext} = Text::AsciidocDown::Subs::substitute_attributes($1, $attrs);
647 }
648  
649 6 my @parts = map { my $x = $_; $x =~ s/^\s+|\s+$//g; $x } split /,/, $raw;
650 6 my @pos;
651  
652 6 for my $p (@parts)
653 {
654 10 ▶ next unless length $p;
Branch: 1 branch
BranchTrueFalseTotal
unless length $p 0 10 10
655 10 ▶ if ($p =~ /^#([A-Za-z_][A-Za-z0-9_\-:.]*)$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($p =~ /^#([A-Za-z_][A-Za-z0-9_\-:.]*)$/) { } 1 9 10
elsif ($p =~ /^([A-Za-z0-9_-]+)=(.*)$/) { } 2 7 9
656 {
657 1 $meta{id} = $1;
658 }
659 elsif ($p =~ /^([A-Za-z0-9_-]+)=(.*)$/)
660 {
661 2 my ($k, $v) = ($1, $2);
662 2 ▶ next if $k eq 'cols' && exists $meta{cols};
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "cols" and exists $meta{"cols"} 1 1 2
Condition66%2/3
$k eq "cols" and exists $meta{"cols"}
!ll&&!rl&&r
011
MC/DC50%1/2
$k eq "cols" and exists $meta{"cols"}
$k eq "cols" exists $meta{"cols"}
Truth table66%2/3
A and B
A= $k eq "cols"B= exists $meta{"cols"}
ABresult
0X0
100
111
663 1 $v =~ s/^"|"$//g;
664 1 $v = Text::AsciidocDown::Subs::substitute_attributes($v, $attrs);
665 1 $meta{$k} = $v;
666 1 ▶ $meta{subs_attributes} = 1 if $k eq 'subs' && $v =~ /attributes/;
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "subs" and $v =~ /attributes/ 0 1 1
Condition33%1/3
$k eq "subs" and $v =~ /attributes/
!ll&&!rl&&r
100
MC/DC0%0/2
$k eq "subs" and $v =~ /attributes/
$k eq "subs" $v =~ /attributes/
Truth table33%1/3
A and B
A= $k eq "subs"B= $v =~ /attributes/
ABresult
0X0
100
111
667 1 ▶ $meta{indent} = $v if $k eq 'indent';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "indent" 0 1 1
668 }
669 else
670 {
671 7 ▶ if ($p =~ /^%([A-Za-z0-9_-]+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($p =~ /^%([A-Za-z0-9_-]+)$/) 1 6 7
672 {
673 1 $meta{$1 . '-option'} = 1;
674 1 next;
675 }
676 6 push @pos, $p;
677 6 ▶ $meta{id} = $1 if $p =~ /^#([A-Za-z_][A-Za-z0-9_\-:.]*)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ /^#([A-Za-z_][A-Za-z0-9_\-:.]*)$/ 0 6 6
678 }
679 }
680  
681 6 ▶ $meta{style} = $pos[0] if @pos;
Branch: 1 branch
BranchTrueFalseTotal
if @pos 4 2 6
682 6 ▶ $meta{lang} = $pos[1] if ($meta{style} || '') eq 'source' && defined $pos[1] && $pos[1] ne '';
Branch: 1 branch
BranchTrueFalseTotal
if ($meta{"style"} || "") eq "source" and defined $pos[1] and $pos[1] ne "" 1 5 6
Condition87%7/8
($meta{"style"} || "") eq "source" and defined $pos[1] and $pos[1] ne ""
!ll&&!rl&&r
501
($meta{"style"} || "") eq "source" and defined $pos[1]
!ll&&!rl&&r
411
$meta{'style'} || ''
l!l
42
MC/DC66%2/3
($meta{"style"} || "") eq "source" and defined $pos[1] and $pos[1] ne ""
$meta{'style'} defined $pos[1] $pos[1] ne ""
Truth table75%3/4
A and B and C
A= $meta{'style'}B= defined $pos[1]C= $pos[1] ne ""
ABCresult
0XX0
10X0
1100
1111
683 6 return \%meta;
684 }
685  
686 sub _list_item_info
687 132 ▶{
Subroutine _list_item_info: called CC=9 SCAR=23.1
688 132 my ($line, $list_indent) = @_;
689 132 my ($spaces, $rest) = $line =~ /^(\s*)(.*)$/;
690 132 ▶ my $extra = int((length($spaces || '')) / ($list_indent || 2));
Condition50%2/4
$spaces || ''
l!l
0132
$list_indent || 2
l!l
1320
MC/DC0%0/1
$spaces || ''
$spaces
MC/DC0%0/1
$list_indent || 2
$list_indent
Truth table50%1/2
A
A= $spaces
Aresult
11
00
Truth table50%1/2
A
A= $list_indent
Aresult
11
00
691  
692 132 ▶ if ($rest =~ /^(\*+|-+)\s+(.+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /^(\*+|-+)\s+(.+)$/) 5 127 132
693 {
694 5 return {type => 'ul', depth => length($1) + $extra, text => $2};
695 }
696 127 ▶ if ($rest =~ /^(\.+)\s+(.+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /^(\.+)\s+(.+)$/) 1 126 127
697 {
698 1 return {type => 'ol', depth => length($1) + $extra, text => $2};
699 }
700 126 ▶ if ($rest =~ /^(\d+\.)\s+(.+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /^(\d+\.)\s+(.+)$/) 0 126 126
701 {
702 0 return {type => 'ol', depth => 1 + $extra, text => $2};
703 }
704 126 ▶ if ($rest =~ /^<(?:[1-9]|1\d|\.)>\s+(.+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /^<(?:[1-9]|1\d|\.)>\s+(.+)$/) 0 126 126
705 {
706 0 return {type => 'ol', depth => 1 + $extra, text => $1};
707 }
708 126 ▶ if ($rest =~ /^(?!:\s)(\S.*?)::(?:\s+(.*))?$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /^(?!:\s)(\S.*?)::(?:\s+(.*))?$/) 3 123 126
709 {
710 3 ▶ return {type => 'dl', depth => 1 + $extra, term => $1, desc => (defined($2) ? $2 : ''), text => $1};
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 3 0 3
711 }
712 123 return undef;
713 }
714  
715 sub _update_list_stack
716 9 ▶{
Subroutine _update_list_stack: called CC=3 SCAR=11.3
717 9 my ($stack, $depth, $type) = @_;
718 9 ▶ $depth = 1 if $depth < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $depth < 1 0 9 9
719 9 ▶ $#$stack = $depth - 1 if @{$stack} > $depth;
Branch: 1 branch
BranchTrueFalseTotal
if @{$stack;} > $depth 0 9 9
720 9 $stack->[$depth - 1] = $type;
721 }
722  
723 sub _in_list_context
724 147 ▶{
Subroutine _in_list_context: called CC=1 SCAR=0.0
725 147 my ($stack) = @_;
726 147 return scalar @{$stack} > 0;
727 }
728  
729 sub _consume_header_line
730 3 ▶{
Subroutine _consume_header_line: called CC=14 SCAR=41.0
731 3 my ($line, $attrs) = @_;
732  
733 3 ▶ if ($line =~ $ATTR_ENTRY_RX)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$ATTR_ENTRY_RX/) 2 1 3
734 {
735 2 ▶ my ($name, $value) = ($1, defined($2) ? $2 : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 2 0 2
736 2 $attrs->{$name} = Text::AsciidocDown::Subs::substitute_attributes($value, $attrs);
737 2 return 1;
738 }
739  
740 1 ▶ if (!exists $attrs->{author} && $line =~ $AUTHOR_LINE_RX)
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $attrs->{"author"} and $line =~ /$AUTHOR_LINE_RX/) 1 0 1
Condition33%1/3
not exists $attrs->{"author"} and $line =~ /$AUTHOR_LINE_RX/
!ll&&!rl&&r
001
MC/DC0%0/2
not exists $attrs->{"author"} and $line =~ /$AUTHOR_LINE_RX/
not exists $attrs->{"author"} $line =~ /$AUTHOR_LINE_RX/
Truth table33%1/3
not(A) and B
A= not exists $attrs->{"author"}B= $line =~ /$AUTHOR_LINE_RX/
ABresult
0X0
100
111
741 {
742 1 my @authors = map { s/\s*<[^>]+>\s*\z//r } split /;\s*/, $line;
743 1 ▶ $attrs->{author} = $authors[0] if @authors;
Branch: 1 branch
BranchTrueFalseTotal
if @authors 1 0 1
744 1 ▶ $attrs->{authors} = join(', ', @authors) if @authors;
Branch: 1 branch
BranchTrueFalseTotal
if @authors 1 0 1
745 1 return 1;
746 }
747  
748 0 ▶ if (!exists $attrs->{revnumber} && !exists $attrs->{revdate} && $line =~ $REVISION_LINE_RX)
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $attrs->{"revnumber"} || exists $attrs->{"revdate"} and $line =~ /$REVISION_LINE_RX/) 0 0 0
Condition0%0/6
not exists $attrs->{"revnumber"} || exists $attrs->{"revdate"} and $line =~ /$REVISION_LINE_RX/
!ll&&!rl&&r
000
exists $attrs->{'revnumber'} || exists $attrs->{'revdate'}
l!l&&r!l&&!r
000
MC/DC0%0/3
not exists $attrs->{"revnumber"} || exists $attrs->{"revdate"} and $line =~ /$REVISION_LINE_RX/
exists $attrs->{'revnumber'} exists $attrs->{'revdate'} $line =~ /$REVISION_LINE_RX/
Truth table0%0/4
not(A || B) and C
A= exists $attrs->{'revnumber'}B= exists $attrs->{'revdate'}C= $line =~ /$REVISION_LINE_RX/
ABCresult
1XX0
01X0
0000
0011
749 {
750 0 my ($revnumber, $revdate1, $revdate2) = ($1, $2, $3);
751 0 ▶ $attrs->{revnumber} = $revnumber if defined $revnumber;
Branch: 1 branch
BranchTrueFalseTotal
if defined $revnumber 0 0 0
752 0 ▶ $attrs->{revdate} = defined($revdate1) ? $revdate1 : $revdate2 if defined($revdate1) || defined($revdate2);
Branch: 2 branches
BranchTrueFalseTotal
if defined $revdate1 or defined $revdate2 0 0 0
defined $revdate1 ? : 0 0 0
Condition0%0/3
defined $revdate1 or defined $revdate2
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $revdate1 or defined $revdate2
defined $revdate1 defined $revdate2
Truth table0%0/3
A or B
A= defined $revdate1B= defined $revdate2
ABresult
1X1
011
000
753 0 return 1;
754 }
755  
756 0 return 0;
757 }
758  
759 sub _apply_normal_subs
760 173 ▶{
Subroutine _apply_normal_subs: called CC=1 SCAR=0.0
761 173 my ($line, $attrs) = @_;
762 173 return Text::AsciidocDown::Subs::apply_normal_subs($line, $attrs);
763 }
764  
765 sub _normalize_input
766 99 ▶{
Subroutine _normalize_input: called CC=2 SCAR=7.0
767 99 my ($text) = @_;
768 99 ▶ $text = '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 99 99
769 99 $text =~ s/\r\n?/\n/g;
770 99 return $text;
771 }
772  
773 sub _normalize_output
774 98 ▶{
Subroutine _normalize_output: called CC=1 SCAR=0.0
775 98 my ($text, undef) = @_;
776  
777 98 $text =~ s/\r\n?/\n/g;
778 98 $text =~ s/[ \t]+$//mg;
779 98 $text =~ s/\n{3,}/\n\n/g;
780 98 $text =~ s/\A(?:\n)+//;
781 98 $text =~ s/(?:\n)+\z//;
782  
783 98 return $text;
784 }
785  
786 18 1;
787  
788 __END__
↑ Summary lib/Text/AsciidocDown/Include.pm »