Compiler/Parser.pm

filter: Statementstmt 68.2% 258 / 378 Branchbran 57.6% 121 / 210 Conditioncond 25.0% 14 / 56 MC/DCmcdc 18.9% 7 / 37 Subroutinesub 80.0% 20 / 25 Podpod 0.0% 0 / 2 totaltotal 59.3% 420 / 708 CC 127 SCAR 39.5
CC
127
Cov
61%
make_hash
200.7
_parse_list_ordered
113.2
_parse_paragraph
43.4
CRAP 52.1
↑ Summary Compiler/Target/Tree.pm »
1 package Markdown::Compiler::Parser;
2 18 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 {
4 package Markdown::Compiler::Parser::Node;
5 18 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 18 has tokens => (
8 is => 'ro',
9 required => 1,
10 );
11
12 18 has children => (
13 is => 'ro',
14 );
15  
16 18 has content => (
17 is => 'ro',
18 );
19  
20 18 1;
21 }
22  
23 {
24 18 package Markdown::Compiler::Parser::Node::Metadata;
25 18 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 18 extends 'Markdown::Compiler::Parser::Node';
27  
28 18 has data => (
29 is => 'ro',
30 );
31  
32 # content => $content,
33 # tokens => [ @tree ],
34 # data => $struct,
35 18 1;
36 }
37  
38 {
39 18 package Markdown::Compiler::Parser::Node::Metadata::Key;
40 18 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 18 extends 'Markdown::Compiler::Parser::Node';
42  
43 18 1;
44 }
45  
46 {
47 18 package Markdown::Compiler::Parser::Node::Metadata::Value;
48 18 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 18 extends 'Markdown::Compiler::Parser::Node';
50  
51 18 1;
52 }
53 }
54 18 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 18 has stream => (
57 is => 'ro',
58 required => 1,
59 );
60  
61 18 has tree => (
62 is => 'ro',
63 lazy => 1,
64 builder => '_build_tree',
65 );
66  
67 18 has htree => (
68 is => 'ro',
69 lazy => 1,
70 builder => '_build_htree',
71 );
72  
73 18 has metadata => (
74 is => 'ro',
75 lazy => 1,
76 builder => '_build_metadata',
77 );
78  
79  
80 64 ▶sub _build_tree {
Subroutine _build_tree: called CC=1 SCAR=0.0
81 64 my ( $self ) = @_;
82  
83 64 my @tokens = @{$self->stream};
84  
85 64 return $self->make_hash($self->_parse(\@tokens));
86 }
87  
88 173 ▶sub make_hash {
Subroutine make_hash: called CC=21 SCAR=53.0
Pod undocumented
89 173 my ( $self, $tokens ) = @_;
90  
91 173 my @stream;
92  
93 173 foreach my $token ( @{$tokens} ) {
94  
95 421 ▶ if ( ref($token) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $token eq 'HASH') { } 421 0 421
96 421 ▶ if ( $token->{children} && @{$token->{children}} >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"children"} and @{$token->{"children"};} >= 1) 109 312 421
Condition66%2/3
$token->{"children"} and @{$token->{"children"};} >= 1
!ll&&!rl&&r
3120109
MC/DC50%1/2
$token->{"children"} and @{$token->{"children"};} >= 1
$token->{"children"} @{$token->{"children"};} >= 1
Truth table66%2/3
A and B
A= $token->{"children"}B= @{$token->{"children"};} >= 1
ABresult
0X0
100
111
97 109 $token->{children} = [ $self->make_hash( $token->{children} ) ];
98 }
99 421 push @stream, $token;
100 } else {
101 0 ▶ push @stream, {
Branch: 8 branches
BranchTrueFalseTotal
$token->can('data') && $token->data ? : 0 0 0
$token->can('href') && $token->href ? : 0 0 0
$token->can('title') && $token->title ? : 0 0 0
$token->can('size') && $token->size ? : 0 0 0
$token->can('text') && $token->text ? : 0 0 0
$token->can('language') && $token->language ? : 0 0 0
$token->can('content') && $token->content ? : 0 0 0
$token->can('children') && $token->children ? : 0 0 0
Condition0%0/24
$token->can("data") and $token->data
!ll&&!rl&&r
000
$token->can("href") and $token->href
!ll&&!rl&&r
000
$token->can("title") and $token->title
!ll&&!rl&&r
000
$token->can("size") and $token->size
!ll&&!rl&&r
000
$token->can("text") and $token->text
!ll&&!rl&&r
000
$token->can("language") and $token->language
!ll&&!rl&&r
000
$token->can("content") and $token->content
!ll&&!rl&&r
000
$token->can("children") and $token->children
!ll&&!rl&&r
000
MC/DC0%0/2
$token->can("data") and $token->data
$token->can("data") $token->data
MC/DC0%0/2
$token->can("href") and $token->href
$token->can("href") $token->href
MC/DC0%0/2
$token->can("title") and $token->title
$token->can("title") $token->title
MC/DC0%0/2
$token->can("size") and $token->size
$token->can("size") $token->size
MC/DC0%0/2
$token->can("text") and $token->text
$token->can("text") $token->text
MC/DC0%0/2
$token->can("language") and $token->language
$token->can("language") $token->language
MC/DC0%0/2
$token->can("content") and $token->content
$token->can("content") $token->content
MC/DC0%0/2
$token->can("children") and $token->children
$token->can("children") $token->children
Truth table0%0/3
A and B
A= $token->can("data")B= $token->data
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $token->can("href")B= $token->href
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $token->can("title")B= $token->title
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $token->can("size")B= $token->size
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $token->can("text")B= $token->text
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $token->can("language")B= $token->language
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $token->can("content")B= $token->content
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $token->can("children")B= $token->children
ABresult
0X0
100
111
102 class => ref($token),
103 tokens => [ $token->tokens ],
104 ( $token->can('data') && $token->data ? ( data => $token->data ) : () ),
105 ( $token->can('href') && $token->href ? ( href => $token->href ) : () ),
106 ( $token->can('title') && $token->title ? ( title => $token->title ) : () ),
107 ( $token->can('size') && $token->size ? ( size => $token->size ) : () ),
108 ( $token->can('text') && $token->text ? ( text => $token->text ) : () ),
109 ( $token->can('language') && $token->language ? ( language => $token->language ) : () ),
110 ( $token->can('content') && $token->content ? ( content => $token->content ) : () ),
111 ( $token->can('children') && $token->children ? ( children => [ $self->make_hash($token->children) ] ) : () ),
112 };
113 }
114 }
115  
116 173 return [ @stream ];
117 }
118  
119 0 ▶sub _build_metadata {
Subroutine _build_metadata: not called CC=3 SCAR=24.8
120 0 my ( $self ) = @_;
121  
122 0 ▶ if ( $self->tree->[0] and $self->tree->[0]->{class} eq 'Markdown::Compiler::Parser::Node::Metadata' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tree->[0] and $self->tree->[0]{"class"} eq "Markdown::Compiler::Parser::Node::Metadata") 0 0 0
Condition0%0/3
$self->tree->[0] and $self->tree->[0]{"class"} eq "Markdown::Compiler::Parser::Node::Metadata"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->tree->[0] and $self->tree->[0]{"class"} eq "Markdown::Compiler::Parser::Node::Metadata"
$self->tree->[0] $self->tree->[0]{"class"} eq "Markdown::Compiler::Parser::Node::Metadata"
Truth table0%0/3
A and B
A= $self->tree->[0]B= $self->tree->[0]{"class"} eq "Markdown::Compiler::Parser::Node::Metadata"
ABresult
0X0
100
111
123 0 return $self->tree->[0]->{data};
124 }
125 0 return undef;
126 }
127  
128 64 ▶sub _parse {
Subroutine _parse: called CC=11 SCAR=24.7
129 64 my ( $self, $tokens ) = @_;
130 64 my @tree;
131  
132 64 ▶ while ( defined ( my $token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = shift @{$tokens;})) 76 64 140
133 # Header
134 76 ▶ if ( $token->type eq 'Header' ) {
Branch: 8 branches
BranchTrueFalseTotal
if ($token->type eq 'Header') { } 1 75 76
elsif (grep {$token->type eq $_;} 'EscapedChar', 'Image', 'Link', 'Word', 'Char', 'Bold', 'Italic', 'BoldItalic', 'InlineCode') { } 57 18 75
elsif ($token->type eq 'HR') { } 0 18 18
elsif ($token->type eq 'TableStart') { } 3 15 18
elsif ($token->type eq 'BlockQuote') { } 1 14 15
elsif ($token->type eq 'CodeBlock') { } 2 12 14
elsif ($token->type eq 'Item') { } 4 8 12
elsif (grep {$token->type eq $_;} 'LineBreak') { } 8 0 8
135 1 push @tree, {
136 class => 'Markdown::Compiler::Parser::Node::Header',
137 size => $token->size,
138 title => $token->title,
139 # tokens => [ $token ],
140 content => $token->content,
141 children => [ $self->_parse_paragraph(Markdown::Compiler->new( source => $token->title )->lexer->tokens) ],
142 };
143 1 next;
144 }
145  
146 # Paragraphs
147 675 elsif ( grep { $token->type eq $_ } ( qw( EscapedChar Image Link Word Char Bold Italic BoldItalic InlineCode ) ) ) {
148 57 unshift @{$tokens}, $token; # Put the token back and go to paragraph context.
149 57 push @tree, {
150 class => 'Markdown::Compiler::Parser::Node::Paragraph',
151 children => [ $self->_parse_paragraph( $tokens ) ],
152 };
153  
154 57 next;
155 }
156
157 # HR
158 elsif ( $token->type eq 'HR' ) {
159 # When is an HR not an HR? -- When it's actually the beginning
160 # of metadata. If this is the first token, then we are dealing
161 # with metadata, not an HR.
162 0 ▶ if ( $token->start == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->start == 0) 0 0 0
163 push @tree, Markdown::Compiler::Parser::Node::Metadata->new(
164 0 %{ $self->_parse_metadata($tokens) },
165 );
166 # language => $token->language,
167 # tokens => [ $token ],
168 # children => [ $self->_parse_metadata( $tokens ) ],
169 0 next;
170 }
171  
172 # Otherwise, we just have a simple HR token.
173 0 push @tree, {
174 class => 'Markdown::Compiler::Parser::Node::HR',
175 # tokens => [ $token ],
176 };
177 0 next;
178 }
179  
180 # Tables
181 elsif ( $token->type eq 'TableStart' ) {
182 3 unshift @{$tokens}, $token; # Put the token back and go to table context.
183 3 push @tree, {
184 class => 'Markdown::Compiler::Parser::Node::Table',
185 # tokens => [ $token ],
186 children => [ $self->_parse_table( $tokens ) ],
187 };
188 3 next;
189 }
190
191 # Blockquotes
192 elsif ( $token->type eq 'BlockQuote' ) {
193 1 push @tree, {
194 class => 'Markdown::Compiler::Parser::Node::BlockQuote',
195 # tokens => [ $token ],
196 children => [ $self->_parse_blockquote( $tokens ) ],
197 };
198 1 next;
199 }
200
201 # Code Blocks
202 elsif ( $token->type eq 'CodeBlock' ) {
203 2 push @tree, {
204 class => 'Markdown::Compiler::Parser::Node::CodeBlock',
205 language => $token->language,
206 # tokens => [ $token ],
207 children => [ $self->_parse_codeblock( $tokens ) ],
208 };
209 2 next;
210 }
211
212 # Lists
213 elsif ( $token->type eq 'Item' ) {
214 # Put the item token back so that _parse_list knows what kind it is.
215 4 unshift @{$tokens}, $token;
216 4 push @tree, $self->_parse_list( $tokens );
217 4 next;
218 }
219  
220 # Tokens To Ignore
221 8 elsif ( grep { $token->type eq $_ } ( qw( LineBreak ) ) ) {
222 # Do Nothing.
223 8 next;
224 }
225  
226 # Unknown Token?
227 else {
228 18 ▶ use Data::Dumper::Concise;
Subroutine BEGIN: called CC=1 SCAR=0.0
229 0 die "Parser::_parse() could not handle token " . $token->type . " on line " . $token->line;
230 }
231 }
232 64 return [ @tree ];
233 }
234  
235 77 ▶sub _parse_paragraph {
Subroutine _parse_paragraph: called CC=25 SCAR=37.7
236 77 my ( $self, $tokens ) = @_;
237  
238 77 my @tree;
239  
240 77 ▶ while ( defined ( my $token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = shift @{$tokens;})) 307 72 379
241 # Exit Conditions:
242 #
243 # - No more tokens (after while loop)
244 # - Two new line tokens in a rwo (first one is eaten)
245 307 ▶ if ( $token->type eq 'LineBreak' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "LineBreak") 7 300 307
246 7 ▶ if ( exists $tokens->[0] and $tokens->[0]->type eq 'LineBreak' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tokens->[0] and $tokens->[0]->type eq "LineBreak") 5 2 7
Condition100%3/3
exists $tokens->[0] and $tokens->[0]->type eq "LineBreak"
!ll&&!rl&&r
115
MC/DC100%2/2
exists $tokens->[0] and $tokens->[0]->type eq "LineBreak"
exists $tokens->[0] $tokens->[0]->type eq "LineBreak"
Truth table100%3/3
A and B
A= exists $tokens->[0]B= $tokens->[0]->type eq "LineBreak"
ABresult
0X0
100
111
247 # Double Line Break, Bail Out
248 5 return @tree;
249 }
250 # Single Line Break - Ignore
251 2 next;
252 }
253 # Exit Conditions Continued:
254 #
255 # - Tokens which are invalid in this context, put the token back and return our @ree
256 300 ▶ if ( grep { $token->type eq $_ } (qw(TableStart CodeBlock BlockQuote List HR Header)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$token->type eq $_;} "TableStart", "CodeBlock", "BlockQuote", "List", "HR", "Header") 0 300 300
257 0 unshift @$tokens, $token;
258 0 return @tree;
259 }
260  
261  
262 # Parsing
263 300 ▶ if ( grep { $token->type eq $_ } (qw(EscapedChar Space Word Char)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$token->type eq $_;} "EscapedChar", "Space", "Word", "Char") 272 28 300
264 272 push @tree, {
265 class => 'Markdown::Compiler::Parser::Node::Paragraph::String',
266 content => $token->content,
267 # tokens => [ $token ],
268 };
269 272 next;
270 }
271  
272 28 ▶ if ( grep { $token->type eq $_ } (qw(Link)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$token->type eq $_;} "Link") 9 19 28
273 9 push @tree, {
274 class => 'Markdown::Compiler::Parser::Node::Paragraph::Link',
275 text => $token->text,
276 title => $token->title,
277 href => $token->href,
278 # tokens => [ $token ],
279 };
280 9 next;
281 }
282
283 19 ▶ if ( $token->type eq 'Image' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "Image") 4 15 19
284 4 push @tree, {
285 class => 'Markdown::Compiler::Parser::Node::Paragraph::Image',
286 text => $token->text,
287 title => $token->title,
288 href => $token->href,
289 # tokens => [ $token ],
290 };
291 4 next;
292 }
293  
294 15 ▶ if ( $token->type eq 'InlineCode' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "InlineCode") 2 13 15
295 2 my @todo;
296  
297 # Eat tokens until the next Bold block, these tokens will be recursively processed.
298 2 ▶ while ( defined ( my $todo_token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $todo_token = shift @{$tokens;})) 5 0 5
299 5 ▶ last if $todo_token->type eq 'InlineCode';
Branch: 1 branch
BranchTrueFalseTotal
if $todo_token->type eq "InlineCode" 2 3 5
300  
301 # Don't cross linebreak boundries
302 3 ▶ if ( $todo_token->type eq 'LineBreak' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($todo_token->type eq "LineBreak") 0 3 3
303 0 unshift @{$tokens}, $todo_token;
304 0 last;
305 }
306  
307 3 push @todo, $todo_token;
308 }
309  
310 # Handle the children as plain strings.
311 push @tree, {
312 class => 'Markdown::Compiler::Parser::Node::Paragraph::InlineCode',
313 content => $token->content,
314 # tokens => [ $token ],
315 children => [
316 2 map { +{
317 3 class => 'Markdown::Compiler::Parser::Node::Paragraph::String',
318 content => $_->content,
319 tokens => [ $_ ],
320 } } @todo
321 ],
322 };
323 2 next;
324 }
325
326 13 ▶ if ( $token->type eq 'BoldItalic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "BoldItalic") 0 13 13
327 0 my @todo;
328  
329 # Eat tokens until the next BoldItalic block, these tokens will be recursively processed.
330 0 ▶ while ( defined ( my $todo_token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $todo_token = shift @{$tokens;})) 0 0 0
331 0 ▶ last if $todo_token->type eq 'BoldItalic';
Branch: 1 branch
BranchTrueFalseTotal
if $todo_token->type eq "BoldItalic" 0 0 0
332  
333 # Don't cross linebreak boundries
334 0 ▶ if ( $todo_token->type eq 'LineBreak' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($todo_token->type eq "LineBreak") 0 0 0
335 0 unshift @{$tokens}, $todo_token;
336 0 last;
337 }
338  
339 0 push @todo, $todo_token;
340 }
341  
342 # Process the children with _parse_paragraph.
343 0 push @tree, {
344 class => 'Markdown::Compiler::Parser::Node::Paragraph::BoldItalic',
345 content => $token->content,
346 # tokens => [ $token ],
347 children => [ $self->_parse_paragraph( \@todo ) ],
348 };
349 0 next;
350 }
351
352 13 ▶ if ( $token->type eq 'Bold' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "Bold") 6 7 13
353 6 my @todo;
354  
355 # Eat tokens until the next Bold block, these tokens will be recursively processed.
356 6 ▶ while ( defined ( my $todo_token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $todo_token = shift @{$tokens;})) 16 0 16
357 16 ▶ last if $todo_token->type eq 'Bold';
Branch: 1 branch
BranchTrueFalseTotal
if $todo_token->type eq "Bold" 6 10 16
358  
359 # Don't cross linebreak boundries
360 10 ▶ if ( $todo_token->type eq 'LineBreak' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($todo_token->type eq "LineBreak") 0 10 10
361 0 unshift @{$tokens}, $todo_token;
362 0 last;
363 }
364  
365 10 push @todo, $todo_token;
366 }
367  
368 # Process the children with _parse_paragraph.
369 6 push @tree, {
370 class => 'Markdown::Compiler::Parser::Node::Paragraph::Bold',
371 content => $token->content,
372 # tokens => [ $token ],
373 children => [ $self->_parse_paragraph( \@todo ) ],
374 };
375 6 next;
376 }
377  
378 7 ▶ if ( $token->type eq 'Italic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq 'Italic') { } 7 0 7
379 7 my @todo;
380  
381 # Eat tokens until the next Italic block, these tokens will be recursively processed.
382 7 ▶ while ( defined ( my $todo_token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $todo_token = shift @{$tokens;})) 20 0 20
383 20 ▶ last if $todo_token->type eq 'Italic';
Branch: 1 branch
BranchTrueFalseTotal
if $todo_token->type eq "Italic" 7 13 20
384  
385 # Don't cross linebreak boundries
386 13 ▶ if ( $todo_token->type eq 'LineBreak' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($todo_token->type eq "LineBreak") 0 13 13
387 0 unshift @{$tokens}, $todo_token;
388 0 last;
389 }
390  
391 13 push @todo, $todo_token;
392 }
393  
394 # Process the children with _parse_paragraph.
395 7 push @tree, {
396 class => 'Markdown::Compiler::Parser::Node::Paragraph::Italic',
397 content => $token->content,
398 # tokens => [ $token ],
399 children => [ $self->_parse_paragraph( \@todo ) ],
400 };
401 7 next;
402 }
403
404 # Unknown Token?
405 else {
406 0 die "Parser::_parse_paragraph() could not handle token " . $token->{type};
407 }
408 }
409 72 return @tree;
410 }
411  
412 3 ▶sub _parse_table_row {
Subroutine _parse_table_row: called CC=7 SCAR=19.7
413 3 my ( $self, $tokens ) = @_;
414
415 3 my @tree;
416  
417 # We must eat from here to
418 3 ▶ while ( my $token = shift @{ $tokens } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = shift @{$tokens;}) 3 3 6
419 3 ▶ last if $token->type eq 'LineBreak';
Branch: 1 branch
BranchTrueFalseTotal
if $token->type eq "LineBreak" 0 3 3
420  
421 3 my @todo;
422 # Eat all of the tokens from here until the next |
423 3 ▶ while ( defined ( my $todo_token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $todo_token = shift @{$tokens;})) 6 0 6
424 6 ▶ last if $todo_token->type eq 'Char' and $todo_token->content eq '|';
Branch: 1 branch
BranchTrueFalseTotal
if $todo_token->type eq "Char" and $todo_token->content eq "|" 3 3 6
Condition66%2/3
$todo_token->type eq "Char" and $todo_token->content eq "|"
!ll&&!rl&&r
303
MC/DC50%1/2
$todo_token->type eq "Char" and $todo_token->content eq "|"
$todo_token->type eq "Char" $todo_token->content eq "|"
Truth table66%2/3
A and B
A= $todo_token->type eq "Char"B= $todo_token->content eq "|"
ABresult
0X0
100
111
425 3 ▶ last if $todo_token->type eq 'LineBreak';
Branch: 1 branch
BranchTrueFalseTotal
if $todo_token->type eq "LineBreak" 0 3 3
426 3 push @todo, $todo_token;
427 }
428 3 push @tree, {
429 class => 'Markdown::Compiler::Parser::Node::Table::Cell',
430 content => $token->content,
431 # tokens => [ $token ],
432 children => [ $self->_parse_paragraph( \@todo ) ],
433 };
434 3 next;
435 }
436  
437 3 return @tree;
438 }
439  
440 3 ▶sub _parse_table_header_row {
Subroutine _parse_table_header_row: called CC=7 SCAR=19.7
441 3 my ( $self, $tokens ) = @_;
442
443 3 my @tree;
444  
445 # We must eat from here to
446 3 ▶ while ( my $token = shift @{ $tokens } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = shift @{$tokens;}) 3 3 6
447 3 ▶ last if $token->type eq 'LineBreak';
Branch: 1 branch
BranchTrueFalseTotal
if $token->type eq "LineBreak" 0 3 3
448  
449 3 my @todo;
450 # Eat all of the tokens from here until the next |
451 3 ▶ while ( defined ( my $todo_token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $todo_token = shift @{$tokens;})) 6 0 6
452 6 ▶ last if $todo_token->type eq 'Char' and $todo_token->content eq '|';
Branch: 1 branch
BranchTrueFalseTotal
if $todo_token->type eq "Char" and $todo_token->content eq "|" 3 3 6
Condition66%2/3
$todo_token->type eq "Char" and $todo_token->content eq "|"
!ll&&!rl&&r
303
MC/DC50%1/2
$todo_token->type eq "Char" and $todo_token->content eq "|"
$todo_token->type eq "Char" $todo_token->content eq "|"
Truth table66%2/3
A and B
A= $todo_token->type eq "Char"B= $todo_token->content eq "|"
ABresult
0X0
100
111
453 3 ▶ last if $todo_token->type eq 'LineBreak';
Branch: 1 branch
BranchTrueFalseTotal
if $todo_token->type eq "LineBreak" 0 3 3
454 3 push @todo, $todo_token;
455 }
456 3 push @tree, {
457 class => 'Markdown::Compiler::Parser::Node::Table::HeaderCell',
458 content => $token->content,
459 # tokens => [ $token ],
460 children => [ $self->_parse_paragraph( \@todo ) ],
461 };
462 3 next;
463 }
464  
465 3 return @tree;
466 }
467  
468 3 ▶sub _parse_table {
Subroutine _parse_table: called CC=10 SCAR=23.2
469 3 my ( $self, $tokens ) = @_;
470
471 3 my @tree;
472  
473 3 my $is_first_row = 1;
474 3 ▶ while ( defined ( my $token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = shift @{$tokens;})) 20 0 20
475 # Exit Conditions:
476 #
477 # - Line break and no more tokens (after while loop)
478 # - Line break, and another line break.
479 20 ▶ if ( $token->type eq 'LineBreak' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "LineBreak") 7 13 20
480 7 ▶ return @tree unless @$tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless @$tokens 0 7 7
481 7 ▶ return @tree if $tokens->[0]->type eq 'LineBreak';
Branch: 1 branch
BranchTrueFalseTotal
if $tokens->[0]->type eq "LineBreak" 3 4 7
482 }
483  
484 17 ▶ if ( $token->type eq 'TableStart' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "TableStart") 6 11 17
485 6 my @todo;
486  
487 # Eat tokens until the next Italic block, these tokens will be recursively processed.
488 6 ▶ while ( defined ( my $todo_token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $todo_token = shift @{$tokens;})) 24 0 24
489 24 ▶ last if $todo_token->type eq 'TableStart';
Branch: 1 branch
BranchTrueFalseTotal
if $todo_token->type eq "TableStart" 0 24 24
490  
491 # Don't cross linebreak boundries
492 24 ▶ if ( $todo_token->type eq 'LineBreak' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($todo_token->type eq "LineBreak") 6 18 24
493 6 unshift @{$tokens}, $todo_token;
494 6 last;
495 }
496  
497 18 push @todo, $todo_token;
498 }
499  
500 # Process the children with _parse_paragraph.
501 6 ▶ if ( $is_first_row ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_first_row) { } 3 3 6
502 3 push @tree, {
503 class => 'Markdown::Compiler::Parser::Node::Table::Row',
504 content => $token->content,
505 # tokens => [ $token ],
506 children => [ $self->_parse_table_header_row( \@todo ) ],
507 };
508 3 $is_first_row = 0;
509 } else {
510 3 push @tree, {
511 class => 'Markdown::Compiler::Parser::Node::Table::Row',
512 content => $token->content,
513 # tokens => [ $token ],
514 children => [ $self->_parse_table_row( \@todo ) ],
515 };
516 }
517 6 next;
518 }
519 }
520 0 return @tree;
521 }
522  
523 0 ▶sub _parse_table_2 {
Subroutine _parse_table_2: not called CC=1 SCAR=6.9
524 0 my ( $self, $tokens ) = @_;
525 # Token Types:
526 # package Markdown::Compiler::Lexer;
527 # package Markdown::Compiler::Lexer::Token;
528 # package Markdown::Compiler::Lexer::Token::EscapedChar;
529 # package Markdown::Compiler::Lexer::Token::CodeBlock;
530 # package Markdown::Compiler::Lexer::Token::HR;
531 # package Markdown::Compiler::Lexer::Token::Image;
532 # package Markdown::Compiler::Lexer::Token::Link;
533 # package Markdown::Compiler::Lexer::Token::Item;
534 # package Markdown::Compiler::Lexer::Token::TableStart;
535 # package Markdown::Compiler::Lexer::Token::TableHeaderSep;
536 # package Markdown::Compiler::Lexer::Token::BlockQuote;
537 # package Markdown::Compiler::Lexer::Token::Header;
538 # package Markdown::Compiler::Lexer::Token::Bold;
539 # package Markdown::Compiler::Lexer::Token::Italic;
540 # package Markdown::Compiler::Lexer::Token::BoldItalic;
541 # package Markdown::Compiler::Lexer::Token::BoldItalicMaker;
542 # package Markdown::Compiler::Lexer::Token::LineBreak;
543 # package Markdown::Compiler::Lexer::Token::Space;
544 # package Markdown::Compiler::Lexer::Token::Word;
545 # package Markdown::Compiler::Lexer::Token::Char;
546  
547 }
548  
549 1 ▶sub _parse_blockquote {
Subroutine _parse_blockquote: called CC=6 SCAR=18.1
550 1 my ( $self, $tokens ) = @_;
551  
552 1 my @tree;
553  
554 1 ▶ while ( defined ( my $token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = shift @{$tokens;})) 7 0 7
555 # Exit Conditions:
556 #
557 # - Line break and no more tokens (after while loop)
558 # - Line break, and another line break.
559 7 ▶ if ( $token->type eq 'LineBreak' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "LineBreak") 2 5 7
560 2 ▶ return @tree unless @$tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless @$tokens 1 1 2
561 1 ▶ return @tree if $tokens->[0]->type eq 'LineBreak';
Branch: 1 branch
BranchTrueFalseTotal
if $tokens->[0]->type eq "LineBreak" 0 1 1
562 }
563  
564 6 ▶ next if $token->type eq 'BlockQuote';
Branch: 1 branch
BranchTrueFalseTotal
if $token->type eq "BlockQuote" 1 5 6
565  
566 5 push @tree, {
567 class => 'Markdown::Compiler::Parser::Node::BlockQuote::String',
568 content => $token->content,
569 # tokens => [ $token ],
570 };
571 }
572 0 return @tree;
573 }
574  
575 2 ▶sub _parse_codeblock {
Subroutine _parse_codeblock: called CC=3 SCAR=11.1
576 2 my ( $self, $tokens ) = @_;
577  
578 2 my @tree;
579  
580 2 ▶ while ( defined ( my $token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = shift @{$tokens;})) 8 0 8
581 # Exit Conditions:
582 #
583 # - No more tokens (after while loop)
584 # - Run into the next CodeBlock token.
585 8 ▶ if ( $token->type eq 'CodeBlock' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "CodeBlock") 2 6 8
586 2 return @tree;
587 }
588
589 6 push @tree, {
590 class => 'Markdown::Compiler::Parser::Node::CodeBlock::String',
591 content => $token->content,
592 # tokens => [ $token ],
593 };
594 }
595 0 return @tree;
596 }
597  
598 # Lists are:
599 #
600 # Ordered ( Numbered )
601 # List Item (Paragraph-like Processing)
602 # New Line terminates (We'll ignore that space-carry-on bullshit for now)
603 # Match Order Preceeding (Spaces before Item), and go to next List Item OR return tree
604 #
605 # Unordered ( Bulleted)
606 #
607 #
608 # Functions:
609 #
610 # _parse_list_unordered( $offset_for_next_match, $tokens )
611 # _parse_list_ordered( $offset_for_next_match, $tokens )
612 # _parse_list_item( $tokens )
613 #
614 #
615 #
616  
617 13 ▶sub _parse_list_item {
Subroutine _parse_list_item: called CC=4 SCAR=13.9
618 13 my ( $self, $tokens ) = @_;
619  
620 13 my @tree;
621  
622 13 ▶ while ( defined ( my $token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = shift @{$tokens;})) 25 1 26
623 # Exit Conditions:
624 #
625 # - No more tokens (after while loop)
626 # - Run into the next CodeBlock token.
627 25 ▶ if ( $token->type eq 'LineBreak' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "LineBreak") 12 13 25
628 12 return @tree;
629 }
630  
631 # Handle links in list
632 13 ▶ if ( $token->type eq 'Link' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "Link") 1 12 13
633 1 push @tree, {
634 class => 'Markdown::Compiler::Parser::Node::Paragraph::Link',
635 text => $token->text,
636 title => $token->title,
637 href => $token->href,
638 # tokens => [ $token ],
639 };
640 1 next;
641 }
642  
643 12 push @tree, {
644 class => 'Markdown::Compiler::Parser::Node::List::Item::String',
645 content => $token->content,
646 # tokens => [ $token ],
647 };
648 }
649  
650 1 return @tree;
651 }
652  
653 1 ▶sub _parse_list_ordered {
Subroutine _parse_list_ordered: called CC=14 SCAR=47.3
654 1 my ( $self, $lvl, $tokens ) = @_;
655  
656 1 my @tree;
657  
658 1 ▶ while ( defined ( my $token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = shift @{$tokens;})) 4 1 5
659 # Exit Conditions.
660 #
661 # If we hit any linebreak we go back to _parse_list to handle it.
662 4 ▶ if ( $token->type eq 'LineBreak' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($token->type eq 'LineBreak') { } 0 4 4
elsif ($lvl == 0 and $token->type eq 'Item') { } 4 0 4
elsif ($token->type eq 'Item') { } 0 0 0
elsif ($token->type eq 'Space') { } 0 0 0
663 0 unshift @{$tokens}, $token;
664 0 return @tree;
665  
666 }
667  
668 # Handle the next item ( root level )
669 ▶ elsif ( $lvl == 0 and $token->type eq 'Item' ) {
Condition33%1/3
$lvl == 0 and $token->type eq "Item"
!ll&&!rl&&r
004
MC/DC0%0/2
$lvl == 0 and $token->type eq "Item"
$lvl == 0 $token->type eq "Item"
Truth table33%1/3
A and B
A= $lvl == 0B= $token->type eq "Item"
ABresult
0X0
100
111
670 4 push @tree, {
671 class => 'Markdown::Compiler::Parser::Node::List::Ordered::Item',
672 # tokens => [ $token ],
673 children => [ $self->_parse_list_item( $tokens ) ],
674 };
675 4 next;
676 }
677  
678 # Transitioning from level 1 to 0 doesn't use the space method below,
679 # it uses this one here.
680 elsif ( $token->type eq 'Item' ) {
681 # Put the space/item token back, return our tree.
682 0 unshift @{$tokens}, $token;
683 0 return @tree;
684 }
685  
686 # Handle Space
687 elsif ( $token->type eq 'Space' ) {
688 # warn "After this space token is a " . $tokens->[0]->type . " with " . $tokens->[0]->content . " content\n";
689 # Case: This is the ordering level for this invocation, stay in this list.
690 0 ▶ if ( $token->length == $lvl ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token->length == $lvl) { } 0 0 0
elsif ($token->length < $lvl or $token->type eq 'Item') { } 0 0 0
elsif ($token->length > $lvl) { } 0 0 0
691 0 $token = shift @{$tokens};
692 0 ▶ if ( $token->type eq 'Word' ) { # Golden, correct stay-in-list level
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "Word") 0 0 0
693 0 $token = shift @{$tokens}
694 0 ▶ if $tokens->[0]->{type} eq 'Space'; # The space before the Item
Branch: 1 branch
BranchTrueFalseTotal
if $tokens->[0]{"type"} eq "Space" 0 0 0
695 0 push @tree, {
696 class => 'Markdown::Compiler::Parser::Node::List::Ordered::Item',
697 # tokens => [ $token ],
698 children => [ $self->_parse_list_item( $tokens ) ],
699 };
700 0 next;
701 }
702 0 die "Error: It shouldn't have gotten here, we're fucked";
703 }
704  
705 # Case: This list is now complete, the next request was for the next parent item.
706 ▶ elsif ( $token->length < $lvl or $token->type eq 'Item' ) {
Condition0%0/3
$token->length < $lvl or $token->type eq "Item"
l!l&&r!l&&!r
000
MC/DC0%0/2
$token->length < $lvl or $token->type eq "Item"
$token->length < $lvl $token->type eq "Item"
Truth table0%0/3
A or B
A= $token->length < $lvlB= $token->type eq "Item"
ABresult
1X1
011
000
707 # Put the space/item token back, return our tree.
708 0 unshift @{$tokens}, $token;
709 0 return @tree;
710 }
711  
712  
713 # Case: This is a new list, existing under the last Item
714 elsif ( $token->length > $lvl ) {
715 0 ▶ if ( $token->content =~ /^\d+\.\s+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->content =~ /^\d+\.\s+$/) { } 0 0 0
716 0 unshift @{$tokens}, $token;
717 0 push @tree, {
718 class => 'Markdown::Compiler::Parser::Node::List::Ordered',
719 # tokens => [ ],
720 children => [ $self->_parse_list_ordered( $token->length, $tokens ) ]
721 };
722 0 next;
723 } else {
724 0 unshift @{$tokens}, $token;
725 push @tree, {
726 class => 'Markdown::Compiler::Parser::Node::List::Unordered',
727 # tokens => [ ],
728 0 children => [ $self->_parse_list_unordered( $token->{length}, $tokens ) ]
729 };
730 0 next;
731 }
732 }
733  
734 else {
735 0 die "Parser::_parse_list_unordered() could not handle token " . $token->type;
736 }
737  
738 }
739 }
740 1 return @tree;
741 }
742  
743 4 ▶sub _parse_list_unordered {
Subroutine _parse_list_unordered: called CC=14 SCAR=30.4
744 4 my ( $self, $lvl, $tokens ) = @_;
745  
746 4 my @tree;
747  
748 4 ▶ while ( defined ( my $token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = shift @{$tokens;})) 11 3 14
749 # Exit Conditions.
750 #
751 # If we hit any linebreak we go back to _parse_list to handle it.
752 11 ▶ if ( $token->type eq 'LineBreak' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($token->type eq 'LineBreak') { } 0 11 11
elsif ($lvl == 0 and $token->type eq 'Item') { } 8 3 11
elsif ($token->type eq 'Item') { } 1 2 3
elsif ($token->type eq 'Space') { } 2 0 2
753 0 unshift @{$tokens}, $token;
754 0 return @tree;
755  
756 }
757  
758 # Handle the next item ( root level )
759 ▶ elsif ( $lvl == 0 and $token->type eq 'Item' ) {
Condition100%3/3
$lvl == 0 and $token->type eq "Item"
!ll&&!rl&&r
218
MC/DC100%2/2
$lvl == 0 and $token->type eq "Item"
$lvl == 0 $token->type eq "Item"
Truth table100%3/3
A and B
A= $lvl == 0B= $token->type eq "Item"
ABresult
0X0
100
111
760 8 push @tree, {
761 class => 'Markdown::Compiler::Parser::Node::List::Unordered::Item',
762 # tokens => [ $token ],
763 children => [ $self->_parse_list_item( $tokens ) ],
764 };
765 8 next;
766 }
767  
768 # Transitioning from level 1 to 0 doesn't use the space method below,
769 # it uses this one here.
770 elsif ( $token->type eq 'Item' ) {
771 # Put the space/item token back, return our tree.
772 1 unshift @{$tokens}, $token;
773 1 return @tree;
774 }
775  
776 # Handle Space
777 elsif ( $token->type eq 'Space' ) {
778 # warn "After this space token is a " . $tokens->[0]->type . " with " . $tokens->[0]->content . " content\n";
779 # Case: This is the ordering level for this invocation, stay in this list.
780 2 ▶ if ( $token->length == $lvl ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token->length == $lvl) { } 1 1 2
elsif ($token->length < $lvl or $token->type eq 'Item') { } 0 1 1
elsif ($token->length > $lvl) { } 1 0 1
781 1 $token = shift @{$tokens};
782 1 ▶ if ( $token->type eq 'Char' ) { # Golden, correct stay-in-list level
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "Char") 1 0 1
783 1 ▶ $token = shift @{$tokens}
Branch: 1 branch
BranchTrueFalseTotal
if $tokens->[0]->type eq "Space" 1 0 1
784 if $tokens->[0]->type eq 'Space'; # The space before the Item
785 1 push @tree, {
786 class => 'Markdown::Compiler::Parser::Node::List::Unordered::Item',
787 # tokens => [ $token ],
788 children => [ $self->_parse_list_item( $tokens ) ],
789 };
790 1 next;
791 }
792 0 die "Error: It shouldn't have gotten here, we're fucked";
793 }
794  
795 # Case: This list is now complete, the next request was for the next parent item.
796 ▶ elsif ( $token->length < $lvl or $token->type eq 'Item' ) {
Condition33%1/3
$token->length < $lvl or $token->type eq "Item"
l!l&&r!l&&!r
001
MC/DC0%0/2
$token->length < $lvl or $token->type eq "Item"
$token->length < $lvl $token->type eq "Item"
Truth table33%1/3
A or B
A= $token->length < $lvlB= $token->type eq "Item"
ABresult
1X1
011
000
797 # Put the space/item token back, return our tree.
798 0 unshift @{$tokens}, $token;
799 0 return @tree;
800 }
801  
802 # Case: This is a new list, existing under the last Item
803 elsif ( $token->length > $lvl ) {
804 1 ▶ if ( $token->content =~ /^\d+\.\s+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->content =~ /^\d+\.\s+$/) { } 0 1 1
805 0 unshift @{$tokens}, $token;
806 0 push @tree, {
807 class => 'Markdown::Compiler::Parser::Node::List::Ordered',
808 # tokens => [ ],
809 children => [ $self->_parse_list_ordered( $token->length, $tokens ) ]
810 };
811 0 next;
812 } else {
813 1 unshift @{$tokens}, $token;
814 1 push @tree, {
815 class => 'Markdown::Compiler::Parser::Node::List::Unordered',
816 # tokens => [ ],
817 children => [ $self->_parse_list_unordered( $token->length, $tokens ) ]
818 };
819 1 next;
820 }
821 }
822  
823  
824 else {
825 0 die "Parser::_parse_list_unordered() could not handle token " . $token->type;
826 }
827  
828 }
829 }
830 3 return @tree;
831 }
832  
833 4 ▶sub _parse_list {
Subroutine _parse_list: called CC=8 SCAR=24.3
834 4 my ( $self, $tokens ) = @_;
835  
836 4 my @tree;
837  
838 4 ▶ while ( defined ( my $token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = shift @{$tokens;})) 4 4 8
839 # Exit Conditions:
840 #
841 # - No more tokens (after while loop)
842 # - Two new line tokens in a rwo (first one is eaten)
843 4 ▶ if ( $token->type eq 'LineBreak' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "LineBreak") 0 4 4
844 0 ▶ if ( exists $tokens->[0] and $tokens->[0]->type eq 'LineBreak' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tokens->[0] and $tokens->[0]->type eq "LineBreak") 0 0 0
Condition0%0/3
exists $tokens->[0] and $tokens->[0]->type eq "LineBreak"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $tokens->[0] and $tokens->[0]->type eq "LineBreak"
exists $tokens->[0] $tokens->[0]->type eq "LineBreak"
Truth table0%0/3
A and B
A= exists $tokens->[0]B= $tokens->[0]->type eq "LineBreak"
ABresult
0X0
100
111
845 # Double Line Break, Bail Out
846 0 warn "See the bail out condition.... in _parse_list\n";
847 0 return @tree;
848 }
849 # Single Line Break - Ignore
850 0 next;
851 }
852 # Exit Conditions Continued:
853 #
854 # - Tokens which are invalid in this context, put the token back and return our @ree
855 4 ▶ if ( grep { $token->type eq $_ } (qw(Char Word TableStart CodeBlock BlockQuote List HR Header)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$token->type eq $_;} "Char", "Word", "TableStart", "CodeBlock", "BlockQuote", "List", "HR", "Header") 0 4 4
856 0 unshift @$tokens, $token;
857 0 return @tree;
858 }
859
860 4 ▶ if ( $token->type eq 'Item' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "Item") 4 0 4
861 4 ▶ if ( $token->content =~ /^\d+\.\s+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->content =~ /^\d+\.\s+$/) { } 1 3 4
862 1 unshift @{$tokens}, $token;
863 1 push @tree, {
864 class => 'Markdown::Compiler::Parser::Node::List::Ordered',
865 # tokens => [ ],
866 children => [ $self->_parse_list_ordered( 0, $tokens ) ]
867 };
868 1 next;
869 } else {
870 3 unshift @{$tokens}, $token;
871 3 push @tree, {
872 class => 'Markdown::Compiler::Parser::Node::List::Unordered',
873 # tokens => [ ],
874 children => [ $self->_parse_list_unordered( 0, $tokens ) ]
875 };
876 3 next;
877 }
878 }
879
880 0 die "Parser::_parse_list() could not handle token " . $token->type;
881  
882 }
883 4 return @tree;
884  
885 # Token Types:
886 # package Markdown::Compiler::Lexer;
887 # package Markdown::Compiler::Lexer::Token;
888 # package Markdown::Compiler::Lexer::Token::EscapedChar;
889 # package Markdown::Compiler::Lexer::Token::CodeBlock;
890 # package Markdown::Compiler::Lexer::Token::HR;
891 # package Markdown::Compiler::Lexer::Token::Image;
892 # package Markdown::Compiler::Lexer::Token::Link;
893 # package Markdown::Compiler::Lexer::Token::Item;
894 # package Markdown::Compiler::Lexer::Token::TableStart;
895 # package Markdown::Compiler::Lexer::Token::TableHeaderSep;
896 # package Markdown::Compiler::Lexer::Token::BlockQuote;
897 # package Markdown::Compiler::Lexer::Token::Header;
898 # package Markdown::Compiler::Lexer::Token::Bold;
899 # package Markdown::Compiler::Lexer::Token::Italic;
900 # package Markdown::Compiler::Lexer::Token::BoldItalic;
901 # package Markdown::Compiler::Lexer::Token::BoldItalicMaker;
902 # package Markdown::Compiler::Lexer::Token::LineBreak;
903 # package Markdown::Compiler::Lexer::Token::Space;
904 # package Markdown::Compiler::Lexer::Token::Word;
905 # package Markdown::Compiler::Lexer::Token::Char;
906 }
907  
908 0 ▶sub _parse_metadata {
Subroutine _parse_metadata: not called CC=4 SCAR=30.0
909 0 my ( $self, $tokens ) = @_;
910  
911 0 my @tree;
912  
913 0 ▶ while ( defined ( my $token = shift @{ $tokens } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = shift @{$tokens;})) 0 0 0
914 # Exit Conditions:
915 #
916 # - We run into the HR block.
917 0 ▶ if ( $token->type eq 'HR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->type eq "HR") 0 0 0
918 0 last;
919 }
920  
921 0 ▶ if ( grep { $token->type eq $_ } ( qw( EscapedChar Space Word Char LineBreak ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$token->type eq $_;} "EscapedChar", "Space", "Word", "Char", "LineBreak") 0 0 0
922 0 push @tree, $token;
923 0 next;
924 }
925  
926 0 die "Parser::_parse_metadata() could not handle token " . $token->type;
927 }
928  
929  
930 0 my $content = join "", map { $_->content } @tree;
931  
932 0 require YAML::XS;
933 0 my $struct = YAML::XS::Load( $content );
934  
935  
936 return {
937 0 content => $content,
938 tokens => [ @tree ],
939 data => $struct,
940 };
941 }
942  
943 0 ▶sub show_tree {
Subroutine show_tree: not called CC=1 SCAR=6.9
Pod undocumented
944 0 my ( $self ) = @_;
945  
946 0 print $self->_pretty_print(0, $self->tree);
947 }
948  
949 0 ▶sub _pretty_print {
Subroutine _pretty_print: not called CC=4 SCAR=30.0
950 0 my ( $self, $index, $tokens ) = @_;
951  
952 0 ▶ $index ||= 0;
Condition0%0/2
$index ||= 0
l!l
00
MC/DC0%0/1
$index ||= 0
$index
Truth table0%0/2
A
A= $index
Aresult
11
00
953 0 my $str;
954  
955 0 foreach my $token ( @{$tokens} ) {
956  
957 0 my $tab = " " x ( $index x 2 );
958  
959 0 my $class = ref($token);
960 0 $class =~ s|Markdown::Compiler::Parser::Node::||;
961  
962 0 my $content = join "", map { $_->content } (@{$token->tokens});
963 0 $content =~ s/\n/\\n/g;
964 0 $content =~ s/\r/\\n/g;
965  
966 0 $str .=
967 " " x ( $index * 2 ) .
968 sprintf( '%-' . (35 - ($index * 2)) . 's', $class ) .
969 "| $content\n";
970  
971 0 ▶ $str .= $self->_pretty_print( $index + 1, $token->children )
Branch: 1 branch
BranchTrueFalseTotal
if $token->children 0 0 0
972 if $token->children;
973 }
974 0 return $str;
975 }
976  
977  
978  
979  
980 18 1;
↑ Summary Compiler/Target/Tree.pm »