Concise/ColorObject.pm

filter: Statementstmt 85.0% 85 / 100 Branchbran 75.0% 15 / 20 Conditioncond 52.1% 12 / 23 MC/DCmcdc 13.3% 2 / 15 Subroutinesub 90.0% 18 / 20 Podpod 0.0% 0 / 11 totaltotal 69.8% 132 / 189 CC 20 SCAR 13.4
CC
20
Cov
78%
luv
12.0
yiq
12.0
set_luminance
4.0
CRAP 3.8
« Concise/ColorUtils.pm ↑ Summary Concise/Util.pm »
1 # -*- indent-tabs-mode: nil -*-
2  
3 =head1 SEE ALSO
4  
5 L<Graphics::ColorObject>
6  
7 L(<https://qiita.com/yoya/items/96c36b069e74398796f3>
8  
9 =cut
10  
11 package Term::ANSIColor::Concise::ColorObject;
12  
13 5 our $VERSION = "3.06";
14  
15 5 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use parent 'Graphics::ColorObject';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 {
23 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 for my $sub (qw(namecolor)) {
26 5 my $name = "Graphics::ColorObject::$sub";
27 5 my $save = \&{$name};
28 5 ▶ *{$name} = sub {
Subroutine __ANON__: called CC=2 SCAR=8.1
29 142 ▶ $_[1] // return;
Condition50%1/2
$_[1] // (return)
l!l
0142
MC/DC0%0/1
$_[1] // (return)
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
30 0 goto $save;
31 }
32 5 }
33 }
34  
35 # RGB
36 101 ▶sub rgb {
Subroutine rgb: called CC=3 SCAR=11.0
Pod undocumented
37 101 my $self = shift;
38 101 ▶ my $class = ref $self || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
70310
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
39 101 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 31 70 101
40 31 bless $self->SUPER::new_RGB255(\@_), $class;
41 } else {
42 70 map int, @{$self->as_RGB255};
43 }
44 }
45  
46 # HSL
47 67 ▶sub hsl {
Subroutine hsl: called CC=3 SCAR=11.0
Pod undocumented
48 67 my $self = shift;
49 67 ▶ my $class = ref $self || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
23440
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
50 67 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 44 23 67
51 44 my($h, $s, $l) = @_;
52 44 bless $self->SUPER::new_HSL([ $h, $s/100, $l/100 ]), $class;
53 } else {
54 23 my($h, $s, $l) = @{$self->as_HSL};
55 23 map int, ($h, $s * 100, $l * 100);
56 }
57 }
58  
59 # Lab
60 62 ▶sub lab {
Subroutine lab: called CC=3 SCAR=11.0
Pod undocumented
61 62 my $self = shift;
62 62 ▶ my $class = ref $self || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
5570
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
63 62 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 57 5 62
64 57 bless Graphics::ColorObject->new_Lab(\@_), $class;
65 } else {
66 5 @{$self->as_Lab};
67 }
68 }
69  
70 # Luv
71 0 ▶sub luv {
Subroutine luv: not called CC=3 SCAR=24.8
Pod undocumented
72 0 my $self = shift;
73 0 ▶ my $class = ref $self || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
74 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
75 0 my($L, $u, $v) = @_;
76 0 bless Graphics::ColorObject->new_Luv([ $L, $u / 100, $v / 100 ]), $class;
77 } else {
78 0 my($L, $u, $v) = @{$self->as_Luv};
79 0 map int, ($L, $u * 100, $v * 100);
80 }
81 }
82  
83 # LCHab
84 13 ▶sub lch {
Subroutine lch: called CC=3 SCAR=11.0
Pod undocumented
85 13 my $self = shift;
86 13 ▶ my $class = ref $self || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
3100
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
87 13 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 10 3 13
88 10 bless Graphics::ColorObject->new_LCHab(\@_), $class;
89 } else {
90 3 @{$self->as_LCHab};
91 }
92 }
93  
94 # YIQ
95 0 ▶sub yiq {
Subroutine yiq: not called CC=3 SCAR=24.8
Pod undocumented
96 0 my $self = shift;
97 0 ▶ my $class = ref $self || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
98 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
99 0 bless Graphics::ColorObject->new_YIQ(\@_), $class;
100 } else {
101 0 @{$self->as_YIQ};
102 }
103 }
104  
105 10 ▶sub luminance {
Subroutine luminance: called CC=2 SCAR=6.9
Pod undocumented
106 10 my $self = shift;
107 10 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 5 5 10
108 5 $self->set_luminance(@_);
109 } else {
110 5 $self->get_luminance;
111 }
112 }
113  
114 5 ▶use List::Util qw(pairs);
Subroutine BEGIN: called CC=1 SCAR=0.0
115  
116 5 ▶sub set {
Subroutine set: called CC=2 SCAR=6.9
Pod undocumented
117 5 my $map = shift;
118 5 $_[$_->[0]] = $_->[1] for pairs @$map;
119 5 @_;
120 }
121  
122 5 ▶sub get_luminance {
Subroutine get_luminance: called CC=1 SCAR=0.0
Pod undocumented
123 5 int $_[0] -> as_Lab -> [0];
124 }
125  
126 40 ▶sub in_rgb_gamut {
Subroutine in_rgb_gamut: called CC=2 SCAR=6.9
Pod undocumented
127 40 my $self = shift;
128 40 my @rgb = @{$self->as_RGB};
129 40 ▶ !grep { $_ < 0 || $_ > 1 } @rgb;
Condition100%3/3
$_ < 0 || $_ > 1
l!l&&r!l&&!r
121296
MC/DC100%2/2
$_ < 0 || $_ > 1
$_ < 0 $_ > 1
Truth table100%3/3
A || B
A= $_ < 0B= $_ > 1
ABresult
1X1
011
000
130 }
131  
132 5 ▶sub set_luminance {
Subroutine set_luminance: called CC=4 SCAR=13.9
Pod undocumented
133 5 my($self, $L) = @_;
134 5 my @lab = $self->lab;
135 5 my $new = __PACKAGE__->lab(set([ 0 => $L ], @lab));
136 5 ▶ return $new if $new->in_rgb_gamut;
Branch: 1 branch
BranchTrueFalseTotal
if $new->in_rgb_gamut 0 5 5
137  
138 # Reduce chroma to fit in RGB gamut using binary search
139 5 my($a, $b) = @lab[1, 2];
140 5 my($lo, $hi) = (0, 100);
141 5 ▶ while ($hi - $lo > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hi - $lo > 1) 35 5 40
142 35 my $mid = ($lo + $hi) / 2;
143 35 my $test = __PACKAGE__->lab($L, $a * $mid / 100, $b * $mid / 100);
144 35 ▶ if ($test->in_rgb_gamut) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test->in_rgb_gamut) { } 22 13 35
145 22 $lo = $mid;
146 } else {
147 13 $hi = $mid;
148 }
149 }
150 5 __PACKAGE__->lab($L, $a * $lo / 100, $b * $lo / 100);
151 }
152  
153 5 1;
« Concise/ColorUtils.pm ↑ Summary Concise/Util.pm »