| 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
| |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my $size = -s _ or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | return 0 if $MAX_SIZE and $size > $MAX_SIZE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$IO::Factotum::Highlight::sourcehighlight::MAX_SIZE and $size > $IO::Factotum::Highlight::sourcehighlight::MAX_SIZE
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
| |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | open my $fh, '<:raw', $file or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | local $/; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | my $content = <$fh> // return 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
readline $fh // (return 0)
MC/DC0%0/1
readline $fh // (return 0)
readline $fh
Truth table0%0/2
A
A= readline $fh
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||