Color/Space/Instance/RGB.pm

filter: Statementstmt 100% 17 / 17 Branchbran 100% 4 / 4 Conditioncond 93.3% 14 / 15 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 91.8% 45 / 49 CC 8 SCAR 17.4
CC
8
Cov
97%
tuple_from_hex
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.7
« Color/Name/Scheme.pm ↑ Summary Color/Space/Instance/HSV.pm »
1  
2 # sRGB color space IEC 61966-2-1 with two special formats: hex_string and array
3  
4 package Graphics::Toolkit::Color::Space::Instance::RGB;
5 16 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Graphics::Toolkit::Color::Space;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 ▶sub hex_from_tuple { uc sprintf("#%02x%02x%02x", @{$_[1]} ) } # translate [ r, g, b ] --> #000000
Subroutine hex_from_tuple: called CC=1 SCAR=0.0
Pod undocumented
10 124 ▶sub tuple_from_hex { # translate #000000 or #000 --> [ r, g, b ]
Subroutine tuple_from_hex: called CC=8 SCAR=20.8
Pod undocumented
11 124 my ($self, $hex) = @_;
12 124 ▶ return "hex color definition '$hex' has to start with # followed by 3 or 6 hex characters (0-9,a-f)"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hex and not ref $hex and length $hex == 4 || length $hex == 7 and substr($hex, 0, 1) eq "#" and $hex =~ /^#[\da-f]+$/iu 110 14 124
Condition93%14/15
defined $hex and not ref $hex and length $hex == 4 || length $hex == 7 and substr($hex, 0, 1) eq "#" and $hex =~ /^#[\da-f]+$/iu
!ll&&!rl&&r
108214
defined $hex and not ref $hex and length $hex == 4 || length $hex == 7 and substr($hex, 0, 1) eq "#"
!ll&&!rl&&r
106216
defined $hex and not ref $hex and length $hex == 4 || length $hex == 7
!ll&&!rl&&r
812518
defined $hex and not ref $hex
!ll&&!rl&&r
08143
length $hex == 4 or length $hex == 7
l!l&&r!l&&!r
51325
MC/DC83%5/6
defined $hex and not ref $hex and length $hex == 4 || length $hex == 7 and substr($hex, 0, 1) eq "#" and $hex =~ /^#[\da-f]+$/iu
defined $hex not ref $hex length $hex == 4 length $hex == 7 substr($hex, 0, 1) eq "#" $hex =~ /^#[\da-f]+$/iu
Truth table88%8/9
A and not(B) and C or D and E and F
A= defined $hexB= not ref $hexC= length $hex == 4D= length $hex == 7E= substr($hex, 0, 1) eq "#"F= $hex =~ /^#[\da-f]+$/iu
ABCDEFresult
0XXXXX0
10XXXX0
1100XX0
111X0X0
11010X0
111X100
1101100
111X111
1101111
13 unless defined $hex and not ref $hex
14 and (length($hex) == 4 or length($hex) == 7)
15 and substr($hex, 0, 1) eq '#' and $hex =~ /^#[\da-f]+$/i;
16 # ($_[0] =~ /^#[[:xdigit:]]{3}$/ or $_[0] =~ /^#[[:xdigit:]]{6}$/)
17 14 $hex = substr $hex, 1;
18 9 [(length $hex == 3) ? (map { hex($_.$_) } unpack( "a1 a1 a1", $hex))
19 14 ▶ : (map { hex($_ ) } unpack( "a2 a2 a2", $hex))];
Branch: 1 branch
BranchTrueFalseTotal
length $hex == 3 ? : 3 11 14
20 }
21  
22 16 Graphics::Toolkit::Color::Space->new (
23 alias_name => 'SRGB', # standard RGB, name is RGB
24 family => 'RGB',
25 axis => [qw/red green blue/],
26 range => 255,
27 precision => 0,
28 format => { 'hex_string' => [\&hex_from_tuple, \&tuple_from_hex],}
29 );
« Color/Name/Scheme.pm ↑ Summary Color/Space/Instance/HSV.pm »