TTY.pm

filter: Statementstmt 89.6% 26 / 29 Branchbran 50.0% 3 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 78.7% 37 / 47 SCAR 18.5
CC
6
Cov
79%
set_tty_color
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 6.3
↑ Summary TTY/Colorschemes.pm »
1 package Term::ExtendedColor::TTY;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 BEGIN {
5 3 ▶ use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶ use vars qw($VERSION @ISA @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶ $VERSION = '0.030';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 @ISA = qw(Exporter);
10  
11 3 @EXPORT_OK = qw(
12 set_tty_color
13 );
14 }
15 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 3 my %color_indexes = (
19 0 => 'P0', #black
20 1 => 'P8', # dark grey
21 2 => 'P1', # dark red
22 3 => 'P9', # red
23 4 => 'P2', # dark green
24 5 => 'PA', # green
25 6 => 'P3', # brown
26 7 => 'PB', # yellow
27 8 => 'P4', # darkblue
28 9 => 'PC', # blue
29 10 => 'P5', # dark magenta
30 11 => 'PD', # magenta
31 12 => 'P6', # dark cyan
32 13 => 'PE', # cyan
33 14 => 'P7', # dark white
34 15 => 'PF', # white
35 );
36  
37  
38 sub set_tty_color {
39 1 ▶ my $map = shift;
Subroutine set_tty_color: called CC=6 SCAR=20.8
Pod documented
40  
41 1 ▶ ref($map) eq 'HASH' or croak("set_tty_color() expects an hashref");
Branch: 1 branch
BranchTrueFalseTotal
ref $map eq "HASH" or croak("set_tty_color() expects an hashref") 0 1 1
42  
43 1 my %results;
44  
45 1 for my $index(sort{ $a <=> $b } keys(%{$map})) {
46 1 ▶ if( ($index < 0) or ($index > 15) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < 0 or $index > 15) 0 1 1
Condition33%1/3
$index < 0 or $index > 15
l!l&&r!l&&!r
001
MC/DC0%0/2
$index < 0 or $index > 15
$index < 0 $index > 15
Truth table33%1/3
A or B
A= $index < 0B= $index > 15
ABresult
1X1
011
000
47 0 croak("'$index': color index must be between 0 and 15, inclusive\n");
48 }
49 1 ▶ if($map->{$index} !~ m/^(?:[A-Za-z0-9]{6}$)/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($map->{$index} =~ /^(?:[A-Za-z0-9]{6}$)/) 0 1 1
50 0 croak(
51 "'$map->{$index}' is not a valid hexadecimal color representation\n"
52 );
53 }
54  
55 $results{$index} = sprintf("\e]%s",
56 $color_indexes{$index}
57 1 . $map->{$index}, #P0ffffff
58 );
59 }
60  
61 1 return \%results;
62 }
63  
64  
65 3 1;
66  
67  
68 __END__
↑ Summary TTY/Colorschemes.pm »