Highlight/sourcehighlight.pm

filter: Statementstmt 52.0% 13 / 25 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 4 totaltotal 24.6% 16 / 65 CC 9 SCAR 31.2
CC
9
Cov
29%
language
42.0
style_option
20.0
markdown
2.0
CRAP 22.6
« Highlight.pm ↑ Summary Highlight/pandoc.pm »
1 package Text::ANSI::Highlight::sourcehighlight;
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 Text::ANSI::Highlight ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # source-highlight of GNU. Its style esc is the colors that less
8 # shows by its lesspipe. The style and the language are given after
9 # it (--style-file and -s).
10 1 our @COMMAND = qw(source-highlight -f esc);
11  
12 # The style: the name of a style file of source-highlight without
13 # .style (esc, esc256, default), or a style file. Set by
14 # Text::ANSI::Highlight for a call.
15 1 our $STYLE;
16 1 our $DEFAULT_STYLE = 'esc';
17  
18 0 ▶sub style_option {
Subroutine style_option: not called CC=4 SCAR=30.0
Pod undocumented
19 0 ▶ my $style = $STYLE // $DEFAULT_STYLE;
Condition0%0/3
$Text::ANSI::Highlight::sourcehighlight::STYLE // $Text::ANSI::Highlight::sourcehighlight::DEFAULT_STYLE
l!l&&r!l&&!r
000
MC/DC0%0/2
$Text::ANSI::Highlight::sourcehighlight::STYLE // $Text::ANSI::Highlight::sourcehighlight::DEFAULT_STYLE
$Text::ANSI::Highlight::sourcehighlight::STYLE $Text::ANSI::Highlight::sourcehighlight::DEFAULT_STYLE
Truth table0%0/3
A // B
A= $Text::ANSI::Highlight::sourcehighlight::STYLEB= $Text::ANSI::Highlight::sourcehighlight::DEFAULT_STYLE
ABresult
1X1
011
000
20 0 ▶ $style .= '.style' unless $style =~ m{[/.]} or -f $style;
Branch: 1 branch
BranchTrueFalseTotal
unless $style =~ m[[/.]]u or -f $style 0 0 0
Condition0%0/3
$style =~ m[[/.]]u or -f $style
l!l&&r!l&&!r
000
MC/DC0%0/2
$style =~ m[[/.]]u or -f $style
$style =~ m[[/.]]u -f $style
Truth table0%0/3
A or B
A= $style =~ m[[/.]]uB= -f $style
ABresult
1X1
011
000
21 0 "--style-file=$style";
22 }
23  
24 # The languages, and the extensions of the files, that the command
25 # knows (source-highlight --lang-list)
26 1 my $language;
27  
28 0 ▶sub language {
Subroutine language: not called CC=6 SCAR=37.4
Pod undocumented
29 0 ▶ $language //= do {
Condition0%0/3
$language //= do { my $list = Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "") // ""; +{map({/^(\S+) = (\S+)\.lang$/u && $2 ne "nohilite" ? ($1, 1) : ();} split(/\n/u, $list, 0))} }
l!l&&r!l&&!r
000
MC/DC0%0/2
$language //= do { my $list = Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "") // ""; +{map({/^(\S+) = (\S+)\.lang$/u && $2 ne "nohilite" ? ($1, 1) : ();} split(/\n/u, $list, 0))} }
$language do { my $list = Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "") // ""; +{map({/^(\S+) = (\S+)\.lang$/u && $2 ne "nohilite" ? ($1, 1) : ();} split(/\n/u, $list, 0))} }
Truth table0%0/3
A //= B
A= $languageB= do { my $list = Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "") // ""; +{map({/^(\S+) = (\S+)\.lang$/u && $2 ne "nohilite" ? ($1, 1) : ();} split(/\n/u, $list, 0))} }
ABresult
1X1
011
000
30 0 ▶ my $list = Text::ANSI::Highlight::run([ $COMMAND[0], '--lang-list' ], '') // '';
Condition0%0/2
Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "") // ""
l!l
00
MC/DC0%0/1
Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "") // ""
Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "")
Truth table0%0/2
A
A= Text::ANSI::Highlight::run([$Text::ANSI::Highlight::sourcehighlight::COMMAND[0], "--lang-list"], "")
Aresult
11
00
31 0 ▶ +{ map { /^(\S+) = (\S+)\.lang$/ && $2 ne 'nohilite' ? ($1 => 1) : () } split /\n/, $list };
Branch: 1 branch
BranchTrueFalseTotal
/^(\S+) = (\S+)\.lang$/u && $2 ne 'nohilite' ? : 0 0 0
Condition0%0/3
/^(\S+) = (\S+)\.lang$/u and $2 ne "nohilite"
!ll&&!rl&&r
000
MC/DC0%0/2
/^(\S+) = (\S+)\.lang$/u and $2 ne "nohilite"
/^(\S+) = (\S+)\.lang$/u $2 ne "nohilite"
Truth table0%0/3
A and B
A= /^(\S+) = (\S+)\.lang$/uB= $2 ne "nohilite"
ABresult
0X0
100
111
32 };
33 0 ▶ $language->{$_[0]} ? $_[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$$language{$_[0]} ? : 0 0 0
34 }
35  
36 # It has no definition of Markdown: the text around the code of a
37 # Markdown text is left as it is.
38 0 ▶sub markdown { 0 }
Subroutine markdown: not called CC=1 SCAR=6.9
Pod undocumented
39  
40 # The command runs once for each text.
41 0 ▶sub highlight {
Subroutine highlight: not called CC=1 SCAR=6.9
Pod undocumented
42 map {
43 0 my($lang, $text) = @$_;
44 0 Text::ANSI::Highlight::run([ @COMMAND, style_option(), '-s', $lang ], $text);
45 } @_;
46 }
47  
48 1 1;
« Highlight.pm ↑ Summary Highlight/pandoc.pm »