Fu/Color.pm

filter: Statementstmt 62.5% 30 / 48 Branchbran 16.6% 2 / 12 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 1 totaltotal 51.2% 41 / 80 CC 9 SCAR 25.2
CC
9
Cov
50%
fu_colorize
30.0
BEGIN
10.9
BEGIN
1.0
CRAP 12.5
« Fu/Chomp.pm ↑ Summary Fu.pm »
1 package Log::Fu::Color;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Log::Fu::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Log::Fu::Common qw(:levels);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 our @EXPORT = qw(fu_colorize);
8  
9 5 our $USE_COLOR = 1;
10  
11 5 ▶BEGIN {
Subroutine BEGIN: called CC=5 SCAR=23.9
12 5 ▶ if ($ENV{LOG_FU_NO_COLOR} || $ENV{ANSI_COLORS_DISABLED}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'LOG_FU_NO_COLOR'} or $ENV{'ANSI_COLORS_DISABLED'}) { } 0 5 5
Condition33%1/3
$ENV{"LOG_FU_NO_COLOR"} or $ENV{"ANSI_COLORS_DISABLED"}
l!l&&r!l&&!r
005
MC/DC0%0/2
$ENV{"LOG_FU_NO_COLOR"} or $ENV{"ANSI_COLORS_DISABLED"}
$ENV{"LOG_FU_NO_COLOR"} $ENV{"ANSI_COLORS_DISABLED"}
Truth table33%1/3
A or B
A= $ENV{"LOG_FU_NO_COLOR"}B= $ENV{"ANSI_COLORS_DISABLED"}
ABresult
1X1
011
000
13 0 $USE_COLOR = 0;
14 } else {
15 5 eval {
16 5 require Term::Terminfo;
17 0 Term::Terminfo->import();
18 0 my $ti = Term::Terminfo->new();
19 0 my $n_colors = $ti->getnum("colors");
20 0 ▶ if ($n_colors < 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n_colors < 8) 0 0 0
21 #Color logging disabled:
22 0 die "Must have >= 16 colors!";
23 }
24 };
25 5 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 5 0 5
26 5 $USE_COLOR = 0;
27 } else {
28 0 $USE_COLOR = 1;
29 }
30 }
31 }
32 5 my %COLORS = (
33 YELLOW => 3,
34 WHITE => 7,
35 MAGENTA => 5,
36 CYAN => 6,
37 BLUE => 4,
38 GREEN => 2,
39 RED => 1,
40 BLACK => 0,
41 );
42  
43 5 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
44 5 COLOR_FG => 3,
45 COLOR_BG => 4,
46 COLOR_BRIGHT_FG => 1,
47 COLOR_INTENSE_FG=> 9,
48 COLOR_DIM_FG => 2
49 5 };
50 5 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
51 5 COLOR_RESET => "\33[0m"
52 5 };
53  
54  
55 0 ▶sub fu_colorize {
Subroutine fu_colorize: not called CC=5 SCAR=34.0
Pod undocumented
56 0 my ($level_number,$message) = @_;
57 0 my $fmt_begin = "\033[";
58 0 my $fmt_end = COLOR_RESET;
59 0 ▶ if ($level_number == LOG_ERR || $level_number == LOG_CRIT) {
Branch: 3 branches
BranchTrueFalseTotal
if ($level_number == 3 or $level_number == 4) { } 0 0 0
elsif ($level_number == 2) { } 0 0 0
elsif ($level_number == 0) { } 0 0 0
Condition0%0/3
$level_number == 3 or $level_number == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$level_number == 3 or $level_number == 4
$level_number == 3 $level_number == 4
Truth table0%0/3
A or B
A= $level_number == 3B= $level_number == 4
ABresult
1X1
011
000
60 0 $fmt_begin .= sprintf("%s;%s%sm", COLOR_BRIGHT_FG, COLOR_FG, $COLORS{RED});
61 } elsif ($level_number == LOG_WARN) {
62 0 $fmt_begin .= sprintf("%s%sm", COLOR_FG, $COLORS{YELLOW});
63 } elsif ($level_number == LOG_DEBUG) {
64 0 $fmt_begin .= sprintf("%s;%s%sm", COLOR_DIM_FG, COLOR_FG, $COLORS{WHITE});
65 } else {
66 0 $fmt_begin = "";
67 0 $fmt_end = "";
68 }
69 0 $message = $fmt_begin . $message . $fmt_end;
70 0 return $message;
71 }
72  
73 5 1;
« Fu/Chomp.pm ↑ Summary Fu.pm »