blib/lib/Colouring/In.pm

filter: Statementstmt 88.0% 176 / 200 Branchbran 92.3% 96 / 104 Conditioncond 66.1% 39 / 59 MC/DCmcdc 48.5% 17 / 35 Subroutinesub 88.8% 48 / 54 Podpod 100% 26 / 26 totaltotal 84.1% 402 / 478 CC 79 SCAR 15.5
CC
79
Cov
86%
mix
12.0
saturate
12.0
desaturate
12.0
CRAP 4.7
↑ Summary
1 package Colouring::In;
2  
3 13 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use smallnum;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 our $VERSION = '0.27';
8  
9 13 our (%TOOL, $ANOBJECT);
10  
11 use overload
12 13 ▶ '""' => sub { $_[0]->toCSS() };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
13  
14  
15 13 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
16 %TOOL = (
17 30557 ▶ clamp => sub { return $TOOL{min}( $TOOL{max}( $_[0], 0 ), $_[1]); },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 30728 ▶ max => sub { $_[ ($_[0] || 0) < ($_[1] || 0) ] || 0 },
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
$_[($_[0] || bless( do{\(my $o = 0)}, 'smallnum' )) < ($_[1] || bless( do{\(my $o = 0)}, 'smallnum' ))] or bless( do{\(my $o = 0)}, 'smallnum' ) 20447 10281 30728
Condition100%4/4
$_[0] || \'0'
l!l
2044710281
$_[1] || \'0'
l!l
13130597
MC/DC100%1/1
$_[0] || \'0'
$_[0]
MC/DC100%1/1
$_[1] || \'0'
$_[1]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
19 30728 ▶ min => sub { $_[ ($_[0] || 0) > ($_[1] || 0) ] || 0 },
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
$_[($_[0] || bless( do{\(my $o = 0)}, 'smallnum' )) > ($_[1] || bless( do{\(my $o = 0)}, 'smallnum' ))] or bless( do{\(my $o = 0)}, 'smallnum' ) 20435 10293 30728
Condition100%4/4
$_[0] || \'0'
l!l
2044110287
$_[1] || \'0'
l!l
3068642
MC/DC100%1/1
$_[0] || \'0'
$_[0]
MC/DC100%1/1
$_[1] || \'0'
$_[1]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
20 266 ▶ round => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
21 266 ▶ return sprintf '%.' . ( defined $_[1] ? $_[1] : 0 ) . 'f', $_[0];
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 1 265 266
22 },
23 10148 ▶ numIs => sub { return defined $_[0] && $_[0] =~ /^[0-9]+/; },
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%3/3
defined $_[0] && $_[0] =~ /^[0-9]+/
!ll&&!rl&&r
62110085
MC/DC100%2/2
defined $_[0] && $_[0] =~ /^[0-9]+/
defined $_[0] $_[0] =~ /^[0-9]+/
Truth table100%3/3
A && B
A= defined $_[0]B= $_[0] =~ /^[0-9]+/
ABresult
0X0
100
111
24 40 ▶ percent => sub { return ( $_[0] * 100 ) . '%'; },
Subroutine __ANON__: called CC=1 SCAR=0.0
25 20081 ▶ depercent => sub { my $p = shift; $p =~ s/%$//; return $p / 100; },
Subroutine __ANON__: called CC=1 SCAR=0.0
26 54 ▶ joinRgb => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
27 54 return join ',', map { $TOOL{clamp}( $TOOL{round}($_), 255 ); } @_;
28 },
29 83 ▶ rgb2hs => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
30 83 my @rgb = map { $_ / 255 } @_;
31 83 push @rgb, $TOOL{max}( $TOOL{max}( $rgb[0], $rgb[1] ), $rgb[2] );
32 83 push @rgb, $TOOL{min}( $TOOL{min}( $rgb[0], $rgb[1] ), $rgb[2] );
33 83 push @rgb, ( $rgb[3] - $rgb[4] );
34 83 return @rgb;
35 },
36 30221 ▶ hue => sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
37 30221 my ( $h, $m1, $m2 ) = @_;
38 30221 ▶ $h = $h < 0 ? $h + 1 : ( $h > 1 ? $h - 1 : $h );
Branch: 2 branches
BranchTrueFalseTotal
$h < \'0' ? : 3348 26873 30221
$h > \'1' ? : 3198 23675 26873
39 30221 ▶ if ( $h * 6 < 1 ) { return $m1 + ( $m2 - $m1 ) * $h * 6; }
Branch: 3 branches
BranchTrueFalseTotal
if ($h * \'6' < \'1') { } 5091 25130 30221
elsif ($h * \'2' < \'1') { } 9993 15137 25130
elsif ($h * \'3' < \'2') { } 5063 10074 15137
40 9993 elsif ( $h * 2 < 1 ) { return $m2; }
41 elsif ( $h * 3 < 2 ) {
42 5063 return $m1 + ( $m2 - $m1 ) * ( 2 / 3 - $h ) * 6;
43 }
44 10074 return $m1;
45 },
46 197 ▶ scaled => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
47 197 my ( $n, $size ) = @_;
48 197 ▶ return ( $n =~ s/%// )
Branch: 1 branch
BranchTrueFalseTotal
$n =~ s/%// ? : 1 196 197
49 ? sprintf( '%.f', (($n * $size) / 100 ))
50 : return sprintf( "%d", $n );
51 },
52 10082 ▶ convertColour => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
53 10082 my $colour = shift;
54 10082 my %converter = (
55 '#' => 'hex2rgb',
56 'rgb' => 'rgb2rgb',
57 'hsl' => 'hsl2rgb',
58 'hsla' => 'hsl2rgb',
59 );
60 10082 my $reg = join '|', reverse sort keys %converter;
61 10082 ▶ if ( $colour =~ s/^($reg)// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colour =~ s/^($reg)//) 10081 1 10082
62 10081 return $TOOL{ $converter{$1} }($colour);
63 }
64 1 ▶ die $TOOL{MESSAGES}{INVALID_COLOUR} || 'Cannot convert the colour format';
Condition50%1/2
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_COLOUR'} || 'Cannot convert the colour format'
l!l
01
MC/DC0%0/1
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_COLOUR'} || 'Cannot convert the colour format'
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_COLOUR'}
Truth table50%1/2
A
A= $Colouring::In::TOOL{'MESSAGES'}{'INVALID_COLOUR'}
Aresult
11
00
65 },
66 19 ▶ rgb2rgb => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
67 19 my @numbers = $TOOL{numbers}(shift);
68 19 ▶ die $TOOL{MESSAGES}{INVALID_RGB} || 'Cannot convert rgb colour format' unless (scalar @numbers > 2);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @numbers > bless( do{\(my $o = 2)}, 'smallnum' ) 1 18 19
Condition50%1/2
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_RGB'} || 'Cannot convert rgb colour format'
l!l
01
MC/DC0%0/1
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_RGB'} || 'Cannot convert rgb colour format'
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_RGB'}
Truth table50%1/2
A
A= $Colouring::In::TOOL{'MESSAGES'}{'INVALID_RGB'}
Aresult
11
00
69 18 return @numbers;
70 },
71 53 ▶ hex2rgb => sub {
Subroutine __ANON__: called CC=9 SCAR=22.7
72 53 my $hex = shift;
73 53 my $l = length $hex;
74 return $l != 6
75 ? $l == 3
76 13 ▶ ? map { my $h = hex( $_ . $_ ); $_ =~ 0 || $h ? $h : die( $TOOL{MESSAGES}{INVALID_HEX} || 'Cannot convert hex colour format' ) } $hex =~ m/./g
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /0/ || $h ? : 12 1 13
Condition80%4/5
$_ =~ /0/ or $h
l!l&&r!l&&!r
841
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_HEX'} || 'Cannot convert hex colour format'
l!l
01
MC/DC100%2/2
$_ =~ /0/ or $h
$_ =~ /0/ $h
MC/DC0%0/1
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_HEX'} || 'Cannot convert hex colour format'
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_HEX'}
Truth table100%3/3
A or B
A= $_ =~ /0/B= $h
ABresult
1X1
011
000
Truth table50%1/2
A
A= $Colouring::In::TOOL{'MESSAGES'}{'INVALID_HEX'}
Aresult
11
00
77 : die 'hex length must be 3 or 6'
78 53 ▶ : map { my $h = hex( $_ ); $_ =~ m/00/ || $h ? $h : die( $TOOL{MESSAGES}{INVALID_HEX} || 'Cannot convert hex colour format' ) } $hex =~ m/../g;
Branch: 3 branches
BranchTrueFalseTotal
$l != \'6' ? : 6 47 53
$l == \'3' ? : 5 1 6
$_ =~ /00/ || $h ? : 141 0 141
Condition40%2/5
$_ =~ /00/ or $h
l!l&&r!l&&!r
321090
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_HEX'} || 'Cannot convert hex colour format'
l!l
00
MC/DC0%0/2
$_ =~ /00/ or $h
$_ =~ /00/ $h
MC/DC0%0/1
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_HEX'} || 'Cannot convert hex colour format'
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_HEX'}
Truth table66%2/3
A or B
A= $_ =~ /00/B= $h
ABresult
1X1
011
000
Truth table0%0/2
A
A= $Colouring::In::TOOL{'MESSAGES'}{'INVALID_HEX'}
Aresult
11
00
79 },
80 10074 ▶ hsl2rgb => sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
81 10074 ▶ my ( $h, $s, $l, $a, $m1, $m2 ) = scalar @_ > 1 ? @_ : $TOOL{numbers}(shift);
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ > \'1' ? : 64 10010 10074
82 10074 ▶ defined $_ && $_ =~ m/([0-9.]+)/ or die $TOOL{MESSAGES}{INVALID_HSL} || 'Cannot convert hsl colour format' for ($h, $s, $l);
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ =~ /([0-9.]+)/ or die $Colouring::In::TOOL{"MESSAGES"}{"INVALID_HSL"} || "Cannot convert hsl colour format" 30219 1 30220
Condition60%3/5
defined $_ and $_ =~ /([0-9.]+)/
!ll&&!rl&&r
1030219
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_HSL'} || 'Cannot convert hsl colour format'
l!l
01
MC/DC50%1/2
defined $_ and $_ =~ /([0-9.]+)/
defined $_ $_ =~ /([0-9.]+)/
MC/DC0%0/1
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_HSL'} || 'Cannot convert hsl colour format'
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_HSL'}
Truth table66%2/3
A and B
A= defined $_B= $_ =~ /([0-9.]+)/
ABresult
0X0
100
111
Truth table50%1/2
A
A= $Colouring::In::TOOL{'MESSAGES'}{'INVALID_HSL'}
Aresult
11
00
83 10073 $h = ( $h % 360 ) / 360;
84 10073 ▶ unless ($m1) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($m1) 10009 64 10073
85 10009 $s = $TOOL{depercent}($s);
86 10009 $l = $TOOL{depercent}($l);
87 }
88 10073 ▶ $m2 = $l <= 0.5 ? $l * ( $s + 1 ) : $l + $s - $l * $s;
Branch: 1 branch
BranchTrueFalseTotal
$l <= \'0.5' ? : 10021 52 10073
89 10073 $m1 = $l * 2 - $m2;
90 return (
91 ($TOOL{clamp}($TOOL{hue}( $h + 1 / 3, $m1, $m2 ), 1) * 255),
92 ($TOOL{clamp}($TOOL{hue}( $h, $m1, $m2 ), 1) * 255),
93 10073 ▶ ($TOOL{clamp}($TOOL{hue}( $h - 1 / 3, $m1, $m2 ), 1) * 255),
Branch: 1 branch
BranchTrueFalseTotal
defined $a ? : 10070 3 10073
94 ( defined $a ? $a : () ),
95 );
96 },
97 10029 ▶ numbers => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
98 10029 return ( $_[0] =~ m/([0-9.]+)/g );
99 },
100 63 ▶ hsl => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
101 63 my $colour = shift;
102 63 ▶ if ( ref \$colour eq 'SCALAR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref \$colour eq "SCALAR") 50 13 63
103 50 $colour = Colouring::In->new($colour);
104 }
105 63 my $hsl = $TOOL{asHSL}($colour);
106 63 return ( $hsl, $colour );
107 },
108 63 ▶ hash2array => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
109 63 my $hash = shift;
110 63 return map { $hash->{$_} } @_;
111 },
112 75 ▶ asHSL => sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
113 75 my ( $r, $g, $b, $max, $min, $d, $h, $s, $l ) = $TOOL{rgb2hs}( $_[0]->colour );
114  
115 75 $l = ( $max + $min ) / 2;
116 75 ▶ if ( $max == $min ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max == $min) { } 68 7 75
117 68 $h = $s = 0;
118 }
119 else {
120 7 $d = smallnum::_smallnum($d); #grrr
121 7 ▶ $s = $l > 0.5 ? ($d / ( 2 - $max - $min )) : ($d / ( $max + $min ));
Branch: 1 branch
BranchTrueFalseTotal
$l > \'0.5' ? : 3 4 7
122 7 ▶ $h = ( $max == $r )
Branch: 3 branches
BranchTrueFalseTotal
$max == $r ? : 4 3 7
$g < $b ? : 1 3 4
$max == $g ? : 2 1 3
123 ? ( $g - $b ) / $d + ( $g < $b ? 6 : 0 )
124 : ( $max == $g )
125 ? ( $b - $r ) / $d + +2
126 : ( $r - $g ) / $d + 4;
127 7 $h /= 6;
128 }
129  
130 return {
131 h => $h * 360,
132 s => $s,
133 l => $l,
134 a => $_[0]->{alpha},
135 75 };
136 }
137 13 );
138 }
139  
140 13 ▶sub import {
Subroutine import: called CC=4 SCAR=13.9
141 13 my ($pkg, @exports) = @_;
142 13 my $caller = caller;
143 13 ▶ $TOOL{MESSAGES} = pop @exports if (ref $exports[-1] eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $exports[-1] eq "HASH" 1 12 13
144 13 ▶ if (scalar @exports) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @exports) 5 8 13
145 13 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
146 5 *{"${caller}::${_}"} = \&{"${_[0]}::${_}"} foreach @exports;
147 }
148 }
149  
150 1 ▶sub rgb {
Subroutine rgb: called CC=1 SCAR=0.0
Pod documented
151 1 return $_[0]->rgba( $_[1], $_[2], $_[3], $_[4] );
152 }
153  
154 65 ▶sub rgba {
Subroutine rgba: called CC=1 SCAR=0.0
Pod documented
155 65 my $rgb = [ map { $TOOL{scaled}( $_, 255 ) } ( $_[1], $_[2], $_[3] ) ];
156 65 return Colouring::In->new( $rgb, $TOOL{clamp}($_[4], 1) );
157 }
158  
159 1 ▶sub hsl {
Subroutine hsl: called CC=1 SCAR=0.0
Pod documented
160 1 my $self = shift;
161 1 return $self->rgba($TOOL{hsl2rgb}(@_, 1));
162 }
163  
164 63 ▶sub hsla {
Subroutine hsla: called CC=1 SCAR=0.0
Pod documented
165 63 my $self = shift;
166 63 return $self->rgba($TOOL{hsl2rgb}(@_, 1));
167 }
168  
169 10142 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
170 10142 my ( $pkg, $rgb, $a ) = @_;
171  
172 10142 my $self = bless {}, $pkg;
173 # The end goal here, is to parse the arguments
174 # into an integer triplet, such as `128, 255, 0`
175 10142 ▶ if ( ref $rgb eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rgb eq 'ARRAY') { } 78 10064 10142
176 78 ▶ scalar @$rgb == 4 and $a = pop @$rgb;
Branch: 1 branch
BranchTrueFalseTotal
scalar @$rgb == bless( do{\(my $o = 4)}, 'smallnum' ) and $a = pop @$rgb 2 76 78
177 78 $self->{colour} = $rgb;
178 } else {
179 10064 $self->{colour} = [ $TOOL{convertColour}($rgb) ];
180 10061 ▶ scalar @{ $self->{colour} } == 4 and $a = pop @{$self->{colour}};
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$self->{"colour"};} == bless( do{\(my $o = 4)}, 'smallnum' ) and $a = pop @{$$self{"colour"};} 10014 47 10061
181 }
182 10139 ▶ $self->{alpha} = $TOOL{numIs}($a) ? $a : 1;
Branch: 1 branch
BranchTrueFalseTotal
$Colouring::In::TOOL{'numIs'}->($a) ? : 10084 55 10139
183 10139 return $self;
184 }
185  
186 18 ▶sub toCSS {
Subroutine toCSS: called CC=2 SCAR=6.9
Pod documented
187 18 my $alpha = $TOOL{round}( $_[0]->{alpha}, $_[1] );
188 18 ▶ return ( $alpha != 1 ) ? $_[0]->toRGBA() : $_[0]->toHEX( $_[2] );
Branch: 1 branch
BranchTrueFalseTotal
$alpha != \'1' ? : 1 17 18
189 }
190  
191 5 ▶sub toTerm {
Subroutine toTerm: called CC=1 SCAR=0.0
Pod documented
192 5 return sprintf( "r%sg%sb%s", $_[0]->colour );
193 }
194  
195 5 ▶sub toOnTerm {
Subroutine toOnTerm: called CC=1 SCAR=0.0
Pod documented
196 5 return sprintf( "on_r%sg%sb%s", $_[0]->colour );
197 }
198  
199 9 ▶sub toRGB {
Subroutine toRGB: called CC=3 SCAR=11.7
Pod documented
200 9 ▶ return $_[0]->toRGBA( $_[1] ) if $TOOL{numIs}( $_[1] ) and $_[1] != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $Colouring::In::TOOL{"numIs"}->($_[bless( do{\(my $o = 1)}, 'smallnum' )]) and $_[1] != bless( do{\(my $o = 1)}, 'smallnum' ) 0 9 9
Condition66%2/3
$Colouring::In::TOOL{"numIs"}->($_[bless( do{\(my $o = 1)}, 'smallnum' )]) and $_[1] != bless( do{\(my $o = 1)}, 'smallnum' )
!ll&&!rl&&r
810
MC/DC0%0/2
$Colouring::In::TOOL{"numIs"}->($_[bless( do{\(my $o = 1)}, 'smallnum' )]) and $_[1] != bless( do{\(my $o = 1)}, 'smallnum' )
$Colouring::In::TOOL{"numIs"}->($_[bless( do{\(my $o = 1)}, 'smallnum' )]) $_[1] != bless( do{\(my $o = 1)}, 'smallnum' )
Truth table66%2/3
A and B
A= $Colouring::In::TOOL{"numIs"}->($_[bless( do{\(my $o = 1)}, 'smallnum' )])B= $_[1] != bless( do{\(my $o = 1)}, 'smallnum' )
ABresult
0X0
100
111
201 9 return sprintf( 'rgb(%s)', ( $TOOL{joinRgb}( $_[0]->colour ) ) );
202 }
203  
204 45 ▶sub toRGBA {
Subroutine toRGBA: called CC=1 SCAR=0.0
Pod documented
205 return sprintf 'rgba(%s,%s)', $TOOL{joinRgb}( $_[0]->colour ),
206 45 $_[0]->{alpha};
207 }
208  
209 28 ▶sub toHEX {
Subroutine toHEX: called CC=3 SCAR=11.0
Pod documented
210 my $colour = sprintf(
211 "#%02lx%02lx%02lx",
212 (
213 28 map { my $c = $TOOL{clamp}( $TOOL{round}($_), 255 ); $c }
214 $_[0]->colour
215 )
216 );
217 28 ▶ unless ( $_[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[1]) 23 5 28
218 23 ▶ if ( $colour =~ /#(.)\1(.)\2(.)\3/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colour =~ /#(.)\1(.)\2(.)\3/g) 22 1 23
219 22 $colour = sprintf "#%s%s%s", $1, $2, $3;
220 }
221 }
222 28 return $colour;
223 }
224  
225 12 ▶sub toHSL {
Subroutine toHSL: called CC=1 SCAR=0.0
Pod documented
226 12 my $hsl = $TOOL{asHSL}($_[0]);
227 sprintf( "hsl(%s,%s,%s)",
228 $hsl->{h},
229 $TOOL{percent}( $hsl->{s} ),
230 12 $TOOL{percent}( $hsl->{l} ),
231 );
232 }
233  
234 8 ▶sub toHSV {
Subroutine toHSV: called CC=6 SCAR=17.9
Pod documented
235 8 my ( $r, $g, $b, $max, $min, $d, $h, $s, $v ) = $TOOL{rgb2hs}( $_[0]->colour );
236  
237 8 $v = $max;
238 8 ▶ $s = ( $max == 0 ) ? $max : $d / $max;
Branch: 1 branch
BranchTrueFalseTotal
$max == \'0' ? : 1 7 8
239  
240 8 ▶ if ( $max == $min ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max == $min) { } 2 6 8
241 2 $h = 0;
242 }
243 else {
244 6 ▶ $h = ( $max == $r ) ? ( $g - $b ) / $d + ( $g < $b ? 6 : 0 )
Branch: 3 branches
BranchTrueFalseTotal
$max == $r ? : 4 2 6
$g < $b ? : 1 3 4
$max == $g ? : 1 1 2
245 : ( $max == $g ) ? ( $b - $r ) / $d + 2
246 : ( $r - $g ) / $d + 4;
247 6 $h /= 6;
248 }
249  
250 return sprintf( "hsv(%s,%s,%s)",
251 ( $h * 360 ),
252 $TOOL{percent}($s),
253 8 $TOOL{percent}($v),
254 );
255 }
256  
257 11 ▶sub lighten {
Subroutine lighten: called CC=4 SCAR=13.9
Pod documented
258 11 my ( $colour, $amt, $meth, $hsl ) = @_;
259  
260 11 ( $hsl, $colour ) = $TOOL{hsl}($colour);
261  
262 11 $amt = $TOOL{depercent}($amt);
263 $hsl->{l} += $TOOL{clamp}(
264 ( $meth && $meth eq 'relative' )
265 11 ▶ ? (($hsl->{l} || 1) * $amt)
Branch: 1 branch
BranchTrueFalseTotal
$meth && $meth eq 'relative' ? : 2 9 11
Condition80%4/5
$meth and $meth eq "relative"
!ll&&!rl&&r
812
$hsl->{'l'} || \'1'
l!l
02
MC/DC100%2/2
$meth and $meth eq "relative"
$meth $meth eq "relative"
MC/DC0%0/1
$hsl->{'l'} || \'1'
$hsl->{'l'}
Truth table100%3/3
A and B
A= $methB= $meth eq "relative"
ABresult
0X0
100
111
Truth table50%1/2
A
A= $hsl->{'l'}
Aresult
11
00
266 : $amt, 1
267 );
268  
269 11 return $colour->hsla( $TOOL{hash2array}( $hsl, 'h', 's', 'l', 'a' ) );
270 }
271  
272 12 ▶sub darken {
Subroutine darken: called CC=3 SCAR=11.0
Pod documented
273 12 my ( $colour, $amt, $meth, $hsl ) = @_;
274  
275 12 ( $hsl, $colour ) = $TOOL{hsl}($colour);
276  
277 12 $amt = $TOOL{depercent}($amt);
278 $hsl->{l} -= $TOOL{clamp}(
279 ( $meth && $meth eq 'relative' )
280 12 ▶ ? $hsl->{l} * $amt
Branch: 1 branch
BranchTrueFalseTotal
$meth && $meth eq 'relative' ? : 1 11 12
Condition100%3/3
$meth and $meth eq "relative"
!ll&&!rl&&r
1011
MC/DC100%2/2
$meth and $meth eq "relative"
$meth $meth eq "relative"
Truth table100%3/3
A and B
A= $methB= $meth eq "relative"
ABresult
0X0
100
111
281 : $amt, 1,
282 );
283  
284 12 return $colour->hsla( $TOOL{hash2array}( $hsl, 'h', 's', 'l', 'a' ) );
285 }
286  
287 12 ▶sub fade {
Subroutine fade: called CC=1 SCAR=0.0
Pod documented
288 12 my ($colour, $amt, $hsl) = @_;
289  
290 12 ($hsl, $colour) = $TOOL{hsl}($colour);
291 12 $hsl->{a} = $TOOL{depercent}($amt);
292  
293 12 return $colour->hsla( $TOOL{hash2array}( $hsl, 'h', 's', 'l', 'a' ) );
294 }
295  
296 14 ▶sub fadeout {
Subroutine fadeout: called CC=3 SCAR=11.0
Pod documented
297 14 my ($colour, $amt, $meth, $hsl) = @_;
298  
299 14 ($hsl, $colour) = $TOOL{hsl}($colour);
300 $hsl->{a} -= (($meth && $meth eq 'relative')
301 ? $hsl->{a} * $TOOL{depercent}($amt)
302 14 ▶ : $TOOL{depercent}($amt));
Branch: 1 branch
BranchTrueFalseTotal
$meth && $meth eq 'relative' ? : 1 13 14
Condition100%3/3
$meth and $meth eq "relative"
!ll&&!rl&&r
1211
MC/DC100%2/2
$meth and $meth eq "relative"
$meth $meth eq "relative"
Truth table100%3/3
A and B
A= $methB= $meth eq "relative"
ABresult
0X0
100
111
303 14 return $colour->hsla( $TOOL{hash2array}( $hsl, 'h', 's', 'l', 'a' ) );
304 }
305  
306 14 ▶sub fadein {
Subroutine fadein: called CC=3 SCAR=11.0
Pod documented
307 14 my ($colour, $amt, $meth, $hsl) = @_;
308 14 ($hsl, $colour) = $TOOL{hsl}($colour);
309 $hsl->{a} += ($meth && $meth eq 'relative')
310 ? $hsl->{a} * $TOOL{depercent}($amt)
311 14 ▶ : $TOOL{depercent}($amt);
Branch: 1 branch
BranchTrueFalseTotal
$meth && $meth eq 'relative' ? : 1 13 14
Condition100%3/3
$meth and $meth eq "relative"
!ll&&!rl&&r
1211
MC/DC100%2/2
$meth and $meth eq "relative"
$meth $meth eq "relative"
Truth table100%3/3
A and B
A= $methB= $meth eq "relative"
ABresult
0X0
100
111
312 14 $hsl->{a} = smallnum::_smallnum($hsl->{a});
313 14 return $colour->hsla( $TOOL{hash2array}( $hsl, 'h', 's', 'l', 'a' ) );
314 }
315  
316 0 ▶sub mix {
Subroutine mix: not called CC=3 SCAR=24.8
Pod documented
317 0 my ($colour1, $colour2, $weight) = @_;
318 0 my ($h1, $c1, $h2, $c2) = ($TOOL{hsl}($colour1), $TOOL{hsl}($colour2));
319 0 ▶ $weight = ($weight || 50) / 100;
Condition0%0/2
$weight || \'50'
l!l
00
MC/DC0%0/1
$weight || \'50'
$weight
Truth table0%0/2
A
A= $weight
Aresult
11
00
320 0 my $a = $h1->{a} - $h2->{a};
321 0 my $w = ($weight * 2) - 1;
322 0 ▶ my $w1 = ((($w * $a == -1) ? $w : ($w + $a) / (1 + $w * $a)) + 1) / 2;
Branch: 1 branch
BranchTrueFalseTotal
$w * $a == -1.0 ? : 0 0 0
323 0 my $w2 = 1 - $w1;
324 return Colouring::In->new([
325 ($c1->{colour}[0] * $w1) + ($c2->{colour}[0] * $w2),
326 ($c1->{colour}[1] * $w1) + ($c2->{colour}[1] * $w2),
327 ($c1->{colour}[2] * $w1) + ($c2->{colour}[2] * $w2),
328 0 ($c1->{alpha} * $weight) + ($c2->{alpha} * 1 - $weight)
329 ]);
330 }
331  
332 0 ▶sub tint {
Subroutine tint: not called CC=1 SCAR=6.9
Pod documented
333 0 my ($colour, $weight) = @_;
334 0 mix(
335 'rgb(255,255,255)',
336 $colour,
337 $weight
338 );
339 }
340  
341 0 ▶sub shade {
Subroutine shade: not called CC=1 SCAR=6.9
Pod documented
342 0 my ($colour, $weight) = @_;
343 0 mix(
344 'rgb(0, 0, 0)',
345 $colour,
346 $weight
347 );
348 }
349  
350 0 ▶sub saturate {
Subroutine saturate: not called CC=3 SCAR=24.8
Pod documented
351 0 my ($colour, $amt, $meth) = @_;
352 0 my ($h1, $c1) = $TOOL{hsl}($colour);
353 0 $amt = $TOOL{depercent}($amt);
354 $h1->{s} += $TOOL{clamp}(
355 ( $meth && $meth eq 'relative' )
356 0 ▶ ? $h1->{s} * $amt
Branch: 1 branch
BranchTrueFalseTotal
$meth && $meth eq 'relative' ? : 0 0 0
Condition0%0/3
$meth and $meth eq "relative"
!ll&&!rl&&r
000
MC/DC0%0/2
$meth and $meth eq "relative"
$meth $meth eq "relative"
Truth table0%0/3
A and B
A= $methB= $meth eq "relative"
ABresult
0X0
100
111
357 : $amt, 1,
358 );
359 0 return $c1->hsla( $TOOL{hash2array}( $h1, 'h', 's', 'l', 'a' ) );
360 }
361  
362 0 ▶sub desaturate {
Subroutine desaturate: not called CC=3 SCAR=24.8
Pod documented
363 0 my ($colour, $amt, $meth) = @_;
364 0 my ($h1, $c1) = $TOOL{hsl}($colour);
365 0 $amt = $TOOL{depercent}($amt);
366 $h1->{s} -= $TOOL{clamp}(
367 ( $meth && $meth eq 'relative' )
368 0 ▶ ? $h1->{s} * $amt
Branch: 1 branch
BranchTrueFalseTotal
$meth && $meth eq 'relative' ? : 0 0 0
Condition0%0/3
$meth and $meth eq "relative"
!ll&&!rl&&r
000
MC/DC0%0/2
$meth and $meth eq "relative"
$meth $meth eq "relative"
Truth table0%0/3
A and B
A= $methB= $meth eq "relative"
ABresult
0X0
100
111
369 : $amt, 1,
370 );
371 0 return $c1->hsla( $TOOL{hash2array}( $h1, 'h', 's', 'l', 'a' ) );
372 }
373  
374 0 ▶sub greyscale {
Subroutine greyscale: not called CC=1 SCAR=6.9
Pod documented
375 0 my ($colour) = @_;
376 0 desaturate($colour, 100);
377 }
378  
379 10193 ▶sub colour {
Subroutine colour: called CC=4 SCAR=13.9
Pod documented
380 10193 my @rgb = @{ $_[0]->{colour} };
381 10193 ▶ my $r = defined $rgb[0] ? $rgb[0] : 255;
Branch: 1 branch
BranchTrueFalseTotal
defined $rgb[0] ? : 10192 1 10193
382 10193 ▶ my $g = defined $rgb[1] ? $rgb[1] : 255;
Branch: 1 branch
BranchTrueFalseTotal
defined $rgb[1] ? : 10192 1 10193
383 10193 ▶ my $b = defined $rgb[2] ? $rgb[2] : 255;
Branch: 1 branch
BranchTrueFalseTotal
defined $rgb[2] ? : 10192 1 10193
384 10193 return ( $r, $g, $b );
385 }
386  
387 4 ▶sub validate {
Subroutine validate: called CC=4 SCAR=14.0
Pod documented
388 4 my ($self, $colour) = @_;
389 4 my $new = eval { $self->new($colour) };
390 4 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 3 1 4
391 return {
392 valid => \0,
393 3 ▶ message => $TOOL{MESSAGES}{VALIDATE_ERROR} || 'The string passed to Colouring::In::validate is not a valid color.',
Condition50%1/2
$Colouring::In::TOOL{'MESSAGES'}{'VALIDATE_ERROR'} || 'The string passed to Colouring::In::validate is not a valid color.'
l!l
30
MC/DC0%0/1
$Colouring::In::TOOL{'MESSAGES'}{'VALIDATE_ERROR'} || 'The string passed to Colouring::In::validate is not a valid color.'
$Colouring::In::TOOL{'MESSAGES'}{'VALIDATE_ERROR'}
Truth table50%1/2
A
A= $Colouring::In::TOOL{'MESSAGES'}{'VALIDATE_ERROR'}
Aresult
11
00
394 color => $colour
395 };
396 }
397 return {
398 valid => \1,
399 1 ▶ message => $TOOL{MESSAGES}{VALIDATE} || 'The string passed to Colouring::In::validate is a valid color',
Condition50%1/2
$Colouring::In::TOOL{'MESSAGES'}{'VALIDATE'} || 'The string passed to Colouring::In::validate is a valid color'
l!l
10
MC/DC0%0/1
$Colouring::In::TOOL{'MESSAGES'}{'VALIDATE'} || 'The string passed to Colouring::In::validate is a valid color'
$Colouring::In::TOOL{'MESSAGES'}{'VALIDATE'}
Truth table50%1/2
A
A= $Colouring::In::TOOL{'MESSAGES'}{'VALIDATE'}
Aresult
11
00
400 color => $colour,
401 colour => $new
402 };
403 }
404  
405 13 1;
406  
407 __END__
↑ Summary