| 1 | package Getopt::EX::Colormap; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 11 | our $VERSION = "3.05"; | |||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 11 | our @EXPORT_OK = ( | |||||||||||||||||||||||||||||||||||||
| 10 | qw( colorize colorize24 ansi_code ansi_pair csi_code ), | ||||||||||||||||||||||||||||||||||||||
| 11 | qw( colortable colortable6 colortable12 colortable24 ), | ||||||||||||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||||||||||||
| 13 | 11 | our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); | |||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | 11 | $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||
| 19 | 11 | ▶ | use List::Util qw(min max first); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | 11 | ▶ | use parent 'Getopt::EX::LabeledParam'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 22 | 11 | ▶ | use Getopt::EX::Util; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 23 | 11 | ▶ | use Getopt::EX::Func qw(callable); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||
| 25 | 11 | ▶ | use Term::ANSIColor::Concise qw(:all); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||||||||||||
| 27 | 11 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 28 | 11 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 29 | 11 | *colorize = \&ansi_color; | |||||||||||||||||||||||||||||||||||||
| 30 | 11 | *colorize24 = \&ansi_color_24; | |||||||||||||||||||||||||||||||||||||
| 31 | 11 | for my $name ( | |||||||||||||||||||||||||||||||||||||
| 32 | qw( NO_NO_COLOR | ||||||||||||||||||||||||||||||||||||||
| 33 | NO_COLOR | ||||||||||||||||||||||||||||||||||||||
| 34 | RGB24 | ||||||||||||||||||||||||||||||||||||||
| 35 | LINEAR_256 | ||||||||||||||||||||||||||||||||||||||
| 36 | LINEAR_GRAY | ||||||||||||||||||||||||||||||||||||||
| 37 | NO_RESET_EL | ||||||||||||||||||||||||||||||||||||||
| 38 | SPLIT_ANSI | ||||||||||||||||||||||||||||||||||||||
| 39 | )) { | ||||||||||||||||||||||||||||||||||||||
| 40 | 77 | *{$name} = *{"Term::ANSIColor::Concise::$name"}; | |||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||
| 44 | #use Term::ANSIColor::Concise::Table qw(:all); | ||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=23.7
| |||||||||||||||||||||||||||||||||||||||
| 46 | 2 | my $sub = our $AUTOLOAD =~ s/.*:://r; | |||||||||||||||||||||||||||||||||||||
| 47 | 2 | ▶ | return if $sub eq 'DESTROY'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($sub =~ /^colortable(?:|6|12|24)$/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 49 | require Term::ANSIColor::Concise::Table | ||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | and Term::ANSIColor::Concise::Table->import(':all'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 51 | 0 | goto &$sub; | |||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||
| 53 | 0 | die "Invalid call for $sub().\n"; | |||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||
| 56 | 11 | ▶ | our $NO_NO_COLOR //= $ENV{GETOPTEX_NO_NO_COLOR}; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
our $NO_NO_COLOR //= $ENV{"GETOPTEX_NO_NO_COLOR"}
MC/DC0%0/2
our $NO_NO_COLOR //= $ENV{"GETOPTEX_NO_NO_COLOR"}
our $NO_NO_COLOR
$ENV{"GETOPTEX_NO_NO_COLOR"}
Truth table33%1/3
A //= B
A= our $NO_NO_COLORB= $ENV{"GETOPTEX_NO_NO_COLOR"}
| |||||||||||||||||||||||||||||||||||||||
| 57 | 11 | ▶ | our $NO_COLOR //= !$NO_NO_COLOR && defined $ENV{NO_COLOR}; | ||||||||||||||||||||||||||||||||||||
|
Condition20%1/5
our $NO_COLOR //= !$Getopt::EX::Colormap::NO_NO_COLOR && defined $ENV{"NO_COLOR"}
!$Getopt::EX::Colormap::NO_NO_COLOR && defined $ENV{'NO_COLOR'}
MC/DC0%0/1
our $NO_COLOR //= !$Getopt::EX::Colormap::NO_NO_COLOR && defined $ENV{"NO_COLOR"}
our $NO_COLOR
Truth table50%1/2
A
A= our $NO_COLOR
| |||||||||||||||||||||||||||||||||||||||
| 58 | 11 | ▶ | our $RGB24 //= $ENV{COLORTERM}//'' eq 'truecolor' || $ENV{GETOPTEX_RGB24}; | ||||||||||||||||||||||||||||||||||||
|
Condition12%1/8
our $RGB24 //=
($ENV{'COLORTERM'} // !1) || $ENV{'GETOPTEX_RGB24'}
$ENV{"COLORTERM"} //
MC/DC0%0/3
our $RGB24 //=
our $RGB24
$ENV{"COLORTERM"}
$ENV{'GETOPTEX_RGB24'}
Truth table0%0/4
A //= B || C
A= our $RGB24B= $ENV{"COLORTERM"}C= $ENV{'GETOPTEX_RGB24'}
| |||||||||||||||||||||||||||||||||||||||
| 59 | 11 | ▶ | our $LINEAR_256 //= $ENV{GETOPTEX_LINEAR_256}; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
our $LINEAR_256 //= $ENV{"GETOPTEX_LINEAR_256"}
MC/DC0%0/2
our $LINEAR_256 //= $ENV{"GETOPTEX_LINEAR_256"}
our $LINEAR_256
$ENV{"GETOPTEX_LINEAR_256"}
Truth table33%1/3
A //= B
A= our $LINEAR_256B= $ENV{"GETOPTEX_LINEAR_256"}
| |||||||||||||||||||||||||||||||||||||||
| 60 | 11 | ▶ | our $LINEAR_GRAY //= $ENV{GETOPTEX_LINEAR_GRAY}; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
our $LINEAR_GRAY //= $ENV{"GETOPTEX_LINEAR_GRAY"}
MC/DC0%0/2
our $LINEAR_GRAY //= $ENV{"GETOPTEX_LINEAR_GRAY"}
our $LINEAR_GRAY
$ENV{"GETOPTEX_LINEAR_GRAY"}
Truth table33%1/3
A //= B
A= our $LINEAR_GRAYB= $ENV{"GETOPTEX_LINEAR_GRAY"}
| |||||||||||||||||||||||||||||||||||||||
| 61 | 11 | ▶ | our $NO_RESET_EL //= $ENV{GETOPTEX_NO_RESET_EL}; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
our $NO_RESET_EL //= $ENV{"GETOPTEX_NO_RESET_EL"}
MC/DC0%0/2
our $NO_RESET_EL //= $ENV{"GETOPTEX_NO_RESET_EL"}
our $NO_RESET_EL
$ENV{"GETOPTEX_NO_RESET_EL"}
Truth table33%1/3
A //= B
A= our $NO_RESET_ELB= $ENV{"GETOPTEX_NO_RESET_EL"}
| |||||||||||||||||||||||||||||||||||||||
| 62 | 11 | ▶ | our $SPLIT_ANSI //= $ENV{GETOPTEX_SPLIT_ANSI}; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
our $SPLIT_ANSI //= $ENV{"GETOPTEX_SPLIT_ANSI"}
MC/DC0%0/2
our $SPLIT_ANSI //= $ENV{"GETOPTEX_SPLIT_ANSI"}
our $SPLIT_ANSI
$ENV{"GETOPTEX_SPLIT_ANSI"}
Truth table33%1/3
A //= B
A= our $SPLIT_ANSIB= $ENV{"GETOPTEX_SPLIT_ANSI"}
| |||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||
| 64 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 65 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||||
| 66 | 2 | my $obj = $class->SUPER::new; | |||||||||||||||||||||||||||||||||||||
| 67 | 2 | my %opt = @_; | |||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | 2 | $obj->{CACHE} = {}; | |||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | $opt{CONCAT} //= "^"; # Reset character for LabeledParam object | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt{"CONCAT"} //= "^"
MC/DC0%0/1
$opt{"CONCAT"} //= "^"
$opt{"CONCAT"}
Truth table50%1/2
A
A= $opt{"CONCAT"}
| |||||||||||||||||||||||||||||||||||||||
| 71 | 2 | $opt{RESET} = '@'; | |||||||||||||||||||||||||||||||||||||
| 72 | 2 | $obj->configure(%opt); | |||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||
| 74 | 2 | $obj; | |||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub index_color { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
index_color: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $index = shift; | |||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $text = shift; | |||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $list = $obj->{LIST}; | |||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if (@$list) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $text = $obj->color($list->[$index % @$list], $text, $index); | |||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $text; | |||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||
| 89 | 5 | ▶ | sub color { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
color: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 90 | 5 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||
| 91 | 5 | my $color = shift; | |||||||||||||||||||||||||||||||||||||
| 92 | 5 | my $text = shift; | |||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||
| 94 | 5 | my $map = $obj->{HASH}; | |||||||||||||||||||||||||||||||||||||
| 95 | 5 | ▶ | my $c = exists $map->{$color} ? $map->{$color} : $color; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||
| 97 | 5 | ▶ | return $text unless $c; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||
| 99 | 5 | cached_ansi_color($obj->{CACHE}, $c, $text); | |||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub colormap { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
colormap: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||
| 104 | 0 | my %opt = ( | |||||||||||||||||||||||||||||||||||||
| 105 | name => "--newopt", | ||||||||||||||||||||||||||||||||||||||
| 106 | option => "--colormap", | ||||||||||||||||||||||||||||||||||||||
| 107 | sort => "length", | ||||||||||||||||||||||||||||||||||||||
| 108 | @_ | ||||||||||||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my $hash = $obj->{HASH}; | |||||||||||||||||||||||||||||||||||||
| 112 | join "\n", ( | ||||||||||||||||||||||||||||||||||||||
| 113 | "option $opt{name} \\", | ||||||||||||||||||||||||||||||||||||||
| 114 | 0 | do { | |||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | my $maxlen = $opt{noalign} ? "" : do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 116 | 0 | max map { length } keys %{$hash}; | |||||||||||||||||||||||||||||||||||||
| 117 | }; | ||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $format = "\t%s %${maxlen}s=%s \\"; | |||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $compare = do { | |||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ($opt{sort} eq "length") { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub { length $a <=> length $b or $a cmp $b }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub { $a cmp $b }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||
| 125 | }; | ||||||||||||||||||||||||||||||||||||||
| 126 | map { | ||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sprintf $format, $opt{option}, $_, $hash->{$_} // ""; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$hash->{$_} // ""
MC/DC0%0/1
$hash->{$_} // ""
$hash->{$_}
Truth table0%0/2
A
A= $hash->{$_}
| |||||||||||||||||||||||||||||||||||||||
| 128 | 0 | } sort $compare keys %{$hash}; | |||||||||||||||||||||||||||||||||||||
| 129 | }, | ||||||||||||||||||||||||||||||||||||||
| 130 | "\t\$<ignore>\n", | ||||||||||||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||
| 134 | 11 | 1; | |||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||
| 136 | __END__ | ||||||||||||||||||||||||||||||||||||||