| 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
Condition100%4/4
$_[0] || \'0'
$_[1] || \'0'
MC/DC100%1/1
$_[0] || \'0'
$_[0]
MC/DC100%1/1
$_[1] || \'0'
$_[1]
Truth table100%2/2
A
A= $_[0]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 30728 | ▶ | min => sub { $_[ ($_[0] || 0) > ($_[1] || 0) ] || 0 }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
Condition100%4/4
$_[0] || \'0'
$_[1] || \'0'
MC/DC100%1/1
$_[0] || \'0'
$_[0]
MC/DC100%1/1
$_[1] || \'0'
$_[1]
Truth table100%2/2
A
A= $_[0]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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]+/
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]+/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 30221 | ▶ | if ( $h * 6 < 1 ) { return $m1 + ( $m2 - $m1 ) * $h * 6; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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'
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_RGB'} || 'Cannot convert rgb colour format'
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition80%4/5
$_ =~ /0/ or $h
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_HEX'} || 'Cannot convert hex colour format'
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
Truth table50%1/2
A
A= $Colouring::In::TOOL{'MESSAGES'}{'INVALID_HEX'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition40%2/5
$_ =~ /00/ or $h
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_HEX'} || 'Cannot convert hex colour format'
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
Truth table0%0/2
A
A= $Colouring::In::TOOL{'MESSAGES'}{'INVALID_HEX'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 10074 | ▶ | defined $_ && $_ =~ m/([0-9.]+)/ or die $TOOL{MESSAGES}{INVALID_HSL} || 'Cannot convert hsl colour format' for ($h, $s, $l); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
defined $_ and $_ =~ /([0-9.]+)/
$Colouring::In::TOOL{'MESSAGES'}{'INVALID_HSL'} || 'Cannot convert hsl colour format'
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.]+)/
Truth table50%1/2
A
A= $Colouring::In::TOOL{'MESSAGES'}{'INVALID_HSL'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 10073 | $h = ( $h % 360 ) / 360; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 10073 | ▶ | unless ($m1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 7 | ▶ | $h = ( $max == $r ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 13 | ▶ | if (scalar @exports) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 78 | ▶ | scalar @$rgb == 4 and $a = pop @$rgb; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 10139 | ▶ | $self->{alpha} = $TOOL{numIs}($a) ? $a : 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$Colouring::In::TOOL{"numIs"}->($_[bless( do{\(my $o = 1)}, 'smallnum' )]) and $_[1] != bless( do{\(my $o = 1)}, 'smallnum' )
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' )
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 23 | ▶ | if ( $colour =~ /#(.)\1(.)\2(.)\3/g ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 8 | ▶ | if ( $max == $min ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | $h = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 6 | ▶ | $h = ( $max == $r ) ? ( $g - $b ) / $d + ( $g < $b ? 6 : 0 ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition80%4/5
$meth and $meth eq "relative"
$hsl->{'l'} || \'1'
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"
Truth table50%1/2
A
A= $hsl->{'l'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$meth and $meth eq "relative"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$meth and $meth eq "relative"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$meth and $meth eq "relative"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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'
MC/DC0%0/1
$weight || \'50'
$weight
Truth table0%0/2
A
A= $weight
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$meth and $meth eq "relative"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$meth and $meth eq "relative"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 10193 | ▶ | my $g = defined $rgb[1] ? $rgb[1] : 255; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 10193 | ▶ | my $b = defined $rgb[2] ? $rgb[2] : 255; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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.'
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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'
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | color => $colour, | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | colour => $new | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||