Color/Space/Format.pm

filter: Statementstmt 95.5% 173 / 181 Branchbran 82.2% 97 / 118 Conditioncond 50.0% 30 / 60 MC/DCmcdc 31.5% 12 / 38 Subroutinesub 95.3% 41 / 43 Podpod 0.0% 0 / 26 totaltotal 75.7% 353 / 466 CC 85 SCAR 16.5
CC
85
Cov
84%
tuple_from_nested_array
10.5
new
9.1
deformat
8.1
CRAP 5.2
« Color/Error.pm ↑ Summary Color/Space/Instance/HSB.pm »
1  
2 # bidirectional conversion of value tuples (ARRAY) into different string and other formats
3 # values can have color space dependant extra shape, suffixes, etc.
4  
5 package Graphics::Toolkit::Color::Space::Format;
6 50 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 50 ▶use Graphics::Toolkit::Color::Space::Util qw/number_re/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #### constructor, building attr data ###################################
11 542 ▶sub new { # -, $:Basis -- ~|@~val_form, ~|@~suffix --> :_
Subroutine new: called CC=9 SCAR=22.1
Pod undocumented
12 542 my ($pkg, $basis, $value_form, $prefix, $suffix) = @_;
13 542 ▶ return 'First argument has to be an GT::Color::Space::Basis reference !'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $basis eq "Graphics::Toolkit::Color::Space::Basis" 1 541 542
14 unless ref $basis eq 'Graphics::Toolkit::Color::Space::Basis';
15  
16 541 my $count = $basis->axis_count;
17 541 ▶ $value_form = number_re() unless defined $value_form;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value_form 522 19 541
18 541 ▶ $value_form = [($value_form) x $count] if ref $value_form ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value_form ne "ARRAY" 523 18 541
19 541 ▶ return "Definition of the value format has to be an ARRAY reference" if ref $value_form ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value_form ne "ARRAY" 0 541 541
20 541 ▶ $value_form = [ map {(defined $_ and $_) ? $_ : number_re() } @$value_form]; # fill missing defs with default
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && $_ ? : 1646 0 1646
Condition33%1/3
defined $_ and $_
!ll&&!rl&&r
001646
MC/DC0%0/2
defined $_ and $_
defined $_ $_
Truth table33%1/3
A and B
A= defined $_B= $_
ABresult
0X0
100
111
21 541 ▶ return 'Need a value form definition for every axis!' unless @$value_form == $count;
Branch: 1 branch
BranchTrueFalseTotal
unless @$value_form == $count 1 540 541
22  
23 540 $suffix = expand_suffix_def( $basis, $suffix ) ;
24 540 ▶ return $suffix unless ref $suffix;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $suffix 1 539 540
25  
26 # format --> tuple
27 2307 ▶ my %deformats = ( hash => sub { tuple_from_hash(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
28 2360 ▶ array => sub { [@{$_[1]}] if $_[0]->basis->is_value_tuple( $_[1] ) },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->basis->is_value_tuple($_[1]) 213 2147 2360
29 2261 ▶ named_array => sub { tuple_from_named_array(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
30 2187 ▶ nested_array => sub { tuple_from_nested_array(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
31 2214 ▶ named_string => sub { tuple_from_named_string(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
32 2323 ▶ css_string => sub { tuple_from_css_string(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
33 539 );
34 # tuple --> format
35 49 ▶ my %formats = (list => sub { (@{$_[1]}) }, # 1, 2, 3
Subroutine __ANON__: called CC=1 SCAR=0.0
36 6 ▶ array => sub { [@{$_[1]}] }, # [ 1, 2, 3 ]
Subroutine __ANON__: called CC=1 SCAR=0.0
37 4 ▶ hash => sub { $basis->long_name_hash_from_tuple($_[1]) }, # { red => 1, green => 2, blue => 3 }
Subroutine __ANON__: called CC=1 SCAR=0.0
38 3 ▶ char_hash => sub { $basis->short_name_hash_from_tuple($_[1]) }, # { r =>1, g => 2, b => 3 }
Subroutine __ANON__: called CC=1 SCAR=0.0
39 5 ▶ named_array => sub { [$basis->space_name, @{$_[1]}] }, # ['rgb',1,2,3]
Subroutine __ANON__: called CC=1 SCAR=0.0
40 0 ▶ nested_array => sub { [$basis->space_name, [@{$_[1]}]] }, # ['rgb' => [1,2,3]]
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 13 ▶ named_string => sub { $_[0]->named_string_from_tuple($_[1]) }, # 'rgb: 1, 2, 3'
Subroutine __ANON__: called CC=1 SCAR=0.0
42 42 ▶ css_string => sub { $_[0]->css_string_from_tuple($_[1]) }, # 'rgb(1,2,3)'
Subroutine __ANON__: called CC=1 SCAR=0.0
43 539 );
44 539 bless { basis => $basis, deformatter => \%deformats, formatter => \%formats,
45 value_form => $value_form, prefix => $prefix, suffix => $suffix,
46 value_numifier => { into_numeric => '', from_numeric => '' },
47 }
48 }
49  
50 1044 ▶sub expand_suffix_def {
Subroutine expand_suffix_def: called CC=5 SCAR=16.1
Pod undocumented
51 1044 my ($basis, $suffix) = @_;
52 1044 my $count = $basis->axis_count;
53 1044 ▶ $suffix = [('') x $count] unless defined $suffix;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $suffix 488 556 1044
54 1044 ▶ $suffix = [($suffix) x $count] unless ref $suffix;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $suffix 9 1035 1044
55 1044 ▶ return 'need an ARRAY as definition of axis value suffix' unless ref $suffix eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $suffix eq "ARRAY" 1 1043 1044
56 1043 ▶ return 'definition of axis value suffix has to have same lengths as basis' unless @$suffix == $count;
Branch: 1 branch
BranchTrueFalseTotal
unless @$suffix == $count 3 1040 1043
57 1040 return $suffix;
58 }
59 2988 ▶sub get_suffix {
Subroutine get_suffix: called CC=2 SCAR=6.9
Pod undocumented
60 2988 my ($self, $suffix) = @_;
61 2988 ▶ return $self->{'suffix'} unless defined $suffix;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $suffix 2484 504 2988
62 504 expand_suffix_def( $self->{'basis'}, $suffix );
63 }
64  
65 17 ▶sub add_formatter {
Subroutine add_formatter: called CC=5 SCAR=19.4
Pod undocumented
66 17 my ($self, $format, $code) = @_;
67 17 ▶ return if not defined $format or ref $format or ref $code ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $format or ref $format or ref $code ne "CODE" 0 17 17
Condition33%2/6
not defined $format or ref $format or ref $code ne "CODE"
l!l&&r!l&&!r
0017
not defined $format or ref $format
l!l&&r!l&&!r
0017
MC/DC0%0/3
not defined $format or ref $format or ref $code ne "CODE"
not defined $format ref $format ref $code ne "CODE"
Truth table25%1/4
not(A) or B or C
A= not defined $formatB= ref $formatC= ref $code ne "CODE"
ABCresult
1XX1
01X1
0011
0000
68 17 ▶ return if $self->has_formatter( $format );
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_formatter($format) 0 17 17
69 17 $self->{'formatter'}{ lc $format } = $code;
70 }
71 17 ▶sub add_deformatter {
Subroutine add_deformatter: called CC=5 SCAR=19.4
Pod undocumented
72 17 my ($self, $format, $code) = @_;
73 17 ▶ return if not defined $format or ref $format or ref $code ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $format or ref $format or ref $code ne "CODE" 0 17 17
Condition33%2/6
not defined $format or ref $format or ref $code ne "CODE"
l!l&&r!l&&!r
0017
not defined $format or ref $format
l!l&&r!l&&!r
0017
MC/DC0%0/3
not defined $format or ref $format or ref $code ne "CODE"
not defined $format ref $format ref $code ne "CODE"
Truth table25%1/4
not(A) or B or C
A= not defined $formatB= ref $formatC= ref $code ne "CODE"
ABCresult
1XX1
01X1
0011
0000
74 17 ▶ return if $self->has_deformatter( $format );
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_deformatter($format) 0 17 17
75 17 $self->{'deformatter'}{ lc $format } = $code;
76 }
77 16 ▶sub set_value_numifier {
Subroutine set_value_numifier: called CC=3 SCAR=12.0
Pod undocumented
78 16 my ($self, $pre_code, $post_code) = @_;
79 16 ▶ return 0 if ref $pre_code ne 'CODE' or ref $post_code ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $pre_code ne "CODE" or ref $post_code ne "CODE" 0 16 16
Condition33%1/3
ref $pre_code ne "CODE" or ref $post_code ne "CODE"
l!l&&r!l&&!r
0016
MC/DC0%0/2
ref $pre_code ne "CODE" or ref $post_code ne "CODE"
ref $pre_code ne "CODE" ref $post_code ne "CODE"
Truth table33%1/3
A or B
A= ref $pre_code ne "CODE"B= ref $post_code ne "CODE"
ABresult
1X1
011
000
80 16 $self->{'value_numifier'}{'into_numeric'} = $pre_code;
81 16 $self->{'value_numifier'}{'from_numeric'} = $post_code;
82 }
83  
84 #### public API: formatting value tuples ###############################
85 9583 ▶sub basis { $_[0]{'basis'}}
Subroutine basis: called CC=1 SCAR=0.0
Pod undocumented
86 169 ▶sub has_formatter { (defined $_[1] and exists $_[0]{'formatter'}{ lc $_[1] }) ? 1 : 0 }
Subroutine has_formatter: called CC=3 SCAR=11.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] && exists $_[0]{'formatter'}{lc $_[1]} ? : 139 30 169
Condition100%3/3
defined $_[1] and exists $_[0]{"formatter"}{lc $_[1]}
!ll&&!rl&&r
129139
MC/DC100%2/2
defined $_[1] and exists $_[0]{"formatter"}{lc $_[1]}
defined $_[1] exists $_[0]{"formatter"}{lc $_[1]}
Truth table100%3/3
A and B
A= defined $_[1]B= exists $_[0]{"formatter"}{lc $_[1]}
ABresult
0X0
100
111
87 19 ▶sub has_deformatter { (defined $_[1] and exists $_[0]{'deformatter'}{ lc $_[1] }) ? 1 : 0 }
Subroutine has_deformatter: called CC=3 SCAR=11.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] && exists $_[0]{'deformatter'}{lc $_[1]} ? : 1 18 19
Condition66%2/3
defined $_[1] and exists $_[0]{"deformatter"}{lc $_[1]}
!ll&&!rl&&r
0181
MC/DC50%1/2
defined $_[1] and exists $_[0]{"deformatter"}{lc $_[1]}
defined $_[1] exists $_[0]{"deformatter"}{lc $_[1]}
Truth table66%2/3
A and B
A= defined $_[1]B= exists $_[0]{"deformatter"}{lc $_[1]}
ABresult
0X0
100
111
88  
89 2360 ▶sub deformat { # check if color definition can be rad by any available formats of this space
Subroutine deformat: called CC=8 SCAR=20.9
Pod undocumented
90 2360 my ($self, $color_def, $suffix) = @_;
91 2360 ▶ return undef unless defined $color_def;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $color_def 0 2360 2360
92 2360 $suffix = $self->get_suffix( $suffix );
93 2360 ▶ return $suffix unless ref $suffix;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $suffix 0 2360 2360
94 2360 for my $format_name (sort keys %{$self->{'deformatter'}}){
95 13777 my $deformatter = $self->{'deformatter'}{$format_name};
96 13777 my $tuple = $deformatter->( $self, $color_def );
97 13777 ▶ next unless ref $tuple;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tuple 13416 361 13777
98 361 $tuple = $self->trim_tuple( $tuple ); # remove space
99 361 $tuple = $self->remove_suffix( $tuple, $suffix );
100 361 ▶ next unless $self->are_tuple_numbers_well_formatted( $tuple );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->are_tuple_numbers_well_formatted($tuple) 187 174 361
101 174 $tuple = $self->numify_values( $tuple );
102 174 ▶ next unless $self->basis->is_number_tuple( $tuple );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->basis->is_number_tuple($tuple) 0 174 174
103 174 ▶ return wantarray ? ($tuple, $format_name) : $tuple;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 145 29 174
104 }
105 2186 return undef;
106 }
107 144 ▶sub format { # format tuple into color definition of this space
Subroutine format: called CC=4 SCAR=13.9
Pod undocumented
108 144 my ($self, $tuple, $format, $suffix, $prefix) = @_;
109 144 ▶ return '' unless $self->basis->is_value_tuple( $tuple );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->basis->is_value_tuple($tuple) 0 144 144
110 144 ▶ return '' unless $self->has_formatter( $format );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_formatter($format) 9 135 144
111 135 $suffix = $self->get_suffix( $suffix );
112 135 ▶ return $suffix unless ref $suffix;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $suffix 3 132 135
113 132 $tuple = $self->denumify_values( $tuple );
114 132 $tuple = $self->add_suffix( $tuple, $suffix );
115 132 $self->{'formatter'}{ lc $format }->($self, $tuple);
116 }
117  
118 #### work methods ######################################################
119 361 ▶sub trim_tuple {
Subroutine trim_tuple: called CC=3 SCAR=11.0
Pod undocumented
120 361 my ($self, $dirty_tuple) = @_;
121 361 ▶ return unless $self->basis->is_value_tuple( $dirty_tuple );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->basis->is_value_tuple($dirty_tuple) 1 360 361
122 360 my $tuple = [@$dirty_tuple];
123 360 $tuple->[$_] =~tr/ //d for $self->basis->axis_iterator;
124 360 return $tuple;
125 }
126  
127 362 ▶sub remove_suffix { # and unnecessary white space and remove special number formats
Subroutine remove_suffix: called CC=7 SCAR=19.5
Pod undocumented
128 362 my ($self, $tuple, $suffix) = @_;
129 362 ▶ return unless $self->basis->is_value_tuple( $tuple );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->basis->is_value_tuple($tuple) 1 361 362
130 361 $suffix = $self->get_suffix( $suffix );
131 361 ▶ return $suffix unless ref $suffix;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $suffix 0 361 361
132 361 $tuple = [@$tuple]; # loose ref and side effects
133 361 for my $axis_index ($self->basis->axis_iterator){
134 1109 ▶ next unless $suffix->[ $axis_index ];
Branch: 1 branch
BranchTrueFalseTotal
unless $suffix->[$axis_index] 982 127 1109
135 127 my $val_length = length $tuple->[ $axis_index ];
136 127 my $suf_length = length $suffix->[ $axis_index ];
137 127 ▶ $tuple->[$axis_index] = substr($tuple->[$axis_index], 0, $val_length - $suf_length)
Branch: 1 branch
BranchTrueFalseTotal
if substr($tuple->[$axis_index], -$suf_length) eq $suffix->[$axis_index] and substr($tuple->[$axis_index], -($suf_length + 1), 1) ne " " 66 61 127
Condition66%2/3
substr($tuple->[$axis_index], -$suf_length) eq $suffix->[$axis_index] and substr($tuple->[$axis_index], -($suf_length + 1), 1) ne " "
!ll&&!rl&&r
61066
MC/DC50%1/2
substr($tuple->[$axis_index], -$suf_length) eq $suffix->[$axis_index] and substr($tuple->[$axis_index], -($suf_length + 1), 1) ne " "
substr($tuple->[$axis_index], -$suf_length) eq $suffix->[$axis_index] substr($tuple->[$axis_index], -($suf_length + 1), 1) ne " "
Truth table66%2/3
A and B
A= substr($tuple->[$axis_index], -$suf_length) eq $suffix->[$axis_index]B= substr($tuple->[$axis_index], -($suf_length + 1), 1) ne " "
ABresult
0X0
100
111
138 if substr( $tuple->[$axis_index], - $suf_length) eq $suffix->[ $axis_index ]
139 and substr( $tuple->[$axis_index], - ($suf_length+1),1) ne ' ';
140 }
141 361 return $tuple;
142 }
143 132 ▶sub add_suffix {
Subroutine add_suffix: called CC=6 SCAR=18.2
Pod undocumented
144 132 my ($self, $tuple, $suffix) = @_;
145 132 ▶ return unless $self->basis->is_value_tuple( $tuple );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->basis->is_value_tuple($tuple) 0 132 132
146 132 $suffix = $self->get_suffix( $suffix );
147 132 ▶ return $suffix unless ref $suffix; # tuple or error message
Branch: 1 branch
BranchTrueFalseTotal
unless ref $suffix 0 132 132
148 132 $tuple = [@$tuple]; # loose ref and side effects
149 132 for my $axis_index ($self->basis->axis_iterator){
150 402 ▶ next unless $suffix->[ $axis_index ];
Branch: 1 branch
BranchTrueFalseTotal
unless $suffix->[$axis_index] 379 23 402
151 23 my $val_length = length $tuple->[ $axis_index ];
152 23 my $suf_length = length $suffix->[ $axis_index ];
153 23 ▶ $tuple->[$axis_index] .= $suffix->[ $axis_index ]
Branch: 1 branch
BranchTrueFalseTotal
if substr($tuple->[$axis_index], -$suf_length) ne $suffix->[$axis_index] 23 0 23
154 if substr( $tuple->[$axis_index], - $suf_length) ne $suffix->[ $axis_index ];
155 }
156 132 return $tuple;
157 }
158  
159 # works only on special value formats
160 174 ▶sub numify_values {
Subroutine numify_values: called CC=3 SCAR=11.0
Pod undocumented
161 174 my ($self, $tuple) = @_;
162 174 ▶ return $tuple unless ref $self->{'value_numifier'}{'into_numeric'};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"value_numifier"}{"into_numeric"} 165 9 174
163 9 $tuple = $self->{'value_numifier'}{'into_numeric'}->($tuple);
164 9 ▶ return $tuple if $self->basis->is_value_tuple( $tuple );
Branch: 1 branch
BranchTrueFalseTotal
if $self->basis->is_value_tuple($tuple) 9 0 9
165 }
166 132 ▶sub denumify_values {
Subroutine denumify_values: called CC=3 SCAR=11.0
Pod undocumented
167 132 my ($self, $tuple) = @_;
168 132 ▶ return $tuple unless ref $self->{'value_numifier'}{'from_numeric'};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"value_numifier"}{"from_numeric"} 128 4 132
169 4 $tuple = $self->{'value_numifier'}{'from_numeric'}->($tuple);
170 4 ▶ return $tuple if $self->basis->is_value_tuple( $tuple );
Branch: 1 branch
BranchTrueFalseTotal
if $self->basis->is_value_tuple($tuple) 4 0 4
171 }
172  
173 361 ▶sub are_tuple_numbers_well_formatted { # custom or normal
Subroutine are_tuple_numbers_well_formatted: called CC=5 SCAR=16.1
Pod undocumented
174 361 my ($self, $tuple) = @_;
175 361 ▶ return 0 if ref $tuple ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $tuple ne "ARRAY" 1 360 361
176 360 ▶ return 0 if @$tuple != $self->basis->axis_count;
Branch: 1 branch
BranchTrueFalseTotal
if @$tuple != $self->basis->axis_count 0 360 360
177 360 my @re = $self->get_value_regex();
178 360 for my $axis_index ($self->basis->axis_iterator){
179 817 ▶ return 0 unless $tuple->[$axis_index] =~ /^$re[$axis_index]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tuple->[$axis_index] =~ /^$re[$axis_index]$/u 186 631 817
180 }
181 174 return 1;
182 }
183  
184 360 ▶sub get_value_regex {
Subroutine get_value_regex: called CC=1 SCAR=0.0
Pod undocumented
185 360 my ($self) = @_;
186 360 map {'\s*('.$self->{'value_form'}[$_].'(?:'.quotemeta($self->{'suffix'}[$_]).')?)\s*' } # quotemeta
187 $self->basis->axis_iterator;
188 }
189  
190 #### converter: format --> values ######################################
191 2214 ▶sub tuple_from_named_string {
Subroutine tuple_from_named_string: called CC=6 SCAR=18.0
Pod undocumented
192 2214 my ($self, $string) = @_;
193 2214 ▶ return 0 unless defined $string and not ref $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string and not ref $string 1602 612 2214
Condition66%2/3
defined $string and not ref $string
!ll&&!rl&&r
01602612
MC/DC50%1/2
defined $string and not ref $string
defined $string not ref $string
Truth table66%2/3
A and not(B)
A= defined $stringB= not ref $string
ABresult
0X0
100
111
194 612 $string =~ /^\s*([^ :]+):\s*(\s*[^:]+)\s*$/i;
195 612 my $space_name = $1;
196 612 my $tuple_string = $2;
197 612 ▶ return 0 unless $self->{'basis'}->is_name( $space_name ) and $tuple_string;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"basis"}->is_name($space_name) and $tuple_string 582 30 612
Condition66%2/3
$self->{"basis"}->is_name($space_name) and $tuple_string
!ll&&!rl&&r
582030
MC/DC50%1/2
$self->{"basis"}->is_name($space_name) and $tuple_string
$self->{"basis"}->is_name($space_name) $tuple_string
Truth table66%2/3
A and B
A= $self->{"basis"}->is_name($space_name)B= $tuple_string
ABresult
0X0
100
111
198 30 local $/ = ' ';
199 30 chomp $tuple_string;
200 30 ▶ return [split(/\s*,\s*/, $tuple_string)] if index($tuple_string, ',') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($tuple_string, ",") != -1 29 1 30
201 1 return [split(/\s+/, $tuple_string)];
202 }
203 2323 ▶sub tuple_from_css_string {
Subroutine tuple_from_css_string: called CC=6 SCAR=18.0
Pod undocumented
204 2323 my ($self, $string) = @_;
205 2323 ▶ return 0 unless defined $string and not ref $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string and not ref $string 1681 642 2323
Condition66%2/3
defined $string and not ref $string
!ll&&!rl&&r
01681642
MC/DC50%1/2
defined $string and not ref $string
defined $string not ref $string
Truth table66%2/3
A and not(B)
A= defined $stringB= not ref $string
ABresult
0X0
100
111
206 642 $string =~ /^\s*([^()]+)\(\s*([^()]+)\s*\)\s*$/i;
207 642 my $space_name = $1;
208 642 my $tuple_string = $2;
209 642 ▶ return 0 unless $self->{'basis'}->is_name( $space_name ) and $tuple_string;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"basis"}->is_name($space_name) and $tuple_string 623 19 642
Condition66%2/3
$self->{"basis"}->is_name($space_name) and $tuple_string
!ll&&!rl&&r
623019
MC/DC50%1/2
$self->{"basis"}->is_name($space_name) and $tuple_string
$self->{"basis"}->is_name($space_name) $tuple_string
Truth table66%2/3
A and B
A= $self->{"basis"}->is_name($space_name)B= $tuple_string
ABresult
0X0
100
111
210 19 local $/ = ' ';
211 19 chomp $tuple_string;
212 19 ▶ return [split(/\s*,\s*/, $tuple_string)] if index($tuple_string, ',') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($tuple_string, ",") != -1 17 2 19
213 2 return [split(/\s+/, $tuple_string)];
214 }
215 2261 ▶sub tuple_from_named_array {
Subroutine tuple_from_named_array: called CC=7 SCAR=19.5
Pod undocumented
216 2261 my ($self, $array) = @_;
217 2261 ▶ return 0 if ref $array ne 'ARRAY' or not @$array;
Branch: 1 branch
BranchTrueFalseTotal
if ref $array ne "ARRAY" or not @$array 1077 1184 2261
Condition66%2/3
ref $array ne "ARRAY" or not @$array
l!l&&r!l&&!r
107701184
MC/DC50%1/2
ref $array ne "ARRAY" or not @$array
ref $array ne "ARRAY" not @$array
Truth table66%2/3
A or not(B)
A= ref $array ne "ARRAY"B= not @$array
ABresult
1X1
011
000
218 1184 ▶ return 0 unless $self->basis->is_name( $array->[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->basis->is_name($array->[0]) 1132 52 1184
219 52 $array = [@$array[1 .. $#$array]];
220 52 ▶ $array = $array->[0] if @$array == 1 and ref $array->[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if @$array == 1 and ref $array->[0] eq "ARRAY" 5 47 52
Condition66%2/3
@$array == 1 and ref $array->[0] eq "ARRAY"
!ll&&!rl&&r
4705
MC/DC50%1/2
@$array == 1 and ref $array->[0] eq "ARRAY"
@$array == 1 ref $array->[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @$array == 1B= ref $array->[0] eq "ARRAY"
ABresult
0X0
100
111
221 52 ▶ return 0 unless @$array == $self->basis->axis_count;
Branch: 1 branch
BranchTrueFalseTotal
unless @$array == $self->basis->axis_count 5 47 52
222 47 return $array;
223 }
224 2187 ▶sub tuple_from_nested_array {
Subroutine tuple_from_nested_array: called CC=6 SCAR=23.5
Pod undocumented
225 2187 my ($self, $array) = @_;
226 2187 ▶ return 0 if ref $array ne 'ARRAY' or @$array != 2;
Branch: 1 branch
BranchTrueFalseTotal
if ref $array ne "ARRAY" or @$array != 2 1718 469 2187
Condition100%3/3
ref $array ne "ARRAY" or @$array != 2
l!l&&r!l&&!r
1050668469
MC/DC100%2/2
ref $array ne "ARRAY" or @$array != 2
ref $array ne "ARRAY" @$array != 2
Truth table100%3/3
A or B
A= ref $array ne "ARRAY"B= @$array != 2
ABresult
1X1
011
000
227 469 ▶ return 0 unless $self->basis->is_name( $array->[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->basis->is_name($array->[0]) 469 0 469
228 0 $array = $array->[1];
229 0 ▶ return 0 if ref $array ne 'ARRAY' or @$array != $self->basis->axis_count;
Branch: 1 branch
BranchTrueFalseTotal
if ref $array ne "ARRAY" or @$array != $self->basis->axis_count 0 0 0
Condition0%0/3
ref $array ne "ARRAY" or @$array != $self->basis->axis_count
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $array ne "ARRAY" or @$array != $self->basis->axis_count
ref $array ne "ARRAY" @$array != $self->basis->axis_count
Truth table0%0/3
A or B
A= ref $array ne "ARRAY"B= @$array != $self->basis->axis_count
ABresult
1X1
011
000
230 0 return [@$array];
231 }
232 2307 ▶sub tuple_from_hash {
Subroutine tuple_from_hash: called CC=2 SCAR=6.9
Pod undocumented
233 2307 my ($self, $hash) = @_;
234 2307 ▶ return 0 unless $self->basis->is_hash($hash);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->basis->is_hash($hash) 2270 37 2307
235 37 $self->basis->tuple_from_hash( $hash );
236 }
237  
238 #### converter: values --> format ######################################
239 0 ▶sub named_array_from_tuple {
Subroutine named_array_from_tuple: not called CC=2 SCAR=17.9
Pod undocumented
240 0 my ($self, $tuple, $name) = @_;
241 0 ▶ $name //= $self->basis->space_name(undef, 'given');
Condition0%0/3
$name //= $self->basis->space_name(undef, "given")
l!l&&r!l&&!r
000
MC/DC0%0/2
$name //= $self->basis->space_name(undef, "given")
$name $self->basis->space_name(undef, "given")
Truth table0%0/3
A //= B
A= $nameB= $self->basis->space_name(undef, "given")
ABresult
1X1
011
000
242 0 return [$name, @$tuple];
243 }
244 13 ▶sub named_string_from_tuple {
Subroutine named_string_from_tuple: called CC=2 SCAR=7.6
Pod undocumented
245 13 my ($self, $tuple, $name) = @_;
246 13 ▶ $name //= $self->basis->space_name(undef, 'given');
Condition33%1/3
$name //= $self->basis->space_name(undef, "given")
l!l&&r!l&&!r
0130
MC/DC0%0/2
$name //= $self->basis->space_name(undef, "given")
$name $self->basis->space_name(undef, "given")
Truth table33%1/3
A //= B
A= $nameB= $self->basis->space_name(undef, "given")
ABresult
1X1
011
000
247 13 return lc($name).': '.join(', ', @$tuple);
248 }
249 42 ▶sub css_string_from_tuple {
Subroutine css_string_from_tuple: called CC=2 SCAR=7.6
Pod undocumented
250 42 my ($self, $tuple, $name) = @_;
251 42 ▶ $name //= $self->basis->space_name(undef, 'given');
Condition33%1/3
$name //= $self->basis->space_name(undef, "given")
l!l&&r!l&&!r
0420
MC/DC0%0/2
$name //= $self->basis->space_name(undef, "given")
$name $self->basis->space_name(undef, "given")
Truth table33%1/3
A //= B
A= $nameB= $self->basis->space_name(undef, "given")
ABresult
1X1
011
000
252 42 return lc($name).'('.join(', ', @$tuple).')';
253 }
254  
255 50 1;
« Color/Error.pm ↑ Summary Color/Space/Instance/HSB.pm »