Concise/Table.pm

filter: Statementstmt 33.3% 26 / 78 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 50.0% 7 / 14 Podpod 80.0% 4 / 5 totaltotal 34.2% 37 / 108 CC 16 SCAR 40.8
CC
16
Cov
30%
colortable
132.0
colortableN
42.0
colortable6
2.0
CRAP 59.3
↑ Summary Concise/Transform.pm »
1 # -*- indent-tabs-mode: nil -*-
2  
3 package Term::ANSIColor::Concise::Table;
4  
5 1 our $VERSION = "3.06";
6  
7 1 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 our @EXPORT = qw();
12 1 our @EXPORT_OK = qw(
13 colortable colortable6 colortable12 colortable24
14 );
15 1 our %EXPORT_TAGS = (all => [ @EXPORT_OK ]);
16  
17 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 $Data::Dumper::Sortkeys = 1;
20  
21 1 ▶use Term::ANSIColor::Concise qw(ansi_color map_to_256);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use List::Util qw(min);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 0 ▶sub colortable6 {
Subroutine colortable6: not called CC=1 SCAR=6.9
Pod documented
25 0 colortableN(
26 step => 6,
27 string => " ",
28 line => 2,
29 x => 1, y => 1, z => 1,
30 @_
31 );
32 }
33  
34 0 ▶sub colortable12 {
Subroutine colortable12: not called CC=1 SCAR=6.9
Pod documented
35 0 colortableN(
36 step => 12,
37 string => " ",
38 x => 1, y => 1, z => 2,
39 @_
40 );
41 }
42  
43 # use charnames ':full';
44  
45 0 ▶sub colortable24 {
Subroutine colortable24: not called CC=1 SCAR=6.9
Pod documented
46 0 colortableN(
47 step => 24,
48 string => "\N{U+2580}", # "\N{UPPER HALF BLOCK}",
49 shift => 1,
50 x => 1, y => 2, z => 4,
51 @_
52 );
53 }
54  
55 0 ▶sub colortableN {
Subroutine colortableN: not called CC=6 SCAR=37.4
Pod undocumented
56 0 my %arg = (
57 shift => 0,
58 line => 1,
59 row => 3,
60 @_);
61 0 my @combi = do {
62 0 my @default = qw( XYZ YZX ZXY YXZ XZY ZYX );
63 0 ▶ if (my @s = $arg{row} =~ /[xyz]{3}/ig) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@s) = $arg{'row'} =~ /[xyz]{3}/giu) { } 0 0 0
64 0 @s;
65 } else {
66 0 @default[0 .. $arg{row} - 1];
67 }
68 };
69 my @order = map {
70 0 my @ord = map { { X=>0, Y=>1, Z=>2 }->{$_} } /[XYZ]/g;
71 0 ▶ sub { @_[@ord] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 0 } map { uc } @combi;
73 0 binmode STDOUT, ":utf8";
74 0 for my $order (@order) {
75 0 ▶ my $rgb = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 sprintf "#%02x%02x%02x",
77 0 map { map_to_256($arg{step}, $_) } $order->(@_);
78 0 };
79 0 ▶ for (my $y = 0; $y < $arg{step}; $y += $arg{y}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $arg{"step"}) 0 0 0
80 0 my @out;
81 0 ▶ for (my $z = 0; $z < $arg{step}; $z += $arg{z}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($z < $arg{"step"}) 0 0 0
82 0 ▶ for (my $x = 0; $x < $arg{step}; $x += $arg{x}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $arg{"step"}) 0 0 0
83 0 my $fg = $rgb->($x, $y, $z);
84 0 my $bg = $rgb->($x, $y + $arg{shift}, $z);
85 0 push @out, ansi_color "$fg/$bg", $arg{string};
86 }
87 }
88 0 print((@out, "\n") x $arg{line});
89 }
90 }
91 }
92  
93 0 ▶sub colortable {
Subroutine colortable: not called CC=11 SCAR=48.8
Pod documented
94 0 ▶ my $width = shift || 144;
Condition0%0/2
shift() || 144
l!l
00
MC/DC0%0/1
shift() || 144
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
95 0 my $column = min 6, $width / (4 * 6);
96 0 for my $c (0..5) {
97 0 for my $b (0..5) {
98 0 my @format =
99 ("%d$b$c", "$c%d$b", "$b$c%d", "$b%d$c", "$c$b%d", "%d$c$b")
100 [0 .. $column - 1];
101 0 for my $format (@format) {
102 0 for my $a (0..5) {
103 0 my $rgb = sprintf $format, $a;
104 0 print ansi_color "$rgb/$rgb", " $rgb";
105 }
106 }
107 0 print "\n";
108 }
109 }
110 0 for my $g (0..5) {
111 0 my $grey = $g x 3;
112 0 print ansi_color "$grey/$grey", sprintf(" %-19s", $grey);
113 }
114 0 print "\n";
115 0 for ('L00' .. 'L25') {
116 0 print ansi_color "$_/$_", " $_";
117 }
118 0 print "\n";
119 0 for my $rgb ("RGBCMYKW", "rgbcmykw") {
120 0 for my $c (split //, $rgb) {
121 0 print ansi_color "$c/$c", " $c ";
122 }
123 0 print "\n";
124 }
125 0 for my $rgb (qw(500 050 005 055 505 550 000 555)) {
126 0 print ansi_color "$rgb/$rgb", " $rgb";
127 }
128 0 print "\n";
129 }
130  
131 1 1;
132  
133 __END__
↑ Summary Concise/Transform.pm »