Highlight/Block/embedz.pm

filter: Statementstmt 100% 38 / 38 Branchbran 100% 24 / 24 Conditioncond 90.0% 18 / 20 MC/DCmcdc 84.6% 11 / 13 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 96.0% 97 / 101 CC 20 SCAR 27.3
CC
20
Cov
98%
parts
19.0
_data
2.0
BEGIN
1.0
CRAP 15.3
« Highlight/pandoc.pm ↑ Summary Highlight/skylighting.pm »
1 package Text::ANSI::Highlight::Block::embedz;
2  
3 1 ▶use v5.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # The parts of a block of pandoc-embedz, each with its language:
8 #
9 # ---
10 # YAML
11 # ---
12 # template of Jinja2
13 # ---
14 # data
15 #
16 # A block without the line of --- at the top is one part, and what it
17 # is depends on the attributes of the fence.
18  
19 # the formats of the data which are the names of a language. CSV is
20 # not here: its colors, one for each column, mean nothing in the data
21 1 my %FORMAT = map { $_ => $_ } qw(json yaml toml);
22  
23 19 ▶sub parts {
Subroutine parts: called CC=19 SCAR=29.4
Pod documented
24 19 my($info, $text) = @_;
25 19 ▶ $text ne '' or return ();
Branch: 1 branch
BranchTrueFalseTotal
$text ne "" or return () 18 1 19
26 18 my %attr = map { $_ => 1 } $info =~ /(?<![\w.])([\w.-]+)=/g;
27 18 ▶ my $format = $info =~ /(?<![\w.])format=["']?(\w+)/ ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$info =~ /(?<![\w.])format=["']?(\w+)/u ? : 3 15 18
28 18 ▶ my $as = $attr{as} || $attr{template};
Condition100%3/3
$attr{'as'} || $attr{'template'}
l!l&&r!l&&!r
5112
MC/DC100%2/2
$attr{'as'} || $attr{'template'}
$attr{'as'} $attr{'template'}
Truth table100%3/3
A || B
A= $attr{'as'}B= $attr{'template'}
ABresult
1X1
011
000
29  
30 18 ▶ if ($text !~ /\A---/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($text =~ /\A---/u) 9 9 18
31 9 ▶ return [ jinja => $text, 'template' ] if $attr{define};
Branch: 1 branch
BranchTrueFalseTotal
if $attr{"define"} 1 8 9
32 8 ▶ return [ yaml => $text, 'config' ] if $as and $attr{data};
Branch: 1 branch
BranchTrueFalseTotal
if $as and $attr{"data"} 2 6 8
Condition100%3/3
$as and $attr{"data"}
!ll&&!rl&&r
332
MC/DC100%2/2
$as and $attr{"data"}
$as $attr{"data"}
Truth table100%3/3
A and B
A= $asB= $attr{"data"}
ABresult
0X0
100
111
33 6 ▶ return [ _data($format) => $text, 'data' ] if $as;
Branch: 1 branch
BranchTrueFalseTotal
if $as 3 3 6
34 3 return [ jinja => $text, 'template' ];
35 }
36  
37 # the lines of --- and the sections between them: the third and
38 # the following are in the data
39 9 my @line = split /^/, $text;
40 9 my @part = ([ undef, shift @line ]);
41 9 my @section = ('');
42 9 ▶ while (defined(my $line = shift @line)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = shift @line)) 55 9 64
43 55 ▶ if (@section < 5 and $line =~ /\A\h*---\h*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@section < 5 and $line =~ /\A\h*---\h*$/u) { } 13 42 55
Condition100%3/3
@section < 5 and $line =~ /\A\h*---\h*$/u
!ll&&!rl&&r
73513
MC/DC100%2/2
@section < 5 and $line =~ /\A\h*---\h*$/u
@section < 5 $line =~ /\A\h*---\h*$/u
Truth table100%3/3
A and B
A= @section < 5B= $line =~ /\A\h*---\h*$/u
ABresult
0X0
100
111
44 13 push @section, $line, '';
45 } else {
46 42 $section[-1] .= $line;
47 }
48 }
49 9 my($yaml, $sep1, $template, $sep2, $data) = @section;
50 9 ▶ $format //= $1 if $yaml =~ /^format:\h*["']?(\w+)/m;
Branch: 1 branch
BranchTrueFalseTotal
if $yaml =~ /^format:\h*["']?(\w+)/mu 2 7 9
Condition33%1/3
$format //= $1
l!l&&r!l&&!r
020
MC/DC0%0/2
$format //= $1
$format $1
Truth table33%1/3
A //= B
A= $formatB= $1
ABresult
1X1
011
000
51 9 ▶ $as ||= $yaml =~ /^(?:as|template):/m;
Condition100%3/3
$as ||= $yaml =~ /^(?:as|template):/mu
l!l&&r!l&&!r
117
MC/DC100%2/2
$as ||= $yaml =~ /^(?:as|template):/mu
$as $yaml =~ /^(?:as|template):/mu
Truth table100%3/3
A ||= B
A= $asB= $yaml =~ /^(?:as|template):/mu
ABresult
1X1
011
000
52 # the section after YAML is the data when a template is used
53 9 ▶ my @middle = ($as and not defined $sep2)
Branch: 1 branch
BranchTrueFalseTotal
$as && !defined($sep2) ? : 1 8 9
Condition100%3/3
$as and not defined $sep2
!ll&&!rl&&r
711
MC/DC100%2/2
$as and not defined $sep2
$as not defined $sep2
Truth table100%3/3
A and not(B)
A= $asB= not defined $sep2
ABresult
0X0
100
111
54 ? (_data($format), 'data') : ('jinja', 'template');
55 9 ▶ push @part,
Branch: 2 branches
BranchTrueFalseTotal
defined $sep1 ? : 8 1 9
defined $sep2 ? : 5 4 9
56 [ yaml => $yaml, 'config' ],
57 defined $sep1 ? ([ undef, $sep1 ], [ $middle[0], $template, $middle[1] ]) : (),
58 defined $sep2 ? ([ undef, $sep2 ], [ _data($format), $data, 'data' ]) : ();
59 9 grep { $_->[1] ne '' } @part;
60 }
61  
62 9 ▶sub _data {
Subroutine _data: called CC=2 SCAR=6.9
63 9 ▶ my $format = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
54
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
64 5 $FORMAT{lc $format};
65 }
66  
67 1 1;
68  
69 __END__
« Highlight/pandoc.pm ↑ Summary Highlight/skylighting.pm »