Term/ANSIColorx/ColorNicknames.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 12 / 12 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 4 / 4 totaltotal 100% 77 / 77 SCAR 22.0
CC
9
Cov
100%
fix_color
8.0
colored
2.0
BEGIN
1.0
CRAP 9.0
« Term/ANSIColorx/AutoFilterFH.pm ↑ Summary
1  
2 package Term::ANSIColorx::ColorNicknames;
3  
4 10 ▶use Term::ANSIColor qw(colorstrip uncolor);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 our $VERSION = '2.7191_2';
9  
10 10 our @FIXED = qw(color colorvalid colored);
11 10 our @EXPORT_OK = qw(fix_color color colorvalid colored colorstrip uncolor);
12 10 our %EXPORT_TAGS = ( all => \@EXPORT_OK, fixed=>\@FIXED );
13  
14 10 our %NICKNAMES = (
15 normal => "clear",
16 unbold => "clear",
17  
18 blood => "red",
19 umber => "bold red",
20 sky => "bold blue",
21 ocean => "cyan",
22 lightblue => "cyan",
23 cyan => "bold cyan",
24 lime => "bold green",
25 orange => "yellow",
26 brown => "yellow",
27 yellow => "bold yellow",
28 purple => "magenta",
29 violet => "bold magenta",
30 pink => "bold magenta",
31 pitch => "bold black",
32 coal => "bold black",
33 grey => "white",
34 gray => "white",
35 white => "bold white",
36  
37 dire => "bold yellow on_red",
38 alert => "bold yellow on_red",
39 todo => "black on_yellow",
40  
41 nc_dir => "bold white on_blue",
42 nc_file => "bold white on_blue",
43 nc_exe => "bold green on_blue",
44 nc_exec => "bold green on_blue",
45 nc_curs => "black on_cyan",
46 nc_pwd => "black on_white",
47 nc_cwd => "black on_white",
48  
49 mc_dir => "bold white on_blue",
50 mc_file => "bold white on_blue",
51 mc_exe => "bold green on_blue",
52 mc_exec => "bold green on_blue",
53 mc_curs => "black on_cyan",
54 mc_pwd => "black on_white",
55 mc_cwd => "black on_white",
56 );
57  
58 sub fix_color(_) {
59 55 ▶ my $color = shift;
Subroutine fix_color: called CC=8 SCAR=20.8
Pod documented
60 55 my $no_nick = $color =~ s/\a//g;
61  
62 55 $color =~ s/[^\w]/ /g;
63 55 $color =~ s/on (\w+)/on_$1/g;
64 55 $color =~ s/un bold/unbold/g;
65 55 $color =~ s/([mn]c) (dir|file|exec?|curs|[pc]wd)/$1_$2/g;
66  
67 my @cl = map {
68 55 (!$no_nick && exists $NICKNAMES{$_})
69 85 ▶ ? split(" ", $NICKNAMES{$_}) : $_
Branch: 1 branch
BranchTrueFalseTotal
!$no_nick && exists $Term::ANSIColorx::ColorNicknames::NICKNAMES{$_} ? : 29 56 85
Condition100%3/3
not $no_nick and exists $Term::ANSIColorx::ColorNicknames::NICKNAMES{$_}
!ll&&!rl&&r
15529
MC/DC100%2/2
not $no_nick and exists $Term::ANSIColorx::ColorNicknames::NICKNAMES{$_}
not $no_nick exists $Term::ANSIColorx::ColorNicknames::NICKNAMES{$_}
Truth table100%3/3
not(A) and B
A= not $no_nickB= exists $Term::ANSIColorx::ColorNicknames::NICKNAMES{$_}
ABresult
0X0
100
111
70 } split(" ", $color);
71  
72 FIXCL: {
73 55 my %m = (faint=>1, dark=>1, bold=>1, bright=>1, clear=>1);
74 62 for my $i (0 .. $#cl) {
75 93 ▶ if( $m{$cl[$i]} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m{$cl[$i]}) 29 64 93
76 29 my $l = 1;
77  
78 29 ▶ $l ++ while $m{$cl[ $i+$l ]};
Branch: 1 branch
BranchTrueFalseTotal
$m{$cl[$i + $l]} and do { ++$l } 18 29 47
79  
80 29 ▶ if( $l > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l > 1) 7 22 29
81 7 splice @cl, $i, $l, $cl[$i];
82 7 redo FIXCL;
83 }
84 }
85 }
86 }
87  
88 55 ▶ $color = join " ", @cl>1 ? grep {$_ ne "clear"} @cl : @cl;
Branch: 1 branch
BranchTrueFalseTotal
@cl > 1 ? : 25 30 55
89  
90 55 return $color;
91 }
92  
93 sub color(_) {
94 35 ▶ @_ = (fix_color $_[0]);
Subroutine color: called CC=1 SCAR=0.0
Pod documented
95 35 goto &Term::ANSIColor::color;
96 }
97  
98 sub colorvalid(_) {
99 13 ▶ @_ = (fix_color $_[0]);
Subroutine colorvalid: called CC=1 SCAR=0.0
Pod documented
100 13 goto &Term::ANSIColor::colorvalid;
101 }
102  
103 sub colored {
104 3 ▶ my ($string, @codes);
Subroutine colored: called CC=2 SCAR=6.9
Pod documented
105  
106 3 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 1 2 3
107 1 @codes = @{+shift};
108 1 $string = join ('', @_);
109  
110 } else {
111 2 $string = shift;
112 2 @codes = @_;
113 }
114  
115 3 @_ = ($string, map {fix_color} @codes);
116 3 goto &Term::ANSIColor::colored;
117 }
118  
119 10 "true";
120  
121 __END__
« Term/ANSIColorx/AutoFilterFH.pm ↑ Summary