| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 541 | ▶ | $value_form = [($value_form) x $count] if ref $value_form ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 541 | ▶ | return "Definition of the value format has to be an ARRAY reference" if ref $value_form ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 541 | ▶ | $value_form = [ map {(defined $_ and $_) ? $_ : number_re() } @$value_form]; # fill missing defs with default | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_ and $_
MC/DC0%0/2
defined $_ and $_
defined $_
$_
Truth table33%1/3
A and B
A= defined $_B= $_
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 541 | ▶ | return 'Need a value form definition for every axis!' unless @$value_form == $count; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 540 | $suffix = expand_suffix_def( $basis, $suffix ) ; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 540 | ▶ | return $suffix unless ref $suffix; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1044 | ▶ | $suffix = [($suffix) x $count] unless ref $suffix; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1044 | ▶ | return 'need an ARRAY as definition of axis value suffix' unless ref $suffix eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 1043 | ▶ | return 'definition of axis value suffix has to have same lengths as basis' unless @$suffix == $count; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
not defined $format or ref $format or ref $code ne "CODE"
not defined $format or ref $format
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 17 | ▶ | return if $self->has_formatter( $format ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
not defined $format or ref $format or ref $code ne "CODE"
not defined $format or ref $format
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 17 | ▶ | return if $self->has_deformatter( $format ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
ref $pre_code ne "CODE" or ref $post_code ne "CODE"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $_[1] and exists $_[0]{"formatter"}{lc $_[1]}
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]}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $_[1] and exists $_[0]{"deformatter"}{lc $_[1]}
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]}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 2360 | $suffix = $self->get_suffix( $suffix ); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 2360 | ▶ | return $suffix unless ref $suffix; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 174 | $tuple = $self->numify_values( $tuple ); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 174 | ▶ | next unless $self->basis->is_number_tuple( $tuple ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 174 | ▶ | return wantarray ? ($tuple, $format_name) : $tuple; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 144 | ▶ | return '' unless $self->has_formatter( $format ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 135 | $suffix = $self->get_suffix( $suffix ); | |||||||||||||||||||||||||||||||||||||||||
| 112 | 135 | ▶ | return $suffix unless ref $suffix; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 361 | $suffix = $self->get_suffix( $suffix ); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 361 | ▶ | return $suffix unless ref $suffix; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
substr($tuple->[$axis_index], -$suf_length) eq $suffix->[$axis_index] and substr($tuple->[$axis_index], -($suf_length + 1), 1) ne " "
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 " "
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 132 | $suffix = $self->get_suffix( $suffix ); | |||||||||||||||||||||||||||||||||||||||||
| 147 | 132 | ▶ | return $suffix unless ref $suffix; # tuple or error message | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 9 | $tuple = $self->{'value_numifier'}{'into_numeric'}->($tuple); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 9 | ▶ | return $tuple if $self->basis->is_value_tuple( $tuple ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | $tuple = $self->{'value_numifier'}{'from_numeric'}->($tuple); | |||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | ▶ | return $tuple if $self->basis->is_value_tuple( $tuple ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 360 | ▶ | return 0 if @$tuple != $self->basis->axis_count; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $string and not ref $string
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->{"basis"}->is_name($space_name) and $tuple_string
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
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 30 | local $/ = ' '; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 30 | chomp $tuple_string; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 30 | ▶ | return [split(/\s*,\s*/, $tuple_string)] if index($tuple_string, ',') > -1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $string and not ref $string
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->{"basis"}->is_name($space_name) and $tuple_string
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
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 19 | local $/ = ' '; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 19 | chomp $tuple_string; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 19 | ▶ | return [split(/\s*,\s*/, $tuple_string)] if index($tuple_string, ',') > -1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
ref $array ne "ARRAY" or not @$array
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
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 1184 | ▶ | return 0 unless $self->basis->is_name( $array->[0] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 52 | $array = [@$array[1 .. $#$array]]; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 52 | ▶ | $array = $array->[0] if @$array == 1 and ref $array->[0] eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$array == 1 and ref $array->[0] eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 52 | ▶ | return 0 unless @$array == $self->basis->axis_count; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
ref $array ne "ARRAY" or @$array != 2
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
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 469 | ▶ | return 0 unless $self->basis->is_name( $array->[0] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $array = $array->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | return 0 if ref $array ne 'ARRAY' or @$array != $self->basis->axis_count; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $array ne "ARRAY" or @$array != $self->basis->axis_count
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 42 | return lc($name).'('.join(', ', @$tuple).')'; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 50 | 1; | |||||||||||||||||||||||||||||||||||||||||