App/HI.pm

filter: Statementstmt 42.8% 33 / 77 Branchbran 23.3% 7 / 30 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 4 totaltotal 32.6% 47 / 144 CC 22 SCAR 40.6
CC
22
Cov
33%
sort_colors
132.0
list_colors
42.0
top_matter
5.7
CRAP 58.2
↑ Summary Term/ANSIColorx/AutoFilterFH.pm »
1  
2 package App::HI;
3  
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Text::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Term::Size;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION = '2.7193';
9  
10 3 ▶sub top_matter {
Subroutine top_matter: called CC=5 SCAR=17.4
Pod undocumented
11 3 my $no_extra = shift;
12 3 my @to_import = qw(color colored colorvalid);
13  
14 3 ▶ if( $no_extra ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($no_extra) { } 0 3 3
15 0 ▶ eval qq/ use Term::ANSIColor qw(@to_import); 1 /
Branch: 1 branch
BranchTrueFalseTotal
eval " use Term::ANSIColor qw(@to_import); 1 " or die $@ 0 0 0
16 or die $@;
17  
18 } else {
19 3 ▶ eval qq/ use Term::ANSIColorx::ColorNicknames qw(@to_import); 1 /
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval " use Term::ANSIColorx::ColorNicknames qw(@to_import); 1 " or die $@ 3 0 3
20 or die $@;
21 }
22  
23 3 ▶ eval q { use Term::ANSIColorx::AutoFilterFH qw(filtered_handle); 1 }
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval " use Term::ANSIColorx::AutoFilterFH qw(filtered_handle); 1 " or die $@ 3 0 3
24 or die $@;
25 }
26  
27 3 ▶sub fire_filter {
Subroutine fire_filter: called CC=3 SCAR=11.0
Pod undocumented
28 3 my $class = shift;
29 3 my %o = @_;
30  
31 3 top_matter( $o{nixnics} );
32  
33 3 my $newstdout = filtered_handle(\*STDOUT, @ARGV);
34 3 $| = 1; my $oldstdout = select $newstdout; $|=1;
35 3 ▶ $newstdout->set_truncate($o{trunc}) if $o{trunc};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"trunc"} 1 2 3
36  
37 3 binmode $newstdout, ':utf8';
38 3 binmode STDIN, ':utf8';
39  
40 3 ▶ while(<STDIN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline STDIN)) 7 3 10
41 7 print
42 }
43 }
44  
45 0 ▶sub sort_colors {
Subroutine sort_colors: not called CC=11 SCAR=48.8
Pod undocumented
46 0 my %yet_seen;
47  
48 0 map {$_->{cn}}
49  
50 sort {
51 $a->{bg} <=> $b->{bg} ||
52 $a->{at} <=> $b->{at} ||
53 $a->{fg} <=> $b->{fg}
54 0 ▶ }
Condition0%0/6
$App::HI::a->{'bg'} <=> $App::HI::b->{'bg'} || $App::HI::a->{'at'} <=> $App::HI::b->{'at'} || $App::HI::a->{'fg'} <=> $App::HI::b->{'fg'}
l!l&&r!l&&!r
000
$App::HI::a->{"bg"} <=> $App::HI::b->{"bg"} or $App::HI::a->{"at"} <=> $App::HI::b->{"at"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$App::HI::a->{'bg'} <=> $App::HI::b->{'bg'} || $App::HI::a->{'at'} <=> $App::HI::b->{'at'} || $App::HI::a->{'fg'} <=> $App::HI::b->{'fg'}
$App::HI::a->{"bg"} <=> $App::HI::b->{"bg"} $App::HI::a->{"at"} <=> $App::HI::b->{"at"} $App::HI::a->{'fg'} <=> $App::HI::b->{'fg'}
Truth table0%0/4
A or B || C
A= $App::HI::a->{"bg"} <=> $App::HI::b->{"bg"}B= $App::HI::a->{"at"} <=> $App::HI::b->{"at"}C= $App::HI::a->{'fg'} <=> $App::HI::b->{'fg'}
ABCresult
1XX1
01X1
0011
0000
55  
56 map {
57 0 my $res = { cn => $_ };
58 0 ▶ my @v = map { $_ >= 90 && $_ <= 107 ? $_-60 : $_ } ( color($_) =~ m/(\d+)/g );
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 90 && $_ <= 107 ? : 0 0 0
Condition0%0/3
$_ >= 90 and $_ <= 107
!ll&&!rl&&r
000
MC/DC0%0/2
$_ >= 90 and $_ <= 107
$_ >= 90 $_ <= 107
Truth table0%0/3
A and B
A= $_ >= 90B= $_ <= 107
ABresult
0X0
100
111
59  
60 0 $res->{at} = grep {$_ <= 8} @v;
61 0 ▶ $res->{fg} = grep {$_ >= 30 && $_ <= 37} @v;
Condition0%0/3
$_ >= 30 && $_ <= 37
!ll&&!rl&&r
000
MC/DC0%0/2
$_ >= 30 && $_ <= 37
$_ >= 30 $_ <= 37
Truth table0%0/3
A && B
A= $_ >= 30B= $_ <= 37
ABresult
0X0
100
111
62 0 ▶ $res->{bg} = grep {$_ >= 40 && $_ <= 47} @v;
Condition0%0/3
$_ >= 40 && $_ <= 47
!ll&&!rl&&r
000
MC/DC0%0/2
$_ >= 40 && $_ <= 47
$_ >= 40 $_ <= 47
Truth table0%0/3
A && B
A= $_ >= 40B= $_ <= 47
ABresult
0X0
100
111
63  
64 0 ▶ $res->{at} = 0 unless $res->{at};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"at"} 0 0 0
65 0 ▶ $res->{fg} = 30 unless $res->{fg};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"fg"} 0 0 0
66 0 ▶ $res->{bg} = 40 unless $res->{bg};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"bg"} 0 0 0
67  
68 0 $res;
69 }
70  
71 grep {
72 0 my $valid = colorvalid($_);
73 0 ▶ warn "$_ isn't valid" unless $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 0 0 0
74  
75 0 $valid
76 }
77  
78 grep {
79 0 !$yet_seen{$_}++
80 }
81  
82 @_
83 }
84  
85 0 ▶sub list_colors {
Subroutine list_colors: not called CC=6 SCAR=37.4
Pod undocumented
86 0 my $class = shift;
87 0 my %o = @_;
88  
89 0 top_matter( $o{nixnics} => qw(color colorvalid) );
90  
91 0 my $table;
92  
93 0 my @colors = sort_colors(
94 map("bold $_", qw( black red green yellow blue magenta cyan white )),
95 qw( black red green yellow blue magenta cyan white ),
96  
97 "white on_black", "white on_red", "blue on_green", "black on_yellow",
98 "white on_blue", "white on_magenta", "black on_cyan", "black on_white",
99  
100 "pitch on white",
101  
102 keys %Term::ANSIColorx::ColorNicknames::NICKNAMES,
103 );
104  
105 0 my ($columns, $rows) = Term::Size::chars *STDOUT;
106  
107 0 $columns --;
108  
109 0 my $m = 20;
110 UGH_SO_BAD: {
111 # XXX: this is so in-efficient it makes my soul hurt
112 0 $table = Text::Table->new;
113  
114 0 my @row;
115 0 for(@colors) {
116 0 push @row, $_;
117  
118 0 ▶ unless( @row % $m ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@row % $m) 0 0 0
119 0 ▶ $table->add(map {$_ ? colored($_, $_) : $_} @row);
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
120 0 @row = ();
121 }
122 }
123  
124 0 ▶ $table->add(map {$_ ? colored($_, $_) : $_} @row);
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
125  
126 0 $m -= 2;
127 0 ▶ redo UGH_SO_BAD if $table->width > $columns;
Branch: 1 branch
BranchTrueFalseTotal
if $table->width > $columns 0 0 0
128 }
129  
130 0 print $table;
131 }
132  
133 __END__
↑ Summary Term/ANSIColorx/AutoFilterFH.pm »