blib/lib/IO/Factotum/Highlight/sourcehighlight.pm

filter: Statementstmt 64.2% 18 / 28 Branchbran 16.6% 2 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 3 totaltotal 43.1% 25 / 58 CC 9 SCAR 33.1
CC
9
Cov
44%
match
56.0
highlight
6.0
setup
2.0
CRAP 27.5
« blib/lib/IO/Factotum/Highlight/skylighting.pm ↑ Summary lib/IO/Factotum.pm »
1 package IO::Factotum::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  
6 1 ▶use IO::Factotum;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # --failsafe gives a file whose language is not known as it is, and
9 # --infer-lang tells the language of a script by its first line
10 1 our @COMMAND = qw(source-highlight --failsafe --infer-lang -f esc);
11  
12 # The colors: esc.style is the style of source-highlight for the
13 # terminal
14 1 our @STYLE = qw(--style-file=esc.style);
15  
16 # A file larger than this is left as it is, 0 for no limit
17 1 our $MAX_SIZE = 256 * 1024;
18  
19 # A file which has an escape character is left as it is, and so are
20 # an empty file and a large one.
21 0 ▶sub match {
Subroutine match: not called CC=7 SCAR=40.3
Pod undocumented
22 0 my $file = shift;
23 0 ▶ return 0 unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
24 0 ▶ my $size = -s _ or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $size = -s _ or return 0 0 0 0
25 0 ▶ return 0 if $MAX_SIZE and $size > $MAX_SIZE;
Branch: 1 branch
BranchTrueFalseTotal
if $IO::Factotum::Highlight::sourcehighlight::MAX_SIZE and $size > $IO::Factotum::Highlight::sourcehighlight::MAX_SIZE 0 0 0
Condition0%0/3
$IO::Factotum::Highlight::sourcehighlight::MAX_SIZE and $size > $IO::Factotum::Highlight::sourcehighlight::MAX_SIZE
!ll&&!rl&&r
000
MC/DC0%0/2
$IO::Factotum::Highlight::sourcehighlight::MAX_SIZE and $size > $IO::Factotum::Highlight::sourcehighlight::MAX_SIZE
$IO::Factotum::Highlight::sourcehighlight::MAX_SIZE $size > $IO::Factotum::Highlight::sourcehighlight::MAX_SIZE
Truth table0%0/3
A and B
A= $IO::Factotum::Highlight::sourcehighlight::MAX_SIZEB= $size > $IO::Factotum::Highlight::sourcehighlight::MAX_SIZE
ABresult
0X0
100
111
26 0 ▶ open my $fh, '<:raw', $file or return 0;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $file or return 0 0 0 0
27 0 local $/;
28 0 ▶ my $content = <$fh> // return 0;
Condition0%0/2
readline $fh // (return 0)
l!l
00
MC/DC0%0/1
readline $fh // (return 0)
readline $fh
Truth table0%0/2
A
A= readline $fh
Aresult
11
00
29 0 index($content, "\e") < 0;
30 }
31  
32 # This is called in a process of its own (IO::Factotum), which
33 # becomes that of source-highlight. When it fails, as with a style
34 # file which is not found, the file is read as it is.
35 0 ▶sub highlight {
Subroutine highlight: not called CC=2 SCAR=17.9
Pod undocumented
36 0 my $file = $_[-1];
37 0 ▶ exec @COMMAND, @STYLE, '-i', $file
Branch: 1 branch
BranchTrueFalseTotal
exec @IO::Factotum::Highlight::sourcehighlight::COMMAND, @IO::Factotum::Highlight::sourcehighlight::STYLE, "-i", $file or die "source-highlight: $!\n" 0 0 0
38 or die "source-highlight: $!\n";
39 }
40  
41 1 my $done;
42 2 ▶sub setup {
Subroutine setup: called CC=2 SCAR=6.9
Pod undocumented
43 2 ▶ return if $done++;
Branch: 1 branch
BranchTrueFalseTotal
if $done++ 1 1 2
44 1 IO::Factotum::register(match => \&match, command => [ \&highlight ]);
45 1 return;
46 }
47  
48 2 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
49 2 setup();
50 2 IO::Factotum::tie_argv();
51 }
52  
53 1 1;
54  
55 __END__
« blib/lib/IO/Factotum/Highlight/skylighting.pm ↑ Summary lib/IO/Factotum.pm »