lib/Getopt/Class.pm

filter: Statementstmt 77.5% 459 / 592 Branchbran 48.5% 168 / 346 Conditioncond 37.9% 119 / 314 MC/DCmcdc 14.0% 24 / 171 Subroutinesub 80.7% 63 / 78 Podpod 94.4% 17 / 18 totaltotal 55.9% 850 / 1519 CC 304 SCAR 53.2
CC
304
Cov
60%
AUTOLOAD
922.3
init
357.8
postprocess
148.9
CRAP 204.6
↑ Summary
1 ##----------------------------------------------------------------------------
2 ## Getopt::Long with Class - ~/lib/m
3 ## Version v1.2.0
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2020/04/25
7 ## Modified 2026/07/16
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.##
12 ##----------------------------------------------------------------------------##
13 package Getopt::Class;
14 BEGIN
15 6 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶ use Clone;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶ use DateTime::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶ use DateTime::Format::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 ▶ use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 6 ▶ use Module::Generic::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 6 ▶ use Module::Generic::File qw( file );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶ use Module::Generic::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 6 our $VERSION = 'v1.2.0';
29 };
30  
31 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 sub init
35 6 ▶{
Subroutine init: called CC=79 SCAR=58.8
Pod documented
36 6 my $self = shift( @_ );
37 6 ▶ my $param = shift( @_ ) || return( $self->error( "No hash parameter was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No hash parameter was provided.'))
l!l
60
MC/DC0%0/1
shift @_ || (return $self->error('No hash parameter was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
38 6 ▶ return( $self->error( "Hash of parameters provided ($param) is not an hash reference." ) ) if( !$self->_is_hash( $param ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($param) 0 6 6
39 6 ▶ $self->SUPER::init( $param ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init($param) or return $self->pass_error 6 0 6
40 6 $self->{configured} = 0;
41 6 $self->{classes} = {};
42 6 $self->{missing} = [];
43 6 $self->{colour_open} = '<';
44 6 $self->{colour_close} = '>';
45 6 ▶ my $dict = $param->{dictionary} || return( $self->error( "No dictionary was provided to initiate Getopt::Long" ) );
Condition50%1/2
$param->{'dictionary'} || (return $self->error('No dictionary was provided to initiate Getopt::Long'))
l!l
60
MC/DC0%0/1
$param->{'dictionary'} || (return $self->error('No dictionary was provided to initiate Getopt::Long'))
$param->{'dictionary'}
Truth table50%1/2
A
A= $param->{'dictionary'}
Aresult
11
00
46 6 ▶ return( $self->error( "Dictionary provided is not a hash reference." ) ) if( !$self->_is_hash( $dict ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($dict) 0 6 6
47 6 $self->dictionary( $dict );
48
49 # Set the aliases hash reference used to contain each of the option aliases,e ach pointing to the same dictionary definition
50 6 $self->{aliases} = {};
51
52 # Tie'ing will make sure that values set for a key or its aliases are populated to other aliases
53 # Getopt::Long already does it, but this takes care of synchronising values for all aliases AFTER Getopt::Long has processed the options
54 # So that if the user change an option value using an alias:, e.g.:
55 # last_name => { type => 'string', alias => [qw( surname )] }
56 # last_name and surname would have the same value set thanks to Getopt::Long
57 # --last-name = 'Einstein';
58 # But if, after, the user does something like:
59 # $opts->{surname} = 'Doe';
60 # $opts->{last_name} would still be 'Einstein'
61 # Getopt::Class::Alias ensures the values for aliases and original key are the same seamlessly
62 # The way tie works means we must tie en empty hash, because we cannot tie an already populated hash sadly enough
63 6 my %options = ();
64 my $tie = tie( %options, 'Getopt::Class::Alias',
65 {
66 dict => $dict,
67 aliases => $self->{aliases},
68 # debug => $self->{debug}
69 6 ▶ }) || return( $self->error( "Unable to get a Getopt::Class::Alias tie object: ", Getopt::Class::Alias->error ) );
Condition50%1/2
tie(%options, 'Getopt::Class::Alias', {'dict', $dict, 'aliases', $self->{'aliases'}}) || (return $self->error('Unable to get a Getopt::Class::Alias tie object: ', 'Getopt::Class::Alias'->error))
l!l
60
MC/DC0%0/1
tie(%options, 'Getopt::Class::Alias', {'dict', $dict, 'aliases', $self->{'aliases'}}) || (return $self->error('Unable to get a Getopt::Class::Alias tie object: ', 'Getopt::Class::Alias'->error))
tie(%options, 'Getopt::Class::Alias', {'dict', $dict, 'aliases', $self->{'aliases'}})
Truth table50%1/2
A
A= tie(%options, 'Getopt::Class::Alias', {'dict', $dict, 'aliases', $self->{'aliases'}})
Aresult
11
00
70
71 6 $self->{configure_options} = [qw( no_ignore_case no_auto_abbrev auto_version auto_help )];
72 6 my $opts = \%options;
73 6 my $params = [];
74  
75 6 foreach my $k ( sort( keys( %$dict ) ) )
76 {
77 114 my $k2_dash = $k;
78 114 $k2_dash =~ tr/_/-/;
79 114 my $k2_under = $k;
80 114 $k2_under =~ tr/-/_/;
81
82 114 my $def = $dict->{ $k };
83 114 ▶ next if( $def->{__no_value_assign} );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"__no_value_assign"} 0 114 114
84  
85 # Do some pre-processing work for booleans
86 114 ▶ if( $def->{type} eq 'boolean' && !exists( $def->{mirror} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($def->{"type"} eq "boolean" and not exists $def->{"mirror"}) 42 72 114
Condition66%2/3
$def->{"type"} eq "boolean" and not exists $def->{"mirror"}
!ll&&!rl&&r
72042
MC/DC50%1/2
$def->{"type"} eq "boolean" and not exists $def->{"mirror"}
$def->{"type"} eq "boolean" not exists $def->{"mirror"}
Truth table66%2/3
A and not(B)
A= $def->{"type"} eq "boolean"B= not exists $def->{"mirror"}
ABresult
0X0
100
111
87 {
88 42 my $mirror_opt;
89 # If this is a boolean, add their counterpart, if necessary
90 42 ▶ if( substr( $k, 0, 5 ) eq 'with_' &&
Branch: 4 branches
BranchTrueFalseTotal
if (substr($k, 0, 5) eq 'with_' and not exists $$dict{'without_' . substr($k, 5)}) { } 0 42 42
elsif (substr($k, 0, 8) eq 'without_' and not exists $$dict{'with_' . substr($k, 8)}) { } 6 36 42
elsif (substr($k, 0, 7) eq 'enable_' and not exists $$dict{'disable_' . substr($k, 7)}) { } 6 30 36
elsif (substr($k, 0, 8) eq 'disable_' and not exists $$dict{'enable_' . substr($k, 8)}) { } 6 48 54
Condition33%1/3
substr($k, 0, 5) eq "with_" and not exists $$dict{'without_' . substr($k, 5)}
!ll&&!rl&&r
4200
MC/DC0%0/2
substr($k, 0, 5) eq "with_" and not exists $$dict{'without_' . substr($k, 5)}
substr($k, 0, 5) eq "with_" not exists $$dict{'without_' . substr($k, 5)}
Truth table33%1/3
A and not(B)
A= substr($k, 0, 5) eq "with_"B= not exists $$dict{'without_' . substr($k, 5)}
ABresult
0X0
100
111
91 !exists( $dict->{ 'without_' . substr( $k, 5 ) } ) )
92 {
93 0 $mirror_opt = 'without_' . substr( $k, 5 );
94 }
95 ▶ elsif( substr( $k, 0, 8 ) eq 'without_' &&
Condition66%2/3
substr($k, 0, 8) eq "without_" and not exists $$dict{'with_' . substr($k, 8)}
!ll&&!rl&&r
3606
MC/DC50%1/2
substr($k, 0, 8) eq "without_" and not exists $$dict{'with_' . substr($k, 8)}
substr($k, 0, 8) eq "without_" not exists $$dict{'with_' . substr($k, 8)}
Truth table66%2/3
A and not(B)
A= substr($k, 0, 8) eq "without_"B= not exists $$dict{'with_' . substr($k, 8)}
ABresult
0X0
100
111
96 !exists( $dict->{ 'with_' . substr( $k, 8 ) } ) )
97 {
98 6 $mirror_opt = 'with_' . substr( $k, 8 );
99 }
100 ▶ elsif( substr( $k, 0, 7 ) eq 'enable_' &&
Condition66%2/3
substr($k, 0, 7) eq "enable_" and not exists $$dict{'disable_' . substr($k, 7)}
!ll&&!rl&&r
3006
MC/DC50%1/2
substr($k, 0, 7) eq "enable_" and not exists $$dict{'disable_' . substr($k, 7)}
substr($k, 0, 7) eq "enable_" not exists $$dict{'disable_' . substr($k, 7)}
Truth table66%2/3
A and not(B)
A= substr($k, 0, 7) eq "enable_"B= not exists $$dict{'disable_' . substr($k, 7)}
ABresult
0X0
100
111
101 !exists( $dict->{ 'disable_' . substr( $k, 7 ) } ) )
102 {
103 6 $mirror_opt = 'disable_' . substr( $k, 7 );
104 }
105 ▶ elsif( substr( $k, 0, 8 ) eq 'disable_' &&
Condition66%2/3
substr($k, 0, 8) eq "disable_" and not exists $$dict{'enable_' . substr($k, 8)}
!ll&&!rl&&r
2406
MC/DC50%1/2
substr($k, 0, 8) eq "disable_" and not exists $$dict{'enable_' . substr($k, 8)}
substr($k, 0, 8) eq "disable_" not exists $$dict{'enable_' . substr($k, 8)}
Truth table66%2/3
A and not(B)
A= substr($k, 0, 8) eq "disable_"B= not exists $$dict{'enable_' . substr($k, 8)}
ABresult
0X0
100
111
106 !exists( $dict->{ 'enable_' . substr( $k, 8 ) } ) )
107 {
108 6 $mirror_opt = 'enable_' . substr( $k, 8 );
109 }
110
111 42 ▶ if( defined( $mirror_opt ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mirror_opt) 18 24 42
112 {
113 18 my $false = 0;
114 my $val = exists( $def->{default} )
115 # ? ( Scalar::Util::reftype( $def->{default} // '' ) eq 'SCALAR' || ref( $def->{default} // '' ) eq 'CODE' )
116 ? ( $self->_is_scalar( $def->{default} ) || $self->_is_code( $def->{default} ) || ref( $def->{default} ) )
117 ? $def->{default}
118 : \$def->{default}
119 : exists( $def->{code} )
120 ? $def->{code}
121 18 ▶ : \$false;
Branch: 3 branches
BranchTrueFalseTotal
exists $def->{'default'} ? : 18 0 18
$self->_is_scalar($def->{'default'}) || $self->_is_code($def->{'default'}) || ref $def->{'default'} ? : 0 18 18
exists $def->{'code'} ? : 0 0 0
Condition33%2/6
$self->_is_scalar($def->{"default"}) or $self->_is_code($def->{"default"}) or ref $def->{"default"}
l!l&&r!l&&!r
0018
$self->_is_scalar($def->{"default"}) or $self->_is_code($def->{"default"})
l!l&&r!l&&!r
0018
MC/DC0%0/3
$self->_is_scalar($def->{"default"}) or $self->_is_code($def->{"default"}) or ref $def->{"default"}
$self->_is_scalar($def->{"default"}) $self->_is_code($def->{"default"}) ref $def->{"default"}
Truth table25%1/4
A or B or C
A= $self->_is_scalar($def->{"default"})B= $self->_is_code($def->{"default"})C= ref $def->{"default"}
ABCresult
1XX1
01X1
0011
0000
122 18 my $copy = Clone::clone( $def );
123 18 $dict->{ $mirror_opt } = $copy;
124 $def->{mirror} = { name => $mirror_opt, toggle => sub
125 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
126 0 my( $value ) = @_;
127 0 $opts->{ $mirror_opt } = int( !$value );
128 18 }};
129 18 ▶ $def->{mirror}->{default} = delete( $def->{default} ) if( exists( $def->{default} ) && defined( $def->{default} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"default"} and defined $def->{"default"} 18 0 18
Condition33%1/3
exists $def->{"default"} and defined $def->{"default"}
!ll&&!rl&&r
0018
MC/DC0%0/2
exists $def->{"default"} and defined $def->{"default"}
exists $def->{"default"} defined $def->{"default"}
Truth table33%1/3
A and B
A= exists $def->{"default"}B= defined $def->{"default"}
ABresult
0X0
100
111
130 # A code is used for this boolean, so we create an anon sub that call this sub just like Getopt::Long would
131 18 ▶ if( ref( $val ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq 'CODE') { } 0 18 18
132 {
133 $copy->{mirror} = { name => $k, toggle => sub
134 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
135 0 my( $value ) = @_;
136 0 $val->( $k, int( !$value ) );
137 0 }};
138 }
139 # Otherwise, we create a sub that set the mirror value
140 else
141 {
142 $copy->{mirror} = { name => $k, toggle => sub
143 3 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
144 3 my( $value ) = @_;
145 3 $opts->{ $k } = int( !$value );
146 18 }};
147 }
148 18 ▶ $copy->{mirror}->{default} = int( !$def->{mirror}->{default} ) if( exists( $def->{mirror}->{default} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"mirror"}{"default"} 18 0 18
149 # We remove it, because they would be assigned by Getopt::Long even if not triggered and this would bother us.
150 18 delete( $def->{default} );
151 18 delete( $copy->{default} );
152 $def->{default} = sub
153 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
154 0 my( $option, $value ) = @_;
155 0 ▶ return if( $def->{mirror}->{is_set} );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"mirror"}{"is_set"} 0 0 0
156 0 $def->{mirror}->{value} = $value;
157 0 $def->{mirror}->{is_set}++;
158 0 $def->{mirror}->{toggle}->( $value );
159 18 };
160 $copy->{default} = sub
161 3 ▶ {
Subroutine __ANON__: called CC=2 SCAR=7.0
162 3 my( $option, $value ) = @_;
163 3 ▶ return if( $copy->{mirror}->{is_set} );
Branch: 1 branch
BranchTrueFalseTotal
if $copy->{"mirror"}{"is_set"} 0 3 3
164 3 $copy->{mirror}->{value} = $value;
165 3 $copy->{mirror}->{is_set}++;
166 3 $copy->{mirror}->{toggle}->( $value );
167 18 };
168 18 $def->{__no_value_assign} = 1;
169 }
170 }
171 }
172
173 # Build the options parameters
174 6 foreach my $k ( sort( keys( %$dict ) ) )
175 {
176 132 my $k2_dash = $k;
177 132 $k2_dash =~ tr/_/-/;
178 132 my $k2_under = $k;
179 132 $k2_under =~ tr/-/_/;
180
181 132 my $def = $dict->{ $k };
182
183 132 my $opt_name = [ $k2_under ];
184 # If the dictionary element is given with dash, e.g. some-thing, we replace it with some_thing, which is our standard
185 # and we set some-thing as an alias
186 132 ▶ if( CORE::index( $k, '-' ) != -1 && $k eq $k2_dash )
Branch: 1 branch
BranchTrueFalseTotal
if (index($k, "-") != -1 and $k eq $k2_dash) 0 132 132
Condition33%1/3
index($k, "-") != -1 and $k eq $k2_dash
!ll&&!rl&&r
13200
MC/DC0%0/2
index($k, "-") != -1 and $k eq $k2_dash
index($k, "-") != -1 $k eq $k2_dash
Truth table33%1/3
A and B
A= index($k, "-") != -1B= $k eq $k2_dash
ABresult
0X0
100
111
187 {
188 0 $dict->{ $k2_under } = CORE::delete( $dict->{ $k } );
189 0 $k = $k2_under;
190 }
191 # Add the dash option as an alias if it is not the same as the underscore one, such as when this is just one word, e.g. version
192 132 ▶ CORE::push( @$opt_name, $k2_dash ) if( $k2_dash ne $k2_under );
Branch: 1 branch
BranchTrueFalseTotal
if $k2_dash ne $k2_under 60 72 132
193  
194 132 ▶ if( !ref( $def->{alias} ) && CORE::length( $def->{alias} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $def->{"alias"} and length $def->{"alias"}) 18 114 132
Condition66%2/3
not ref $def->{"alias"} and length $def->{"alias"}
!ll&&!rl&&r
011418
MC/DC50%1/2
not ref $def->{"alias"} and length $def->{"alias"}
not ref $def->{"alias"} length $def->{"alias"}
Truth table66%2/3
not(A) and B
A= not ref $def->{"alias"}B= length $def->{"alias"}
ABresult
0X0
100
111
195 {
196 18 $def->{alias} = [$def->{alias}];
197 }
198 # Add the given aliases, if any
199 132 ▶ if( $self->_is_array( $def->{alias} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($def->{"alias"})) 18 114 132
200 {
201 18 ▶ push( @$opt_name, @{$def->{alias}} ) if( scalar( @{$def->{alias}} ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$def->{"alias"};} 18 0 18
202 # push( @$opt_name, $k2_under ) if( !scalar( grep( /^$k2_under$/, @{$def->{alias}} ) ) );
203 }
204 # Now, also add the original key-something and key_something to the alias, so we can find them from one of the aliases
205 # When we do exec, we'll be able to find all the aliases
206 132 ▶ $def->{alias} = [] if( !CORE::exists( $def->{alias} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $def->{"alias"} 114 18 132
207 132 ▶ CORE::push( @{$def->{alias}}, $k2_dash ) if( !scalar( grep( /^$k2_dash$/, @{$def->{alias}} ) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar grep(/^$k2_dash$/, @{$$def{"alias"};}) 132 0 132
208 132 ▶ CORE::push( @{$def->{alias}}, $k2_under ) if( !scalar( grep( /^$k2_under$/, @{$def->{alias}} ) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar grep(/^$k2_under$/, @{$$def{"alias"};}) 60 72 132
209 132 $def->{alias} = Module::Generic::Array->new( $def->{alias} );
210
211 132 my $opt = join( '|', @$opt_name );
212 132 ▶ if( defined( $def->{default} ) && ( ref( $def->{default} ) || length( $def->{default} ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $def->{'default'} and ref $def->{'default'} || length $def->{'default'}) { } 84 48 132
Condition66%4/6
defined $def->{"default"} and ref $def->{"default"} || length $def->{"default"}
!ll&&!rl&&r
48084
ref $def->{"default"} or length $def->{"default"}
l!l&&r!l&&!r
60240
MC/DC33%1/3
defined $def->{"default"} and ref $def->{"default"} || length $def->{"default"}
defined $def->{"default"} ref $def->{"default"} length $def->{"default"}
Truth table75%3/4
A and B or C
A= defined $def->{"default"}B= ref $def->{"default"}C= length $def->{"default"}
ABCresult
0XX0
1000
11X1
1011
213 {
214 84 ▶ if( $def->{type} eq 'file' )
Branch: 1 branch
BranchTrueFalseTotal
if ($def->{'type'} eq 'file') { } 0 84 84
215 {
216 0 ▶ if( !ref( $def->{default} ) || $self->_can_overload( $def->{default} => '""' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $def->{"default"} or $self->_can_overload($def->{"default"}, "\"\"")) 0 0 0
Condition0%0/3
not ref $def->{"default"} or $self->_can_overload($def->{"default"}, "\"\"")
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $def->{"default"} or $self->_can_overload($def->{"default"}, "\"\"")
not ref $def->{"default"} $self->_can_overload($def->{"default"}, "\"\"")
Truth table0%0/3
not(A) or B
A= not ref $def->{"default"}B= $self->_can_overload($def->{"default"}, "\"\"")
ABresult
1X1
011
000
217 {
218 0 $opts->{ $k2_under } = "$def->{default}";
219 }
220 }
221 else
222 {
223 84 $opts->{ $k2_under } = $def->{default};
224 }
225 }
226 else
227 {
228 48 $opts->{ $k2_under } = '';
229 }
230 132 my $suff = '';
231 132 ▶ if( $def->{type} eq 'string' || $def->{type} eq 'scalar' )
Branch: 13 branches
BranchTrueFalseTotal
if ($def->{'type'} eq 'string' or $def->{'type'} eq 'scalar') { } 24 108 132
elsif ($def->{'type'} eq 'string-hash') { } 6 102 108
elsif ($def->{'type'} eq 'array' or $def->{'type'} eq 'file-array' or $def->{'type'} eq 'uri-array') { } 6 96 102
elsif ($def->{'type'} eq 'boolean') { } 60 36 96
elsif ($def->{'type'} eq 'hash') { } 0 36 36
elsif ($def->{'type'} eq 'code' and ref $def->{'code'} eq 'CODE') { } 18 18 36
elsif ($def->{'type'} eq 'integer') { } 12 6 18
elsif ($def->{'type'} eq 'decimal' or $def->{'type'} eq 'float' or $def->{'type'} eq 'number') { } 0 6 6
elsif ($def->{'type'} eq 'date' or $def->{'type'} eq 'datetime') { } 6 0 6
elsif ($def->{'type'} eq 'code') { } 0 0 0
elsif ($def->{'type'} eq 'file') { } 0 0 0
elsif ($def->{'type'} eq 'uri') { } 0 0 0
elsif ($def->{'type'} eq 'version') { } 0 0 0
Condition66%2/3
$def->{"type"} eq "string" or $def->{"type"} eq "scalar"
l!l&&r!l&&!r
240108
MC/DC50%1/2
$def->{"type"} eq "string" or $def->{"type"} eq "scalar"
$def->{"type"} eq "string" $def->{"type"} eq "scalar"
Truth table66%2/3
A or B
A= $def->{"type"} eq "string"B= $def->{"type"} eq "scalar"
ABresult
1X1
011
000
232 {
233 24 $suff = '=s';
234 }
235 elsif( $def->{type} eq 'string-hash' )
236 {
237 6 $suff = '=s%';
238 }
239 ▶ elsif( $def->{type} eq 'array' ||
Condition66%4/6
$def->{"type"} eq "array" or $def->{"type"} eq "file-array" or $def->{"type"} eq "uri-array"
l!l&&r!l&&!r
6096
$def->{"type"} eq "array" or $def->{"type"} eq "file-array"
l!l&&r!l&&!r
6096
MC/DC33%1/3
$def->{"type"} eq "array" or $def->{"type"} eq "file-array" or $def->{"type"} eq "uri-array"
$def->{"type"} eq "array" $def->{"type"} eq "file-array" $def->{"type"} eq "uri-array"
Truth table50%2/4
A or B or C
A= $def->{"type"} eq "array"B= $def->{"type"} eq "file-array"C= $def->{"type"} eq "uri-array"
ABCresult
1XX1
01X1
0011
0000
240 $def->{type} eq 'file-array' ||
241 $def->{type} eq 'uri-array' )
242 {
243 6 $suff = '=s@';
244 6 ▶ $opts->{ $k2_under } = [] unless( length( $def->{default} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $def->{"default"} 0 6 6
245 6 ▶ $def->{min} = 1 if( !exists( $def->{min} ) && !exists( $def->{max} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $def->{"min"} or exists $def->{"max"} 0 6 6
Condition33%1/3
exists $def->{"min"} or exists $def->{"max"}
l!l&&r!l&&!r
600
MC/DC0%0/2
exists $def->{"min"} or exists $def->{"max"}
exists $def->{"min"} exists $def->{"max"}
Truth table33%1/3
A or B
A= exists $def->{"min"}B= exists $def->{"max"}
ABresult
1X1
011
000
246 }
247 elsif( $def->{type} eq 'boolean' )
248 {
249 60 $suff = '!';
250 60 ▶ if( exists( $def->{code} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"code"} and ref $def->{"code"} eq "CODE" and ref($opts->{$k2_under} // "") ne "CODE") 0 60 60
Condition25%2/8
exists $def->{"code"} and ref $def->{"code"} eq "CODE" and ref($opts->{$k2_under} // "") ne "CODE"
!ll&&!rl&&r
6000
exists $def->{"code"} and ref $def->{"code"} eq "CODE"
!ll&&!rl&&r
6000
$opts->{$k2_under} // ""
l!l
00
MC/DC0%0/3
exists $def->{"code"} and ref $def->{"code"} eq "CODE" and ref($opts->{$k2_under} // "") ne "CODE"
exists $def->{"code"} ref $def->{"code"} eq "CODE" $opts->{$k2_under}
Truth table25%1/4
A and B and C
A= exists $def->{"code"}B= ref $def->{"code"} eq "CODE"C= $opts->{$k2_under}
ABCresult
0XX0
10X0
1100
1111
251 ref( $def->{code} ) eq 'CODE' &&
252 # Will not override if a code ref is already assigned
253 ref( $opts->{ $k2_under } // '' ) ne 'CODE' )
254 {
255 0 $opts->{ $k2_under } = $def->{code};
256 }
257 }
258 elsif( $def->{type} eq 'hash' )
259 {
260 0 $suff = '=s%';
261 0 ▶ $opts->{ $k2_under } = {} unless( length( $def->{default} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $def->{"default"} 0 0 0
262 }
263 ▶ elsif( $def->{type} eq 'code' && ref( $def->{code} ) eq 'CODE' )
Condition66%2/3
$def->{"type"} eq "code" and ref $def->{"code"} eq "CODE"
!ll&&!rl&&r
18018
MC/DC50%1/2
$def->{"type"} eq "code" and ref $def->{"code"} eq "CODE"
$def->{"type"} eq "code" ref $def->{"code"} eq "CODE"
Truth table66%2/3
A and B
A= $def->{"type"} eq "code"B= ref $def->{"code"} eq "CODE"
ABresult
0X0
100
111
264 {
265 18 $opts->{ $k2_under } = $def->{code};
266 }
267 elsif( $def->{type} eq 'integer' )
268 {
269 12 $suff = '=i';
270 }
271 ▶ elsif( $def->{type} eq 'decimal' || $def->{type} eq 'float' || $def->{type} eq 'number' )
Condition33%2/6
$def->{"type"} eq "decimal" or $def->{"type"} eq "float" or $def->{"type"} eq "number"
l!l&&r!l&&!r
006
$def->{"type"} eq "decimal" or $def->{"type"} eq "float"
l!l&&r!l&&!r
006
MC/DC0%0/3
$def->{"type"} eq "decimal" or $def->{"type"} eq "float" or $def->{"type"} eq "number"
$def->{"type"} eq "decimal" $def->{"type"} eq "float" $def->{"type"} eq "number"
Truth table25%1/4
A or B or C
A= $def->{"type"} eq "decimal"B= $def->{"type"} eq "float"C= $def->{"type"} eq "number"
ABCresult
1XX1
01X1
0011
0000
272 {
273 0 $suff .= '=f';
274 }
275 ▶ elsif( $def->{type} eq 'date' || $def->{type} eq 'datetime' )
Condition33%1/3
$def->{"type"} eq "date" or $def->{"type"} eq "datetime"
l!l&&r!l&&!r
060
MC/DC0%0/2
$def->{"type"} eq "date" or $def->{"type"} eq "datetime"
$def->{"type"} eq "date" $def->{"type"} eq "datetime"
Truth table33%1/3
A or B
A= $def->{"type"} eq "date"B= $def->{"type"} eq "datetime"
ABresult
1X1
011
000
276 {
277 6 $suff = '=s';
278 }
279 elsif( $def->{type} eq 'code' )
280 {
281 0 ▶ return( $self->error( "Type is code, but there is no property code for this option \"$k\"." ) ) if( !CORE::exists( $def->{code} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $def->{"code"} 0 0 0
282 0 ▶ return( $self->error( "Type is code, but the property code is not a code reference for this option \"$k\"." ) ) if( ref( $def->{code} ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $def->{"code"} ne "CODE" 0 0 0
283 0 $opts->{ $k2_under } = $def->{code};
284 }
285 elsif( $def->{type} eq 'file' )
286 {
287 0 $suff = '=s';
288 }
289 elsif( $def->{type} eq 'uri' )
290 {
291 0 $suff = '=s';
292 }
293 elsif( $def->{type} eq 'version' )
294 {
295 0 $suff = '=s';
296 }
297
298 132 ▶ if( $def->{min} )
Branch: 1 branch
BranchTrueFalseTotal
if ($def->{"min"}) 6 126 132
299 {
300 # If there is no max, it would be for example s{1,}
301 # 2nd formatter is %s because it could be blank. %d would translate to 0 when blank.
302 6 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
303 6 $suff .= sprintf('{%d,%s}', @$def{ qw( min max ) } );
304 }
305
306 132 ▶ if( $def->{re} && ref( $def->{re} ) ne 'Regexp' )
Branch: 1 branch
BranchTrueFalseTotal
if ($def->{"re"} and ref $def->{"re"} ne "Regexp") 0 132 132
Condition66%2/3
$def->{"re"} and ref $def->{"re"} ne "Regexp"
!ll&&!rl&&r
120120
MC/DC0%0/2
$def->{"re"} and ref $def->{"re"} ne "Regexp"
$def->{"re"} ref $def->{"re"} ne "Regexp"
Truth table66%2/3
A and B
A= $def->{"re"}B= ref $def->{"re"} ne "Regexp"
ABresult
0X0
100
111
307 {
308 0 return( $self->error( "Regular expression provided for property \"$k\" ($def->{re}) is not a proper regular expression. I was expecting something like qr// and of type 'Regexp'." ) );
309 }
310 132 push( @$params, $opt . $suff );
311 }
312 6 $self->options( $opts );
313 6 $self->parameters( $params );
314 6 $self->{getopt} = Getopt::Long::Parser->new;
315 6 return( $self );
316 }
317  
318 sub check_class_data
319 1 ▶{
Subroutine check_class_data: called CC=28 SCAR=49.9
Pod documented
320 1 my $self = shift( @_ );
321 1 ▶ my $class = shift( @_ ) || return( $self->error( "No class was provided to return its definition" ) );
Condition50%1/2
shift @_ || (return $self->error('No class was provided to return its definition'))
l!l
10
MC/DC0%0/1
shift @_ || (return $self->error('No class was provided to return its definition'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
322 1 ▶ return( $self->error( "Class provided '$class' is not a string." ) ) if( ref( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1 1
323 1 my $p = {};
324 1 ▶ $p = shift( @_ ) if( scalar( @_ ) && $self->_is_hash( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ and $self->_is_hash($_[0]) 0 1 1
Condition33%1/3
scalar @_ and $self->_is_hash($_[0])
!ll&&!rl&&r
100
MC/DC0%0/2
scalar @_ and $self->_is_hash($_[0])
scalar @_ $self->_is_hash($_[0])
Truth table33%1/3
A and B
A= scalar @_B= $self->_is_hash($_[0])
ABresult
0X0
100
111
325 1 ▶ my $dict = $self->class( $class ) || return;
Condition50%1/2
$self->class($class) || (return)
l!l
10
MC/DC0%0/1
$self->class($class) || (return)
$self->class($class)
Truth table50%1/2
A
A= $self->class($class)
Aresult
11
00
326 1 ▶ my $v = $self->get_class_values( $class ) || return;
Condition50%1/2
$self->get_class_values($class) || (return)
l!l
10
MC/DC0%0/1
$self->get_class_values($class) || (return)
$self->get_class_values($class)
Truth table50%1/2
A
A= $self->get_class_values($class)
Aresult
11
00
327 1 my $errors =
328 {
329 missing => {},
330 regexp => {},
331 };
332 1 foreach my $f ( sort( keys( %$dict ) ) )
333 {
334 4 my $def = $dict->{ $f };
335 4 ▶ my $n = $def->{name} ? $def->{name} : $f;
Branch: 1 branch
BranchTrueFalseTotal
$def->{'name'} ? : 1 3 4
336 4 ▶ $def->{error} ||= "does not match requirements";
Condition50%1/2
$def->{"error"} ||= "does not match requirements"
l!l
04
MC/DC0%0/1
$def->{"error"} ||= "does not match requirements"
$def->{"error"}
Truth table50%1/2
A
A= $def->{"error"}
Aresult
11
00
337 4 ▶ if( !!$p->{required} && $def->{required} )
Branch: 1 branch
BranchTrueFalseTotal
if (not !$p->{"required"} and $def->{"required"}) 0 4 4
Condition33%1/3
not !$p->{"required"} and $def->{"required"}
!ll&&!rl&&r
400
MC/DC0%0/2
not !$p->{"required"} and $def->{"required"}
not !$p->{"required"} $def->{"required"}
Truth table33%1/3
A and B
A= not !$p->{"required"}B= $def->{"required"}
ABresult
0X0
100
111
338 {
339 0 ▶ if( ( $def->{type} =~ /^(?:boolean|decimal|integer|string)/ && !length( $v->{ $f } ) ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($def->{"type"} =~ /^(?:boolean|decimal|integer|string)/ and not length $v->{$f} or $def->{"type"} eq "hash" || $def->{"type"} eq "string-hash" and not scalar keys %{$$v{$f};} or $def->{"type"} eq "array" and not scalar @{$v->{$f};}) 0 0 0
Condition0%0/15
$def->{"type"} =~ /^(?:boolean|decimal|integer|string)/ and not length $v->{$f} or $def->{"type"} eq "hash" || $def->{"type"} eq "string-hash" and not scalar keys %{$$v{$f};} or $def->{"type"} eq "array" and not scalar @{$v->{$f};}
l!l&&r!l&&!r
000
$def->{"type"} =~ /^(?:boolean|decimal|integer|string)/ and not length $v->{$f} or $def->{"type"} eq "hash" || $def->{"type"} eq "string-hash" and not scalar keys %{$$v{$f};}
l!l&&r!l&&!r
000
$def->{"type"} =~ /^(?:boolean|decimal|integer|string)/ and not length $v->{$f}
!ll&&!rl&&r
000
$def->{"type"} eq "hash" || $def->{"type"} eq "string-hash" and not scalar keys %{$$v{$f};}
!ll&&!rl&&r
000
$def->{"type"} eq "hash" or $def->{"type"} eq "string-hash"
l!l&&r!l&&!r
000
MC/DC0%0/6
$def->{"type"} =~ /^(?:boolean|decimal|integer|string)/ and not length $v->{$f} or $def->{"type"} eq "hash" || $def->{"type"} eq "string-hash" and not scalar keys %{$$v{$f};} or $def->{"type"} eq "array" and not scalar @{$v->{$f};}
$def->{"type"} =~ /^(?:boolean|decimal|integer|string)/ not length $v->{$f} $def->{"type"} eq "hash" $def->{"type"} eq "string-hash" not scalar keys %{$$v{$f};} $def->{"type"} eq "array" and not scalar @{$v->{$f};}
Truth table0%0/17
A and not(B) or C or D and not(E) or F
A= $def->{"type"} =~ /^(?:boolean|decimal|integer|string)/B= not length $v->{$f}C= $def->{"type"} eq "hash"D= $def->{"type"} eq "string-hash"E= not scalar keys %{$$v{$f};}F= $def->{"type"} eq "array" and not scalar @{$v->{$f};}
ABCDEFresult
11XXXX1
0X1X1X1
0X011X1
101X1X1
10011X1
0X00X11
0X1X011
0X01011
1000X11
101X011
1001011
0X00X00
0X1X000
0X01000
1000X00
101X000
1001000
340 0 ▶ ( ( $def->{type} eq 'hash' || $def->{type} eq 'string-hash' ) && !scalar( keys( %{$v->{ $f }} ) ) ) ||
Condition0%0/3
$def->{"type"} eq "array" and not scalar @{$v->{$f};}
!ll&&!rl&&r
000
MC/DC0%0/2
$def->{"type"} eq "array" and not scalar @{$v->{$f};}
$def->{"type"} eq "array" not scalar @{$v->{$f};}
Truth table0%0/3
A and not(B)
A= $def->{"type"} eq "array"B= not scalar @{$v->{$f};}
ABresult
0X0
100
111
341 0 ( $def->{type} eq 'array' && !scalar( @{$v->{ $f }} ) ) )
342 {
343 0 $errors->{missing}->{ $f } = "$f ($n) is missing";
344 0 next;
345 }
346 }
347 4 ▶ if( $def->{re} )
Branch: 2 branches
BranchTrueFalseTotal
if ($def->{'re'}) { } 1 3 4
elsif ($def->{'type'} eq 'decimal' and not $v->{$f} =~ /^\d+(\.\d{1,12})?$/) { } 0 6 6
348 {
349 1 ▶ if( $def->{type} eq 'string' && length( $v->{ $f } ) && $v->{ $f } !~ /$def->{re}/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($def->{'type'} eq 'string' and length $v->{$f} and not $v->{$f} =~ /$def->{'re'}/) { } 0 1 1
elsif ($def->{'type'} eq 'array') { } 1 0 1
Condition33%2/6
$def->{"type"} eq "string" and length $v->{$f} and not $v->{$f} =~ /$def->{"re"}/
!ll&&!rl&&r
100
$def->{"type"} eq "string" and length $v->{$f}
!ll&&!rl&&r
100
MC/DC0%0/3
$def->{"type"} eq "string" and length $v->{$f} and not $v->{$f} =~ /$def->{"re"}/
$def->{"type"} eq "string" length $v->{$f} not $v->{$f} =~ /$def->{"re"}/
Truth table25%1/4
A and B and not(C)
A= $def->{"type"} eq "string"B= length $v->{$f}C= not $v->{$f} =~ /$def->{"re"}/
ABCresult
0XX0
10X0
1100
1111
350 {
351 0 $errors->{regexp}->{ $f } = "$f ($n) " . $def->{error};
352 }
353 elsif( $def->{type} eq 'array' )
354 {
355 1 my $sub_err = [];
356 1 foreach my $this ( @{$v->{ $f }} )
357 {
358 1 ▶ if( $this !~ /$def->{re}/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($this =~ /$def->{"re"}/) 1 0 1
359 {
360 1 push( @$sub_err, $this );
361 }
362 }
363 1 $errors->{regexp}->{ $f } = join( ', ', @$sub_err ) . ' ' . $def->{error};
364 }
365 }
366 ▶ elsif( $def->{type} eq 'decimal' && $v->{ $f } !~ /^\d+(\.\d{1,12})?$/ )
Condition33%1/3
$def->{"type"} eq "decimal" and not $v->{$f} =~ /^\d+(\.\d{1,12})?$/
!ll&&!rl&&r
300
MC/DC0%0/2
$def->{"type"} eq "decimal" and not $v->{$f} =~ /^\d+(\.\d{1,12})?$/
$def->{"type"} eq "decimal" not $v->{$f} =~ /^\d+(\.\d{1,12})?$/
Truth table33%1/3
A and not(B)
A= $def->{"type"} eq "decimal"B= not $v->{$f} =~ /^\d+(\.\d{1,12})?$/
ABresult
0X0
100
111
367 {
368 0 $errors->{regexp}->{ $f } = "$f ($n) " . $def->{error};
369 }
370 }
371 1 return( $errors );
372 }
373  
374 sub class
375 4 ▶{
Subroutine class: called CC=15 SCAR=27.9
Pod documented
376 4 my $self = shift( @_ );
377 4 ▶ my $class = shift( @_ ) || return( $self->error( "No class was provided to return its definition" ) );
Condition50%1/2
shift @_ || (return $self->error('No class was provided to return its definition'))
l!l
40
MC/DC0%0/1
shift @_ || (return $self->error('No class was provided to return its definition'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
378 4 ▶ return( $self->error( "Class provided '$class' is not a string." ) ) if( ref( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 4 4
379 4 my $classes = $self->classes;
380 4 ▶ return( $self->error( "I was expecting an hash reference for the classes dictionaries but got '$classes' instead." ) ) if( !ref( $classes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $classes 0 4 4
381 4 ▶ return( $self->error( "No class \"$class\" was found." ) ) if( scalar( keys( %$classes ) ) && !exists( $classes->{ $class } ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %$classes and not exists $classes->{$class} 0 4 4
Condition66%2/3
scalar keys %$classes and not exists $classes->{$class}
!ll&&!rl&&r
220
MC/DC0%0/2
scalar keys %$classes and not exists $classes->{$class}
scalar keys %$classes not exists $classes->{$class}
Truth table66%2/3
A and not(B)
A= scalar keys %$classesB= not exists $classes->{$class}
ABresult
0X0
100
111
382 4 my $dict = $self->dictionary;
383 4 ▶ return( $self->error( "No dictionary data could be found!" ) ) if( !scalar( keys( %$dict ) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %$dict 0 4 4
384 4 foreach my $k ( sort( keys( %$dict ) ) )
385 {
386 88 my $def = $dict->{ $k };
387 88 ▶ next if( !exists( $def->{class} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $def->{"class"} 68 20 88
388 20 my $class_names = $def->{class};
389 20 my $k2 = $k;
390 20 $k2 =~ tr/-/_/;
391 20 foreach my $class ( @$class_names )
392 {
393 # Create the class if it doe snot exists yet
394 32 ▶ $classes->{ $class } = {} if( !exists( $classes->{ $class } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $classes->{$class} 4 28 32
395 32 my $this = $classes->{ $class };
396 # Then add the property and it definition hash
397 32 $this->{ $k2 } = $def;
398 # If there are any alias, we add them too
399 32 ▶ if( $def->{alias} && scalar( @{$def->{alias}} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($def->{"alias"} and scalar @{$def->{"alias"};}) 32 0 32
Condition50%1/2
$def->{"alias"} and scalar @{$def->{"alias"};}
!ll
032
MC/DC0%0/1
$def->{"alias"} and scalar @{$def->{"alias"};}
$def->{"alias"}
Truth table50%1/2
A
A= $def->{"alias"}
Aresult
00
11
400 {
401 32 foreach my $f ( @{$def->{alias}} )
402 {
403 32 my $f2 = $f;
404 32 $f2 =~ tr/-/_/;
405 32 $this->{ $f } = $this->{ $f2 } = $def;
406 }
407 }
408 }
409 }
410 4 ▶ return( $self->error( "No class \"$class\" was found." ) ) if( !exists( $classes->{ $class } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $classes->{$class} 0 4 4
411 4 return( $classes->{ $class } );
412 }
413  
414 4 ▶sub classes { return( shift->_set_get_hash( 'classes', @_ ) ); }
Subroutine classes: called CC=1 SCAR=0.0
Pod documented
415  
416 sub class_properties
417 2 ▶{
Subroutine class_properties: called CC=2 SCAR=7.0
Pod documented
418 2 my $self = shift( @_ );
419 2 my $class = shift( @_ );
420 2 ▶ return( $self->error( "No class was provided to list its properties." ) ) if( !length( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $class 0 2 2
421 2 my $fields = [];
422 2 my $ref = $self->class( $class );
423 2 my $props = [ sort( keys( %$ref ) ) ];
424 2 return( Module::Generic::Array->new( $props ) );
425 }
426  
427 sub configure
428 6 ▶{
Subroutine configure: called CC=6 SCAR=18.9
Pod documented
429 6 my $self = shift( @_ );
430 6 ▶ return( $self ) if( $self->{configured} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"configured"} 0 6 6
431 6 my $conf = [];
432 6 ▶ $conf = shift( @_ ) if( ref( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 6 6
433 6 ▶ $conf = $self->configure_options if( !scalar( @$conf ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$conf 6 0 6
434 6 ▶ my $getopt = $self->getopt || return( $self->error( "No Getopt::Long::Parser object found." ) );
Condition50%1/2
$self->getopt || (return $self->error('No Getopt::Long::Parser object found.'))
l!l
60
MC/DC0%0/1
$self->getopt || (return $self->error('No Getopt::Long::Parser object found.'))
$self->getopt
Truth table50%1/2
A
A= $self->getopt
Aresult
11
00
435 6 local $@;
436 # try-catch
437 eval
438 6 {
439 6 $getopt->configure( @$conf );
440 6 $self->{configured} = 1;
441 };
442 6 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 6 6
443 {
444 0 return( $self->error( "An error occurred while configuration Getlong::Opt: $@" ) );
445 }
446 6 return( $self );
447 }
448  
449 6 ▶sub configure_errors { return( shift->_set_get_array_as_object( 'configure_errors', @_ ) ); }
Subroutine configure_errors: called CC=1 SCAR=0.0
Pod documented
450  
451 6 ▶sub configure_options { return( shift->_set_get_array_as_object( 'configure_options', @_ ) ); }
Subroutine configure_options: called CC=1 SCAR=0.0
Pod documented
452  
453 28 ▶sub dictionary { return( shift->_set_get_hash( 'dictionary', @_ ) ); }
Subroutine dictionary: called CC=1 SCAR=0.0
Pod documented
454  
455 sub exec
456 6 ▶{
Subroutine exec: called CC=26 SCAR=43.9
Pod documented
457 6 my $self = shift( @_ );
458 6 ▶ $self->configure || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->configure or return 6 0 6
459 6 my $errors = [];
460 6 my $missing = [];
461 6 my $dict = $self->dictionary;
462 6 ▶ return( $self->error( "The data returned by dictionary() is not an hash reference." ) ) if( !$self->_is_hash( $dict ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($dict) 0 6 6
463 6 ▶ return( $self->error( "Somehow, the dictionary hash is empty!" ) ) if( !scalar( keys( %$dict ) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %$dict 0 6 6
464 6 my $opts = $self->options;
465 6 ▶ return( $self->error( "The data returned by options() is not an hash reference." ) ) if( !$self->_is_hash( $opts ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($opts) 0 6 6
466 6 ▶ return( $self->error( "Somehow, the options hash is empty!" ) ) if( !scalar( keys( %$opts ) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %$opts 0 6 6
467 6 my $params = $self->parameters;
468 6 ▶ return( $self->error( "Data returned by parameters() is not an array reference" ) ) if( !$self->_is_array( $params ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($params) 0 6 6
469 6 ▶ return( $self->error( "Somehow, the parameters array is empty!" ) ) if( !scalar( @$params ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$params 0 6 6
470 6 ▶ my $getopt = $self->getopt || return( $self->error( "No Getopt::Long object found." ) );
Condition50%1/2
$self->getopt || (return $self->error('No Getopt::Long object found.'))
l!l
60
MC/DC0%0/1
$self->getopt || (return $self->error('No Getopt::Long object found.'))
$self->getopt
Truth table50%1/2
A
A= $self->getopt
Aresult
11
00
471 6 my $required = $self->required;
472 6 ▶ return( $self->error( "Data returned by required() is not an array reference" ) ) if( !$self->_is_array( $required ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($required) 0 6 6
473
474 6 ▶ my $tie = tied( %$opts ) || return( $self->error( "Unable to get the tie object for the options value hash." ) );
Condition50%1/2
tied %$opts || (return $self->error('Unable to get the tie object for the options value hash.'))
l!l
60
MC/DC0%0/1
tied %$opts || (return $self->error('Unable to get the tie object for the options value hash.'))
tied %$opts
Truth table50%1/2
A
A= tied %$opts
Aresult
11
00
475
476 local $Getopt::Long::SIG{ '__DIE__' } = sub
477 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
478 0 push( @$errors, join( '', @_ ) );
479 6 };
480 local $Getopt::Long::SIG{ '__WARN__' } = sub
481 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
482 0 push( @$errors, join( '', @_ ) );
483 6 };
484 6 $self->configure_errors( $errors );
485
486 6 $tie->enable(1);
487 $getopt->getoptions( $opts, @$params ) || do
488 6 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
$getopt->getoptions($opts, @$params) or do { my $usage = $self->usage; return &$usage() if ref $usage eq "CODE"; return } 6 0 6
489 0 my $usage = $self->usage;
490 0 ▶ return( $usage->() ) if( ref( $usage ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $usage eq "CODE" 0 0 0
491 0 return;
492 };
493
494 6 foreach my $key ( @$required )
495 {
496 1 ▶ if( exists( $opts->{ $key } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{$key} and !(defined $opts->{$key} && length $opts->{$key}) || $opts->{$key} =~ /^[[:blank:]]*$/ || ref $opts->{$key} eq "SCALAR" && (!length(${$opts->{$key};}) || ${$opts->{$key};} =~ /^[[:blank:]]*$/) || ref $opts->{$key} eq "ARRAY" && !scalar(@{$opts->{$key};})) 1 0 1
Condition23%5/21
exists $opts->{$key} and !(defined $opts->{$key} && length $opts->{$key}) || $opts->{$key} =~ /^[[:blank:]]*$/ || ref $opts->{$key} eq "SCALAR" && (!length(${$opts->{$key};}) || ${$opts->{$key};} =~ /^[[:blank:]]*$/) || ref $opts->{$key} eq "ARRAY" && !scalar(@{$opts->{$key};})
!ll&&!rl&&r
001
not defined $opts->{$key} && length $opts->{$key} or $opts->{$key} =~ /^[[:blank:]]*$/ or ref $opts->{$key} eq "SCALAR" and !length(${$opts->{$key};}) || ${$opts->{$key};} =~ /^[[:blank:]]*$/ or ref $opts->{$key} eq "ARRAY" and not scalar @{$opts->{$key};}
l!l&&r!l&&!r
100
not defined $opts->{$key} && length $opts->{$key} or $opts->{$key} =~ /^[[:blank:]]*$/ or ref $opts->{$key} eq "SCALAR" and !length(${$opts->{$key};}) || ${$opts->{$key};} =~ /^[[:blank:]]*$/
l!l&&r!l&&!r
100
not defined $opts->{$key} && length $opts->{$key} or $opts->{$key} =~ /^[[:blank:]]*$/
l!l&&r!l&&!r
100
defined $opts->{$key} && length $opts->{$key}
!ll&&!rl&&r
010
ref $opts->{$key} eq "SCALAR" and !length(${$opts->{$key};}) || ${$opts->{$key};} =~ /^[[:blank:]]*$/
!ll&&!rl&&r
000
not length ${$opts->{$key};} or ${$opts->{$key};} =~ /^[[:blank:]]*$/
l!l&&r!l&&!r
000
MC/DC0%0/8
exists $opts->{$key} and !(defined $opts->{$key} && length $opts->{$key}) || $opts->{$key} =~ /^[[:blank:]]*$/ || ref $opts->{$key} eq "SCALAR" && (!length(${$opts->{$key};}) || ${$opts->{$key};} =~ /^[[:blank:]]*$/) || ref $opts->{$key} eq "ARRAY" && !scalar(@{$opts->{$key};})
exists $opts->{$key} defined $opts->{$key} length $opts->{$key} $opts->{$key} =~ /^[[:blank:]]*$/ ref $opts->{$key} eq "SCALAR" not length ${$opts->{$key};} ${$opts->{$key};} =~ /^[[:blank:]]*$/ ref $opts->{$key} eq "ARRAY" and not scalar @{$opts->{$key};}
Truth table10%1/10
A and not(B && C) or D or E and not(F) or G or H
A= exists $opts->{$key}B= defined $opts->{$key}C= length $opts->{$key}D= $opts->{$key} =~ /^[[:blank:]]*$/E= ref $opts->{$key} eq "SCALAR"F= not length ${$opts->{$key};}G= ${$opts->{$key};} =~ /^[[:blank:]]*$/H= ref $opts->{$key} eq "ARRAY" and not scalar @{$opts->{$key};}
ABCDEFGHresult
0XXXXXXX0
11100XX00
111010000
10XXXXXX1
110XXXXX1
1111XXXX1
111011XX1
1110101X1
11100XX11
111010011
497 ( !defined( $opts->{ $key } ) ||
498 !length( $opts->{ $key } ) ||
499 $opts->{ $key } =~ /^[[:blank:]]*$/ ||
500 ( ref( $opts->{ $key } ) eq 'SCALAR' &&
501 0 ▶ ( !length( ${$opts->{ $key }} ) || ${$opts->{ $key }} =~ /^[[:blank:]]*$/ )
Condition0%0/3
ref $opts->{$key} eq "ARRAY" and not scalar @{$opts->{$key};}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $opts->{$key} eq "ARRAY" and not scalar @{$opts->{$key};}
ref $opts->{$key} eq "ARRAY" not scalar @{$opts->{$key};}
Truth table0%0/3
A and not(B)
A= ref $opts->{$key} eq "ARRAY"B= not scalar @{$opts->{$key};}
ABresult
0X0
100
111
502 ) ||
503 (
504 ref( $opts->{ $key } ) eq 'ARRAY' &&
505 0 !scalar( @{$opts->{ $key }} )
506 )
507 )
508 )
509 {
510 1 push( @$missing, $key );
511 }
512 }
513 6 $self->missing( $missing );
514
515 # Make sure we can access each of the options dictionary definition not just from the original key, but also from any of it aliases
516 6 my $aliases = $self->{aliases};
517 6 foreach my $k ( keys( %$dict ) )
518 {
519 132 my $def = $dict->{ $k };
520 132 $aliases->{ $k } = $def;
521 132 foreach my $a ( @{$def->{alias}} )
522 {
523 210 $aliases->{ $a } = $def;
524 }
525 }
526 6 $tie->enable(1);
527
528 6 $self->postprocess;
529
530 # return( $opts );
531 # e return a Getopt::Class::Values object, so we can call the option values hash key as method:
532 # $object->metadata / $object->metadata( $some_hash );
533 # instead of:
534 # $object->{metadata}
535 # return( $opts );
536 my $o = Getopt::Class::Values->new({
537 data => $opts,
538 dict => $dict,
539 aliases => $aliases,
540 debug => $self->{debug},
541 6 ▶ }) || return( $self->pass_error( Getopt::Class::Values->error ) );
Condition50%1/2
'Getopt::Class::Values'->new({'data', $opts, 'dict', $dict, 'aliases', $aliases, 'debug', $self->{'debug'}}) || (return $self->pass_error('Getopt::Class::Values'->error))
l!l
60
MC/DC0%0/1
'Getopt::Class::Values'->new({'data', $opts, 'dict', $dict, 'aliases', $aliases, 'debug', $self->{'debug'}}) || (return $self->pass_error('Getopt::Class::Values'->error))
'Getopt::Class::Values'->new({'data', $opts, 'dict', $dict, 'aliases', $aliases, 'debug', $self->{'debug'}})
Truth table50%1/2
A
A= 'Getopt::Class::Values'->new({'data', $opts, 'dict', $dict, 'aliases', $aliases, 'debug', $self->{'debug'}})
Aresult
11
00
542 6 return( $o );
543 }
544  
545 sub get_class_values
546 1 ▶{
Subroutine get_class_values: called CC=16 SCAR=32.6
Pod documented
547 1 my $self = shift( @_ );
548 1 ▶ my $class = shift( @_ ) || return( $self->error( "No class was provided to return its definition" ) );
Condition50%1/2
shift @_ || (return $self->error('No class was provided to return its definition'))
l!l
10
MC/DC0%0/1
shift @_ || (return $self->error('No class was provided to return its definition'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
549 1 ▶ return( $self->error( "Class provided '$class' is not a string." ) ) if( ref( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1 1
550 1 ▶ my $this_dict = $self->class( $class ) || return;
Condition50%1/2
$self->class($class) || (return)
l!l
10
MC/DC0%0/1
$self->class($class) || (return)
$self->class($class)
Truth table50%1/2
A
A= $self->class($class)
Aresult
11
00
551 1 my $opts = $self->options;
552 1 ▶ return( $self->error( "The data returned by options() is not an hash reference." ) ) if( !$self->_is_hash( $opts ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($opts) 0 1 1
553 1 ▶ return( $self->error( "Somehow, the options hash is empty!" ) ) if( !scalar( keys( %$opts ) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %$opts 0 1 1
554 1 my $v = {};
555 1 ▶ $v = shift( @_ ) if( scalar( @_ ) && $self->_is_hash( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ and $self->_is_hash($_[0]) 0 1 1
Condition33%1/3
scalar @_ and $self->_is_hash($_[0])
!ll&&!rl&&r
100
MC/DC0%0/2
scalar @_ and $self->_is_hash($_[0])
scalar @_ $self->_is_hash($_[0])
Truth table33%1/3
A and B
A= scalar @_B= $self->_is_hash($_[0])
ABresult
0X0
100
111
556 1 foreach my $f ( sort( keys( %$this_dict ) ) )
557 {
558 4 ▶ my $ref = lc( Scalar::Util::reftype( $opts->{ $f } ) // '' );
Condition100%2/2
builtin::reftype($opts->{$f}) // ""
l!l
13
MC/DC100%1/1
builtin::reftype($opts->{$f}) // ""
builtin::reftype($opts->{$f})
Truth table100%2/2
A
A= builtin::reftype($opts->{$f})
Aresult
11
00
559 4 ▶ if( $ref eq 'hash' )
Branch: 3 branches
BranchTrueFalseTotal
if ($ref eq 'hash') { } 0 4 4
elsif ($ref eq 'array') { } 1 3 4
elsif (not length $ref) { } 3 0 3
560 {
561 0 ▶ $v->{ $f } = $opts->{ $f } if( scalar( keys( %{$opts->{ $f }} ) ) > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$$opts{$f};} > 0 0 0 0
562 }
563 elsif( $ref eq 'array' )
564 {
565 1 ▶ $v->{ $f } = $opts->{ $f } if( scalar( @{$opts->{ $f }} ) > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$opts->{$f};} > 0 1 0 1
566 }
567 elsif( !length( $ref ) )
568 {
569 3 ▶ $v->{ $f } = $opts->{ $f } if( length( $opts->{ $f } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $opts->{$f} 0 3 3
570 }
571 }
572 1 return( $v );
573 }
574  
575 12 ▶sub getopt { return( shift->_set_get_object( 'getopt', 'Getopt::Long::Parser', @_ ) ); }
Subroutine getopt: called CC=1 SCAR=0.0
Pod documented
576  
577 7 ▶sub missing { return( shift->_set_get_array_as_object( 'missing', @_ ) ); }
Subroutine missing: called CC=1 SCAR=0.0
Pod documented
578  
579 19 ▶sub options { return( shift->_set_get_hash( 'options', @_ ) ); }
Subroutine options: called CC=1 SCAR=0.0
Pod documented
580  
581 12 ▶sub parameters { return( shift->_set_get_array_as_object( 'parameters', @_ ) ); }
Subroutine parameters: called CC=1 SCAR=0.0
Pod documented
582  
583 sub postprocess
584 6 ▶{
Subroutine postprocess: called CC=40 SCAR=50.0
Pod undocumented
585 6 my $self = shift( @_ );
586 6 my $dict = $self->dictionary;
587 6 my $opts = $self->options;
588 6 foreach my $k ( sort( keys( %$dict ) ) )
589 {
590 132 my $def = $dict->{ $k };
591 132 ▶ next if( !length( $opts->{ $k } ) && !$def->{default} );
Branch: 1 branch
BranchTrueFalseTotal
unless length $opts->{$k} or $def->{"default"} 25 107 132
Condition66%2/3
length $opts->{$k} or $def->{"default"}
l!l&&r!l&&!r
107025
MC/DC50%1/2
length $opts->{$k} or $def->{"default"}
length $opts->{$k} $def->{"default"}
Truth table66%2/3
A or B
A= length $opts->{$k}B= $def->{"default"}
ABresult
1X1
011
000
592 107 ▶ return( $self->error( "Dictionary is malformed with entry $k value not being an hash reference." ) ) if( ref( $def ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $def ne "HASH" 0 107 107
593
594 107 ▶ if( ( $def->{type} eq 'date' || $def->{type} eq 'datetime' ) && length( $opts->{ $k } ) )
Branch: 11 branches
BranchTrueFalseTotal
if ($def->{'type'} eq 'date' || $def->{'type'} eq 'datetime' and length $opts->{$k}) { } 2 105 107
elsif ($def->{'type'} eq 'array') { } 6 99 105
elsif ($def->{'type'} eq 'hash' or $def->{'type'} eq 'string-hash') { } 6 93 99
elsif ($def->{'type'} eq 'boolean') { } 54 39 93
elsif ($def->{'type'} eq 'string' or $def->{'type'} eq 'scalar') { } 14 25 39
elsif ($def->{'type'} eq 'integer' or $def->{'type'} eq 'number' or $def->{'type'} eq 'float' or $def->{'type'} eq 'decimal' or $def->{'decimal'}) { } 7 18 25
elsif ($def->{'type'} eq 'file' and length($opts->{$k} // '')) { } 0 18 18
elsif ($def->{'type'} eq 'file-array') { } 0 18 18
elsif ($def->{'type'} eq 'uri') { } 0 18 18
elsif ($def->{'type'} eq 'uri-array') { } 0 18 18
elsif ($def->{'type'} eq 'version') { } 0 18 18
Condition66%4/6
$def->{"type"} eq "date" || $def->{"type"} eq "datetime" and length $opts->{$k}
!ll&&!rl&&r
10502
$def->{"type"} eq "date" or $def->{"type"} eq "datetime"
l!l&&r!l&&!r
02105
MC/DC33%1/3
$def->{"type"} eq "date" || $def->{"type"} eq "datetime" and length $opts->{$k}
$def->{"type"} eq "date" $def->{"type"} eq "datetime" length $opts->{$k}
Truth table40%2/5
A or B and C
A= $def->{"type"} eq "date"B= $def->{"type"} eq "datetime"C= length $opts->{$k}
ABCresult
00X0
1X00
0100
1X11
0111
595 {
596 2 my $dt = $self->_parse_timestamp( $opts->{ $k } );
597 2 ▶ return( $self->pass_error ) if( !defined( $dt ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dt 0 2 2
598 2 ▶ $opts->{ $k } = $dt if( $dt );
Branch: 1 branch
BranchTrueFalseTotal
if $dt 2 0 2
599 }
600 elsif( $def->{type} eq 'array' )
601 {
602 6 $opts->{ $k } = Module::Generic::Array->new( $opts->{ $k } );
603 }
604 ▶ elsif( $def->{type} eq 'hash' ||
Condition66%2/3
$def->{"type"} eq "hash" or $def->{"type"} eq "string-hash"
l!l&&r!l&&!r
0693
MC/DC50%1/2
$def->{"type"} eq "hash" or $def->{"type"} eq "string-hash"
$def->{"type"} eq "hash" $def->{"type"} eq "string-hash"
Truth table66%2/3
A or B
A= $def->{"type"} eq "hash"B= $def->{"type"} eq "string-hash"
ABresult
1X1
011
000
605 $def->{type} eq 'string-hash' )
606 {
607 6 $opts->{ $k } = $self->_set_get_hash_as_object( $k, $opts->{ $k } );
608 }
609 elsif( $def->{type} eq 'boolean' )
610 {
611 54 ▶ if( exists( $def->{mirror} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"mirror"} and exists $def->{"mirror"}{"value"}) 3 51 54
Condition100%3/3
exists $def->{"mirror"} and exists $def->{"mirror"}{"value"}
!ll&&!rl&&r
18333
MC/DC100%2/2
exists $def->{"mirror"} and exists $def->{"mirror"}{"value"}
exists $def->{"mirror"} exists $def->{"mirror"}{"value"}
Truth table100%3/3
A and B
A= exists $def->{"mirror"}B= exists $def->{"mirror"}{"value"}
ABresult
0X0
100
111
612 exists( $def->{mirror}->{value} ) )
613 {
614 3 $opts->{ $k } = $def->{mirror}->{value};
615 }
616 54 ▶ $opts->{ $k } = ( $opts->{ $k } ? $self->true : $self->false );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{$k} ? : 41 13 54
617 }
618 ▶ elsif( $def->{type} eq 'string' || $def->{type} eq 'scalar' )
Condition66%2/3
$def->{"type"} eq "string" or $def->{"type"} eq "scalar"
l!l&&r!l&&!r
14025
MC/DC50%1/2
$def->{"type"} eq "string" or $def->{"type"} eq "scalar"
$def->{"type"} eq "string" $def->{"type"} eq "scalar"
Truth table66%2/3
A or B
A= $def->{"type"} eq "string"B= $def->{"type"} eq "scalar"
ABresult
1X1
011
000
619 {
620 14 $opts->{ $k } = Module::Generic::Scalar->new( $opts->{ $k } );
621 }
622 ▶ elsif( $def->{type} eq 'integer' || $def->{type} eq 'number' || $def->{type} eq 'float' || $def->{type} eq 'decimal' || $def->{decimal} )
Condition66%8/12
$def->{"type"} eq "integer" or $def->{"type"} eq "number" or $def->{"type"} eq "float" or $def->{"type"} eq "decimal" or $def->{"decimal"}
l!l&&r!l&&!r
7018
$def->{"type"} eq "integer" or $def->{"type"} eq "number" or $def->{"type"} eq "float" or $def->{"type"} eq "decimal"
l!l&&r!l&&!r
7018
$def->{"type"} eq "integer" or $def->{"type"} eq "number" or $def->{"type"} eq "float"
l!l&&r!l&&!r
7018
$def->{"type"} eq "integer" or $def->{"type"} eq "number"
l!l&&r!l&&!r
7018
MC/DC20%1/5
$def->{"type"} eq "integer" or $def->{"type"} eq "number" or $def->{"type"} eq "float" or $def->{"type"} eq "decimal" or $def->{"decimal"}
$def->{"type"} eq "integer" $def->{"type"} eq "number" $def->{"type"} eq "float" $def->{"type"} eq "decimal" $def->{"decimal"}
Truth table33%2/6
A or B or C or D or E
A= $def->{"type"} eq "integer"B= $def->{"type"} eq "number"C= $def->{"type"} eq "float"D= $def->{"type"} eq "decimal"E= $def->{"decimal"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
623 {
624 # Even though this is a number, this was set as a scalar reference, so we need to dereference it
625 7 ▶ if( $self->_is_scalar( $opts->{ $k } ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_scalar($opts->{$k})) { } 6 1 7
626 {
627 6 $opts->{ $k } = Module::Generic::Scalar->new( $opts->{ $k } );
628 }
629 else
630 {
631 1 $opts->{ $k } = $self->_set_get_number( $k, $opts->{ $k } );
632 }
633 }
634 ▶ elsif( $def->{type} eq 'file' && length( $opts->{ $k } // '' ) )
Condition20%1/5
$def->{"type"} eq "file" and length($opts->{$k} // "")
!ll&&!rl&&r
1800
$opts->{$k} // ""
l!l
00
MC/DC0%0/2
$def->{"type"} eq "file" and length($opts->{$k} // "")
$def->{"type"} eq "file" $opts->{$k}
Truth table33%1/3
A and B
A= $def->{"type"} eq "file"B= $opts->{$k}
ABresult
0X0
100
111
635 {
636 0 $opts->{ $k } = file( $opts->{ $k } );
637 }
638 elsif( $def->{type} eq 'file-array' )
639 {
640 0 my $arr = Module::Generic::Array->new;
641 0 foreach( @{$opts->{ $k }} )
642 {
643 0 push( @$arr, file( $_ ) );
644 }
645 0 $opts->{ $k } = $arr;
646 }
647 elsif( $def->{type} eq 'uri' )
648 {
649 0 ▶ my $uri_class = exists( $def->{package} ) ? $def->{package} : exists( $def->{class} ) ? $def->{class} : 'URI';
Branch: 2 branches
BranchTrueFalseTotal
exists $def->{'package'} ? : 0 0 0
exists $def->{'class'} ? : 0 0 0
650 0 $opts->{ $k } = $uri_class->new( $opts->{ $k } );
651 }
652 elsif( $def->{type} eq 'uri-array' )
653 {
654 0 ▶ my $uri_class = exists( $def->{package} ) ? $def->{package} : exists( $def->{class} ) ? $def->{class} : 'URI';
Branch: 2 branches
BranchTrueFalseTotal
exists $def->{'package'} ? : 0 0 0
exists $def->{'class'} ? : 0 0 0
655 0 my $arr = Module::Generic::Array->new;
656 0 foreach( @{$opts->{ $k }} )
657 {
658 0 push( @$arr, $uri_class->new( $_ ) );
659 }
660 0 $opts->{ $k } = $arr;
661 }
662 elsif( $def->{type} eq 'version' )
663 {
664 0 ▶ my $vers_class = exists( $def->{package} ) ? $def->{package} : exists( $def->{class} ) ? $def->{class} : 'version';
Branch: 2 branches
BranchTrueFalseTotal
exists $def->{'package'} ? : 0 0 0
exists $def->{'class'} ? : 0 0 0
665 0 $opts->{ $k } = $vers_class->new( $opts->{ $k } );
666 }
667 }
668 6 return( $self );
669 }
670  
671 7 ▶sub required { return( shift->_set_get_array_as_object( 'required', @_ ) ); }
Subroutine required: called CC=1 SCAR=0.0
Pod documented
672  
673 0 ▶sub usage { return( shift->_set_get_code( 'usage', @_ ) ); }
Subroutine usage: not called CC=1 SCAR=6.9
Pod documented
674  
675 # NOTE: Getopt::Class::Values package
676 package Getopt::Class::Values;
677 BEGIN
678 {
679 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
680 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
681 6 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
682 };
683  
684 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
685 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
686  
687 sub new
688 6 ▶{
Subroutine new: called CC=2 SCAR=7.1
689 6 my $that = shift( @_ );
690 6 my %hash = ();
691 6 my $obj = tie( %hash, 'Getopt::Class::Repository' );
692 6 ▶ my $self = bless( \%hash => ( ref( $that ) || $that ) )->init( @_ );
Condition33%1/3
ref $that || $that
l!l&&r!l&&!r
060
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table33%1/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
693 6 $obj->enable( 1 );
694 6 return( $self );
695 }
696  
697 9 ▶sub debug { return( shift->_set_get_number( 'debug', @_ ) ); }
Subroutine debug: called CC=1 SCAR=0.0
698  
699 sub init
700 6 ▶{
Subroutine init: called CC=17 SCAR=33.2
701 6 my $self = shift( @_ );
702 6 ▶ my $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
600
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
703 6 $self->{data} = {};
704 6 $self->{dict} = {};
705 6 $self->{aliases} = {};
706 # Can only set properties that exist
707 6 $self->{_init_strict} = 1;
708 6 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error( $self->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error($self->error) 6 0 6
709 6 ▶ return( $self->error( "No dictionary as provided." ) ) if( !$self->{dict} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dict"} 0 6 6
710 6 ▶ return( $self->error( "No dictionary as provided." ) ) if( !$self->{aliases} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"aliases"} 0 6 6
711 6 ▶ return( $self->error( "Dictionary provided (", ( $self->{dict} // 'undef' ), ") is not an hash reference." ) ) if( !$self->_is_hash( $self->{dict} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($self->{"dict"}) 0 6 6
Condition0%0/2
$self->{"dict"} // "undef"
l!l
00
MC/DC0%0/1
$self->{"dict"} // "undef"
$self->{"dict"}
Truth table0%0/2
A
A= $self->{"dict"}
Aresult
11
00
712 6 ▶ return( $self->error( "Aliases provided is not an hash reference." ) ) if( !$self->_is_hash( $self->{aliases} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($self->{"aliases"}) 0 6 6
713 6 ▶ scalar( keys( %{$self->{dict}} ) ) || return( $self->error( "No dictionary data was provided." ) );
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %{$$self{"dict"};} or return $self->error("No dictionary data was provided.") 6 0 6
714 6 ▶ return( $self->error( "Data provided is not an hash reference." ) ) if( !$self->_is_hash( $self->{data} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($self->{"data"}) 0 6 6
715 6 my $call_offset = 0;
716 6 ▶ while( my @call_data = caller( $call_offset ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my(@call_data) = caller $call_offset) 12 0 12
717 {
718 12 ▶ unless( $call_offset > 0 && $call_data[0] ne $class && (caller($call_offset-1))[0] eq $class )
Branch: 1 branch
BranchTrueFalseTotal
unless ($call_offset > 0 and $call_data[0] ne $class and (caller $call_offset - 1)[0] eq $class) 6 6 12
Condition66%4/6
$call_offset > 0 and $call_data[0] ne $class and (caller $call_offset - 1)[0] eq $class
!ll&&!rl&&r
606
$call_offset > 0 and $call_data[0] ne $class
!ll&&!rl&&r
606
MC/DC33%1/3
$call_offset > 0 and $call_data[0] ne $class and (caller $call_offset - 1)[0] eq $class
$call_offset > 0 $call_data[0] ne $class (caller $call_offset - 1)[0] eq $class
Truth table50%2/4
A and B and C
A= $call_offset > 0B= $call_data[0] ne $classC= (caller $call_offset - 1)[0] eq $class
ABCresult
0XX0
10X0
1100
1111
719 {
720 6 $call_offset++;
721 6 next;
722 }
723 6 ▶ last if( $call_data[9] || ( $call_offset > 0 && (caller($call_offset-1))[0] ne $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if $call_data[9] or $call_offset > 0 and (caller $call_offset - 1)[0] ne $class 6 0 6
Condition16%1/6
$call_data[9] or $call_offset > 0 and (caller $call_offset - 1)[0] ne $class
l!l&&r!l&&!r
600
$call_offset > 0 and (caller $call_offset - 1)[0] ne $class
!ll&&!rl&&r
000
MC/DC0%0/3
$call_data[9] or $call_offset > 0 and (caller $call_offset - 1)[0] ne $class
$call_data[9] $call_offset > 0 (caller $call_offset - 1)[0] ne $class
Truth table25%1/4
A or B and C
A= $call_data[9]B= $call_offset > 0C= (caller $call_offset - 1)[0] ne $class
ABCresult
1XX1
0111
00X0
0100
724 0 $call_offset++;
725 }
726 6 my $bitmask = ( caller( $call_offset ) )[9];
727 6 my $offset = $warnings::Offsets{uninitialized};
728 6 my $should_display_warning = vec( $bitmask, $offset, 1 );
729 6 $self->{warnings} = $should_display_warning;
730 6 return( $self );
731 }
732  
733 0 ▶sub verbose { return( shift->_set_get_number( 'verbose', @_ ) ); }
Subroutine verbose: not called CC=1 SCAR=6.9
734  
735 # NOTE: AUTOLOAD
736 AUTOLOAD
737 10 ▶{
Subroutine AUTOLOAD: called CC=38 SCAR=68.3
738 10 my( $method ) = our $AUTOLOAD =~ /([^:]+)$/;
739 6 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
740 10 my $self = shift( @_ );
741 10 ▶ my $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
1000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
742 # Options dictionary
743 10 my $dict = $self->{dict};
744 # Values provided on command line
745 10 my $data = $self->{data};
746 # printf( STDERR "AUTOLOAD: \$data has %d items and property '$method' has value '%s'\n", scalar( keys( %$self ) ), $self->{ $method } );
747 # return if( !CORE::exists( $data->{ $method } ) );
748 10 ▶ return if( !CORE::exists( $self->{ $method } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$method} 0 10 10
749 10 my $f = $method;
750 # Dictionary definition for this particular option field
751 10 my $def = $dict->{ $f };
752 10 ▶ if( !exists( $def->{type} ) ||
Branch: 14 branches
BranchTrueFalseTotal
if (not exists $def->{'type'} && defined $def->{'type'}) { } 10 0 10
elsif ($def->{'type'} eq 'boolean' or $self->_is_object($self->{$f}) and $self->{$f}->isa('Module::Generic::Boolean')) { } 0 0 0
elsif ($def->{'type'} eq 'string' or $def->{'type'} eq 'scalar' or builtin::reftype($self->{$f}) eq 'SCALAR') { } 0 0 0
elsif ($def->{'type'} eq 'integer' or $def->{'type'} eq 'number' or $def->{'type'} eq 'numeric' or $def->{'type'} eq 'float' or $def->{'type'} eq 'decimal') { } 0 0 0
elsif ($def->{'type'} eq 'date' or $def->{'type'} eq 'datetime') { } 0 0 0
elsif ($def->{'type'} eq 'array') { } 0 0 0
elsif ($def->{'type'} eq 'hash' or $def->{'type'} eq 'string-hash') { } 0 0 0
elsif ($def->{'type'} eq 'code') { } 0 0 0
elsif ($def->{'type'} eq 'file') { } 0 0 0
elsif ($def->{'type'} eq 'file-array') { } 0 0 0
elsif ($def->{'type'} eq 'uri') { } 0 0 0
elsif ($def->{'type'} eq 'uri-array') { } 0 0 0
elsif ($def->{'type'} eq 'uri') { } 0 0 0
elsif ($def->{'type'} eq 'uri-array') { } 0 0 0
Condition33%1/3
exists $def->{'type'} && defined $def->{'type'}
!ll&&!rl&&r
1000
MC/DC0%0/2
exists $def->{'type'} && defined $def->{'type'}
exists $def->{'type'} defined $def->{'type'}
Truth table33%1/3
A && B
A= exists $def->{'type'}B= defined $def->{'type'}
ABresult
0X0
100
111
753 !defined( $def->{type} ) )
754 {
755 10 ▶ CORE::warn( "Property \"${f}\" has no defined type. Using scalar.\n" ) if( $self->{warnings} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"warnings"} 0 10 10
756 10 return( $self->_set_get_scalar( $f, @_ ) );
757 }
758 ▶ elsif( $def->{type} eq 'boolean' || ( $self->_is_object( $self->{ $f } ) && $self->{ $f }->isa( 'Module::Generic::Boolean' ) ) )
Condition0%0/6
$def->{"type"} eq "boolean" or $self->_is_object($self->{$f}) and $self->{$f}->isa("Module::Generic::Boolean")
l!l&&r!l&&!r
000
$self->_is_object($self->{$f}) and $self->{$f}->isa("Module::Generic::Boolean")
!ll&&!rl&&r
000
MC/DC0%0/3
$def->{"type"} eq "boolean" or $self->_is_object($self->{$f}) and $self->{$f}->isa("Module::Generic::Boolean")
$def->{"type"} eq "boolean" $self->_is_object($self->{$f}) $self->{$f}->isa("Module::Generic::Boolean")
Truth table0%0/4
A or B and C
A= $def->{"type"} eq "boolean"B= $self->_is_object($self->{$f})C= $self->{$f}->isa("Module::Generic::Boolean")
ABCresult
1XX1
0111
00X0
0100
759 {
760 0 return( $self->_set_get_boolean( $f, @_ ) );
761 }
762 ▶ elsif( $def->{type} eq 'string' ||
Condition0%0/6
$def->{"type"} eq "string" or $def->{"type"} eq "scalar" or builtin::reftype($self->{$f}) eq "SCALAR"
l!l&&r!l&&!r
000
$def->{"type"} eq "string" or $def->{"type"} eq "scalar"
l!l&&r!l&&!r
000
MC/DC0%0/3
$def->{"type"} eq "string" or $def->{"type"} eq "scalar" or builtin::reftype($self->{$f}) eq "SCALAR"
$def->{"type"} eq "string" $def->{"type"} eq "scalar" builtin::reftype($self->{$f}) eq "SCALAR"
Truth table0%0/4
A or B or C
A= $def->{"type"} eq "string"B= $def->{"type"} eq "scalar"C= builtin::reftype($self->{$f}) eq "SCALAR"
ABCresult
1XX1
01X1
0011
0000
763 $def->{type} eq 'scalar' ||
764 Scalar::Util::reftype( $self->{ $f } ) eq 'SCALAR' )
765 {
766 0 return( $self->_set_get_scalar_as_object( $f, @_ ) );
767 }
768 ▶ elsif( $def->{type} eq 'integer' ||
Condition0%0/12
$def->{"type"} eq "integer" or $def->{"type"} eq "number" or $def->{"type"} eq "numeric" or $def->{"type"} eq "float" or $def->{"type"} eq "decimal"
l!l&&r!l&&!r
000
$def->{"type"} eq "integer" or $def->{"type"} eq "number" or $def->{"type"} eq "numeric" or $def->{"type"} eq "float"
l!l&&r!l&&!r
000
$def->{"type"} eq "integer" or $def->{"type"} eq "number" or $def->{"type"} eq "numeric"
l!l&&r!l&&!r
000
$def->{"type"} eq "integer" or $def->{"type"} eq "number"
l!l&&r!l&&!r
000
MC/DC0%0/5
$def->{"type"} eq "integer" or $def->{"type"} eq "number" or $def->{"type"} eq "numeric" or $def->{"type"} eq "float" or $def->{"type"} eq "decimal"
$def->{"type"} eq "integer" $def->{"type"} eq "number" $def->{"type"} eq "numeric" $def->{"type"} eq "float" $def->{"type"} eq "decimal"
Truth table0%0/6
A or B or C or D or E
A= $def->{"type"} eq "integer"B= $def->{"type"} eq "number"C= $def->{"type"} eq "numeric"D= $def->{"type"} eq "float"E= $def->{"type"} eq "decimal"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
769 $def->{type} eq 'number' ||
770 $def->{type} eq 'numeric' ||
771 $def->{type} eq 'float' ||
772 $def->{type} eq 'decimal' )
773 {
774 0 return( $self->_set_get_number( $f, @_ ) );
775 }
776 ▶ elsif( $def->{type} eq 'date' ||
Condition0%0/3
$def->{"type"} eq "date" or $def->{"type"} eq "datetime"
l!l&&r!l&&!r
000
MC/DC0%0/2
$def->{"type"} eq "date" or $def->{"type"} eq "datetime"
$def->{"type"} eq "date" $def->{"type"} eq "datetime"
Truth table0%0/3
A or B
A= $def->{"type"} eq "date"B= $def->{"type"} eq "datetime"
ABresult
1X1
011
000
777 $def->{type} eq 'datetime' )
778 {
779 0 return( $self->_set_get_datetime( $f, @_ ) );
780 }
781 elsif( $def->{type} eq 'array' )
782 {
783 0 return( $self->_set_get_array_as_object( $f, @_ ) );
784 }
785 ▶ elsif( $def->{type} eq 'hash' ||
Condition0%0/3
$def->{"type"} eq "hash" or $def->{"type"} eq "string-hash"
l!l&&r!l&&!r
000
MC/DC0%0/2
$def->{"type"} eq "hash" or $def->{"type"} eq "string-hash"
$def->{"type"} eq "hash" $def->{"type"} eq "string-hash"
Truth table0%0/3
A or B
A= $def->{"type"} eq "hash"B= $def->{"type"} eq "string-hash"
ABresult
1X1
011
000
786 $def->{type} eq 'string-hash' )
787 {
788 0 return( $self->_set_get_hash_as_object( $f, @_ ) );
789 }
790 elsif( $def->{type} eq 'code' )
791 {
792 0 return( $self->_set_get_code( $f, @_ ) );
793 }
794 elsif( $def->{type} eq 'file' )
795 {
796 0 return( $self->_set_get_file( $f, @_ ) );
797 }
798 elsif( $def->{type} eq 'file-array' )
799 {
800 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
801 {
802 0 my $arr = Module::Generic::Array->new;
803 0 foreach( @_ )
804 {
805 0 push( @$arr, file( $_ ) );
806 }
807 0 $self->{ $f } = $arr;
808 }
809 0 return( $self->_set_get_array_as_object( $f ) );
810 }
811 elsif( $def->{type} eq 'uri' )
812 {
813 0 ▶ my $uri_class = exists( $def->{package} ) ? $def->{package} : 'URI';
Branch: 1 branch
BranchTrueFalseTotal
exists $def->{'package'} ? : 0 0 0
814 0 return( $self->_set_get_uri( { field => $f, class => $uri_class }, @_ ) );
815 }
816 elsif( $def->{type} eq 'uri-array' )
817 {
818 0 ▶ my $uri_class = exists( $def->{package} ) ? $def->{package} : 'URI';
Branch: 1 branch
BranchTrueFalseTotal
exists $def->{'package'} ? : 0 0 0
819 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
820 {
821 0 my $arr = Module::Generic::Array->new;
822 0 foreach( @_ )
823 {
824 0 push( @$arr, $uri_class->new( $_ ) );
825 }
826 0 $self->{ $f } = $arr;
827 }
828 0 return( $self->_set_get_uri( { field => $f, class => $uri_class } ) );
829 }
830 elsif( $def->{type} eq 'uri' )
831 {
832 0 return( $self->_set_get_uri( $f, @_ ) );
833 }
834 elsif( $def->{type} eq 'uri-array' )
835 {
836 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
837 {
838 0 my $arr = Module::Generic::Array->new;
839 0 foreach( @_ )
840 {
841 0 push( @$arr, file( $_ ) );
842 }
843 0 $self->{ $f } = $arr;
844 }
845 0 return( $self->_set_get_array_as_object( $f ) );
846 }
847 else
848 {
849 0 ▶ CORE::warn( "I do not know what to do with this property \"$f\" type \"$def->{type}\". Using scalar.\n" ) if( $self->{warnings} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"warnings"} 0 0 0
850 0 return( $self->_set_get_scalar( $f, @_ ) );
851 }
852 };
853  
854 # NOTE: Getopt::Class::Repository package
855 package Getopt::Class::Repository;
856 BEGIN
857 {
858 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
859 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
860 6 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
861 6 ▶ use constant VALUES_CLASS => 'Getopt::Class::Value';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
862 };
863  
864 # tie( %self, 'Getopt::Class::Repository' );
865 # Used by Getopt::Class::Values to ensure that whether the data are accessed as methods or as hash keys,
866 # in either way it returns the option data
867 # Actually option data are stored in the Getopt::Class::Values object data property
868 sub TIEHASH
869 6 ▶{
Subroutine TIEHASH: called CC=2 SCAR=7.6
870 6 my $self = shift( @_ );
871 6 ▶ my $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
060
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
872 6 return( bless( { data => {} } => $class ) );
873 }
874  
875 sub CLEAR
876 0 ▶{
Subroutine CLEAR: not called CC=1 SCAR=6.9
877 0 my $self = shift( @_ );
878 0 my $data = $self->{data};
879 0 my $caller = caller;
880 0 %$data = ();
881 }
882  
883 sub DELETE
884 0 ▶{
Subroutine DELETE: not called CC=3 SCAR=24.8
885 0 my $self = shift( @_ );
886 0 my $data = $self->{data};
887 0 my $key = shift( @_ );
888 0 ▶ if( caller eq VALUES_CLASS || !$self->{enable} )
Branch: 1 branch
BranchTrueFalseTotal
if (caller eq 'Getopt::Class::Value' or not $self->{'enable'}) { } 0 0 0
Condition0%0/3
caller eq "Getopt::Class::Value" or not $self->{"enable"}
l!l&&r!l&&!r
000
MC/DC0%0/2
caller eq "Getopt::Class::Value" or not $self->{"enable"}
caller eq "Getopt::Class::Value" not $self->{"enable"}
Truth table0%0/3
A or not(B)
A= caller eq "Getopt::Class::Value"B= not $self->{"enable"}
ABresult
1X1
011
000
889 {
890 0 CORE::delete( $self->{ $key } );
891 }
892 else
893 {
894 0 CORE::delete( $data->{ $key } );
895 }
896 }
897  
898 sub EXISTS
899 1377 ▶{
Subroutine EXISTS: called CC=3 SCAR=11.0
900 1377 my $self = shift( @_ );
901 1377 my $data = $self->{data};
902 1377 my $key = shift( @_ );
903 1377 ▶ if( caller eq VALUES_CLASS || !$self->{enable} )
Branch: 1 branch
BranchTrueFalseTotal
if (caller eq 'Getopt::Class::Value' or not $self->{'enable'}) { } 78 1299 1377
Condition66%2/3
caller eq "Getopt::Class::Value" or not $self->{"enable"}
l!l&&r!l&&!r
0781299
MC/DC50%1/2
caller eq "Getopt::Class::Value" or not $self->{"enable"}
caller eq "Getopt::Class::Value" not $self->{"enable"}
Truth table66%2/3
A or not(B)
A= caller eq "Getopt::Class::Value"B= not $self->{"enable"}
ABresult
1X1
011
000
904 {
905 78 CORE::exists( $self->{ $key } );
906 }
907 else
908 {
909 1299 CORE::exists( $data->{ $key } );
910 }
911 }
912  
913 sub FETCH
914 1375 ▶{
Subroutine FETCH: called CC=3 SCAR=11.0
915 1375 my $self = shift( @_ );
916 1375 my $data = $self->{data};
917 1375 my $key = shift( @_ );
918 1375 my $caller = caller;
919 # print( STDERR "FETCH($caller)[enable=$self->{enable}] <- '$key''\n" );
920 1375 ▶ if( caller eq VALUES_CLASS || !$self->{enable} )
Branch: 1 branch
BranchTrueFalseTotal
if (caller eq 'Getopt::Class::Value' or not $self->{'enable'}) { } 514 861 1375
Condition66%2/3
caller eq "Getopt::Class::Value" or not $self->{"enable"}
l!l&&r!l&&!r
0514861
MC/DC50%1/2
caller eq "Getopt::Class::Value" or not $self->{"enable"}
caller eq "Getopt::Class::Value" not $self->{"enable"}
Truth table66%2/3
A or not(B)
A= caller eq "Getopt::Class::Value"B= not $self->{"enable"}
ABresult
1X1
011
000
921 {
922 # print( STDERR "FETCH($caller)[enable=$self->{enable}] <- '$key' <- '$self->{$key}'\n" );
923 514 return( $self->{ $key } )
924 }
925 else
926 {
927 # print( STDERR "FETCH($caller)[enable=$self->{enable}] <- '$key' <- '$self->{$key}'\n" );
928 861 return( $data->{ $key } );
929 }
930 }
931  
932 sub FIRSTKEY
933 0 ▶{
Subroutine FIRSTKEY: not called CC=3 SCAR=24.8
934 0 my $self = shift( @_ );
935 0 my $data = $self->{data};
936 0 my @keys = ();
937 0 ▶ if( caller eq VALUES_CLASS || !$self->{enable} )
Branch: 1 branch
BranchTrueFalseTotal
if (caller eq 'Getopt::Class::Value' or not $self->{'enable'}) { } 0 0 0
Condition0%0/3
caller eq "Getopt::Class::Value" or not $self->{"enable"}
l!l&&r!l&&!r
000
MC/DC0%0/2
caller eq "Getopt::Class::Value" or not $self->{"enable"}
caller eq "Getopt::Class::Value" not $self->{"enable"}
Truth table0%0/3
A or not(B)
A= caller eq "Getopt::Class::Value"B= not $self->{"enable"}
ABresult
1X1
011
000
938 {
939 0 @keys = keys( %$self );
940 }
941 else
942 {
943 0 @keys = keys( %$data );
944 }
945 0 $self->{ITERATOR} = \@keys;
946 0 return( shift( @keys ) );
947 }
948  
949 sub NEXTKEY
950 0 ▶{
Subroutine NEXTKEY: not called CC=2 SCAR=17.9
951 0 my $self = shift( @_ );
952 0 my $data = $self->{data};
953 0 ▶ my $keys = ref( $self->{ITERATOR} ) ? $self->{ITERATOR} : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'ITERATOR'} ? : 0 0 0
954 0 return( shift( @$keys ) );
955 }
956  
957 sub SCALAR
958 7 ▶{
Subroutine SCALAR: called CC=3 SCAR=11.0
959 7 my $self = shift( @_ );
960 7 my $data = $self->{data};
961 7 ▶ if( caller eq VALUES_CLASS || !$self->{enable} )
Branch: 1 branch
BranchTrueFalseTotal
if (caller eq 'Getopt::Class::Value' or not $self->{'enable'}) { } 6 1 7
Condition66%2/3
caller eq "Getopt::Class::Value" or not $self->{"enable"}
l!l&&r!l&&!r
061
MC/DC50%1/2
caller eq "Getopt::Class::Value" or not $self->{"enable"}
caller eq "Getopt::Class::Value" not $self->{"enable"}
Truth table66%2/3
A or not(B)
A= caller eq "Getopt::Class::Value"B= not $self->{"enable"}
ABresult
1X1
011
000
962 {
963 6 return( scalar( keys( %$self ) ) );
964 }
965 else
966 {
967 1 return( scalar( keys( %$data ) ) );
968 }
969 }
970  
971 sub STORE
972 136 ▶{
Subroutine STORE: called CC=3 SCAR=11.0
973 136 my $self = shift( @_ );
974 136 my $data = $self->{data};
975 136 my( $key, $val ) = @_;
976 # print( STDERR "STORE($caller)[enable=$self->{enable}] -> '$key'\n" );
977 136 ▶ if( caller eq VALUES_CLASS || !$self->{enable} )
Branch: 1 branch
BranchTrueFalseTotal
if (caller eq 'Getopt::Class::Value' or not $self->{'enable'}) { } 126 10 136
Condition66%2/3
caller eq "Getopt::Class::Value" or not $self->{"enable"}
l!l&&r!l&&!r
012610
MC/DC50%1/2
caller eq "Getopt::Class::Value" or not $self->{"enable"}
caller eq "Getopt::Class::Value" not $self->{"enable"}
Truth table66%2/3
A or not(B)
A= caller eq "Getopt::Class::Value"B= not $self->{"enable"}
ABresult
1X1
011
000
978 {
979 # print( STDERR "STORE($caller)[enable=$self->{enable}] -> '$key' -> '$val'\n" );
980 126 $self->{ $key } = $val;
981 }
982 else
983 {
984 # print( STDERR "STORE($caller)[enable=$self->{enable}] -> '$key' -> '$val'\n" );
985 10 $data->{ $key } = $val;
986 }
987 }
988  
989 sub enable
990 18 ▶{
Subroutine enable: called CC=2 SCAR=7.0
991 18 my $self = shift( @_ );
992 18 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 18 0 18
993 {
994 18 $self->{enable} = shift( @_ );
995 }
996 18 return( $self->{enable} );
997 }
998  
999 # NOTE: Getopt::Class::Alias package
1000 # This is an alternative to perl feature of refealiasing
1001 # https://metacpan.org/pod/perlref#Assigning-to-References
1002 package Getopt::Class::Alias;
1003 BEGIN
1004 {
1005 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1006 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1007 6 ▶ use parent -norequire, qw( Getopt::Class::Repository Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
1008 6 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
1009 };
1010  
1011 # tie( %$opts, 'Getopt::Class::Alias', $dictionary );
1012 sub TIEHASH
1013 6 ▶{
Subroutine TIEHASH: called CC=17 SCAR=37.8
1014 # $this is actually the HASH tied
1015 6 my $this = shift( @_ );
1016 6 ▶ my $class = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
060
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
1017 # Valid options are:
1018 # dict: options dictionary
1019 # debug
1020 6 my $opts = {};
1021 6 ▶ $opts = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 6 0 6
1022 # print( STDERR __PACKAGE__ . "::TIEHASH() called with following arguments: '", join( ', ', @_ ), "'.\n" );
1023 6 my $call_offset = 0;
1024 6 ▶ while( my @call_data = caller( $call_offset ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my(@call_data) = caller $call_offset) 18 6 24
1025 {
1026 # printf( STDERR "[$call_offset] In file $call_data[1] at line $call_data[2] from subroutine %s has bitmask $call_data[9]\n", (caller($call_offset+1))[3] );
1027 18 ▶ unless( $call_offset > 0 && $call_data[0] ne $class && (caller($call_offset-1))[0] eq $class )
Branch: 1 branch
BranchTrueFalseTotal
unless ($call_offset > 0 and $call_data[0] ne $class and (caller $call_offset - 1)[0] eq $class) 18 0 18
Condition66%4/6
$call_offset > 0 and $call_data[0] ne $class and (caller $call_offset - 1)[0] eq $class
!ll&&!rl&&r
6120
$call_offset > 0 and $call_data[0] ne $class
!ll&&!rl&&r
6012
MC/DC0%0/3
$call_offset > 0 and $call_data[0] ne $class and (caller $call_offset - 1)[0] eq $class
$call_offset > 0 $call_data[0] ne $class (caller $call_offset - 1)[0] eq $class
Truth table50%2/4
A and B and C
A= $call_offset > 0B= $call_data[0] ne $classC= (caller $call_offset - 1)[0] eq $class
ABCresult
0XX0
10X0
1100
1111
1028 {
1029 # print( STDERR "Skipping package $call_data[0]\n" );
1030 18 $call_offset++;
1031 18 next;
1032 }
1033 0 ▶ last if( $call_data[9] || ( $call_offset > 0 && (caller($call_offset-1))[0] ne $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if $call_data[9] or $call_offset > 0 and (caller $call_offset - 1)[0] ne $class 0 0 0
Condition0%0/6
$call_data[9] or $call_offset > 0 and (caller $call_offset - 1)[0] ne $class
l!l&&r!l&&!r
000
$call_offset > 0 and (caller $call_offset - 1)[0] ne $class
!ll&&!rl&&r
000
MC/DC0%0/3
$call_data[9] or $call_offset > 0 and (caller $call_offset - 1)[0] ne $class
$call_data[9] $call_offset > 0 (caller $call_offset - 1)[0] ne $class
Truth table0%0/4
A or B and C
A= $call_data[9]B= $call_offset > 0C= (caller $call_offset - 1)[0] ne $class
ABCresult
1XX1
0111
00X0
0100
1034 0 $call_offset++;
1035 }
1036 # print( STDERR "Using offset $call_offset with bitmask ", ( caller( $call_offset ) )[9], "\n" );
1037 6 my $bitmask = ( caller( $call_offset - 1 ) )[9];
1038 6 my $offset = $warnings::Offsets{uninitialized};
1039 # print( STDERR "Caller (2)'s bitmask is '$bitmask', warnings offset is '$offset' and vector is '", vec( $bitmask, $offset, 1 ), "'.\n" );
1040 6 ▶ my $should_display_warning = vec( ( $bitmask // 0 ), $offset, 1 );
Condition50%1/2
$bitmask // 0
l!l
60
MC/DC0%0/1
$bitmask // 0
$bitmask
Truth table50%1/2
A
A= $bitmask
Aresult
11
00
1041
1042 6 ▶ my $dict = $opts->{dict} || return( __PACKAGE__->error( "No dictionary was provided to Getopt::Class:Alias" ) );
Condition50%1/2
$opts->{'dict'} || (return __PACKAGE__->error('No dictionary was provided to Getopt::Class:Alias'))
l!l
60
MC/DC0%0/1
$opts->{'dict'} || (return __PACKAGE__->error('No dictionary was provided to Getopt::Class:Alias'))
$opts->{'dict'}
Truth table50%1/2
A
A= $opts->{'dict'}
Aresult
11
00
1043 6 ▶ if( Scalar::Util::reftype( $dict ) ne 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::reftype($dict) ne 'HASH') { } 0 6 6
elsif (not scalar keys %$dict) { } 0 6 6
1044 {
1045 #warn( "Dictionary provided is not an hash reference.\n" ) if( $should_display_warning );
1046 #return;
1047 0 return( __PACKAGE__->error({ message => "Dictionary provided is not an hash reference.", no_return_null_object => 1 }) );
1048 }
1049 elsif( !scalar( keys( %$dict ) ) )
1050 {
1051 #warn( "The dictionary hash reference provided is empty.\n" ) if( $should_display_warning );
1052 #return;
1053 0 return( __PACKAGE__->error( "The dictionary hash reference provided is empty." ) );
1054 }
1055
1056 my $aliases = $opts->{aliases} || do
1057 6 ▶ {
Condition33%1/3
$opts->{'aliases'} || do { return __PACKAGE__->error('No aliases map was provided to Getopt::Class:Alias') }
l!l&&r!l&&!r
600
MC/DC0%0/2
$opts->{'aliases'} || do { return __PACKAGE__->error('No aliases map was provided to Getopt::Class:Alias') }
$opts->{'aliases'} do { return __PACKAGE__->error('No aliases map was provided to Getopt::Class:Alias') }
Truth table33%1/3
A || B
A= $opts->{'aliases'}B= do { return __PACKAGE__->error('No aliases map was provided to Getopt::Class:Alias') }
ABresult
1X1
011
000
1058 #warn( "No aliases map was provided to Getopt::Class:Alias\n" ) if( $should_display_warning );
1059 #return;
1060 0 return( __PACKAGE__->error( "No aliases map was provided to Getopt::Class:Alias" ) );
1061 };
1062 6 ▶ if( Scalar::Util::reftype( $aliases ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($aliases) ne "HASH") 0 6 6
1063 {
1064 #warn( "Aliases map provided is not an hash reference.\n" ) if( $should_display_warning );
1065 #return;
1066 0 return( __PACKAGE__->error( "Aliases map provided is not an hash reference." ) );
1067 }
1068 my $hash =
1069 {
1070 data => {},
1071 dict => $dict,
1072 aliases => $aliases,
1073 warnings => $should_display_warning,
1074 6 ▶ debug => ( $opts->{debug} || 0 ),
Condition50%1/2
$opts->{'debug'} || 0
l!l
06
MC/DC0%0/1
$opts->{'debug'} || 0
$opts->{'debug'}
Truth table50%1/2
A
A= $opts->{'debug'}
Aresult
11
00
1075 # _data_repo => 'data',
1076 colour_open => '<',
1077 colour_close => '>',
1078 };
1079 6 return( bless( $hash => $class ) );
1080 }
1081  
1082 sub FETCH
1083 1322 ▶{
Subroutine FETCH: called CC=1 SCAR=0.0
1084 1322 my $self = shift( @_ );
1085 1322 my $data = $self->{data};
1086 # my $dict = $self->{dict};
1087 1322 my $key = shift( @_ );
1088 # my $def = $dict->{ $key };
1089 1322 return( $data->{ $key } );
1090 }
1091  
1092 sub STORE
1093 262 ▶{
Subroutine STORE: called CC=13 SCAR=32.4
1094 262 my $self = shift( @_ );
1095 262 my $class = ref( $self );
1096 262 my $data = $self->{data};
1097 # Aliases contains both the original dictionary key and all its aliases
1098 262 my $aliases = $self->{aliases};
1099 262 my( $pack, $file, $line ) = caller;
1100 262 my( $key, $val ) = @_;
1101 6 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1102 262 my $dict = $self->{dict};
1103 262 my $enabled = $self->{enable};
1104 my $fallback = sub
1105 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1106 0 my( $k, $v ) = @_;
1107 0 $data->{ $k } = $v;
1108 262 };
1109 262 ▶ if( $enabled && CORE::exists( $aliases->{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($enabled and exists $aliases->{$key}) { } 102 160 262
Condition100%3/3
$enabled and exists $aliases->{$key}
!ll&&!rl&&r
15010102
MC/DC100%2/2
$enabled and exists $aliases->{$key}
$enabled exists $aliases->{$key}
Truth table100%3/3
A and B
A= $enabledB= exists $aliases->{$key}
ABresult
0X0
100
111
1110 {
1111 my $def = $aliases->{ $key } || do
1112 102 ▶ {
Condition33%1/3
$aliases->{$key} || do { warn qq[No dictionary definition found for "$key".\n] if $self->{'warnings'}; return &$fallback($key, $val) }
l!l&&r!l&&!r
10200
MC/DC0%0/2
$aliases->{$key} || do { warn qq[No dictionary definition found for "$key".\n] if $self->{'warnings'}; return &$fallback($key, $val) }
$aliases->{$key} do { warn qq[No dictionary definition found for "$key".\n] if $self->{'warnings'}; return &$fallback($key, $val) }
Truth table33%1/3
A || B
A= $aliases->{$key}B= do { warn qq[No dictionary definition found for "$key".\n] if $self->{'warnings'}; return &$fallback($key, $val) }
ABresult
1X1
011
000
1113 0 ▶ CORE::warn( "No dictionary definition found for \"$key\".\n" ) if( $self->{warnings} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"warnings"} 0 0 0
1114 0 return( $fallback->( $key, $val ) );
1115 };
1116 102 ▶ if( !$self->_is_array( $def->{alias} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_array($def->{"alias"})) 0 102 102
1117 {
1118 0 ▶ CORE::warn( "I was expecting an array reference for this alias, but instead got '$def->{alias}'.\n" ) if( $self->{warnings} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"warnings"} 0 0 0
1119 0 return( $fallback->( $key, $val ) );
1120 }
1121 my $alias = $def->{alias} || do
1122 102 ▶ {
Condition33%1/3
$def->{'alias'} || do { warn "No alias property found. This should not happen.\n" if $self->{'warnings'}; return &$fallback($key, $val) }
l!l&&r!l&&!r
10200
MC/DC0%0/2
$def->{'alias'} || do { warn "No alias property found. This should not happen.\n" if $self->{'warnings'}; return &$fallback($key, $val) }
$def->{'alias'} do { warn "No alias property found. This should not happen.\n" if $self->{'warnings'}; return &$fallback($key, $val) }
Truth table33%1/3
A || B
A= $def->{'alias'}B= do { warn "No alias property found. This should not happen.\n" if $self->{'warnings'}; return &$fallback($key, $val) }
ABresult
1X1
011
000
1123 0 ▶ CORE::warn( "No alias property found. This should not happen.\n" ) if( $self->{warnings} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"warnings"} 0 0 0
1124 0 return( $fallback->( $key, $val ) );
1125 };
1126 102 ▶ if( Scalar::Util::reftype( $alias ) ne 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($alias) ne "ARRAY") 0 102 102
1127 {
1128 0 ▶ CORE::warn( "Alias property is not an array reference. This should not happen.\n" ) if( $self->{warnings} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"warnings"} 0 0 0
1129 0 return( $fallback->( $key, $val ) );
1130 }
1131 102 $data->{ $key } = $val;
1132 102 foreach my $a ( @$alias )
1133 {
1134 172 ▶ next if( $a eq $key );
Branch: 1 branch
BranchTrueFalseTotal
if $a eq $key 102 70 172
1135 # We do not set the value, if for some reason, the user would have removed this key
1136 # $data->{ $a } = $val if( CORE::exists( $data->{ $a } ) );
1137 70 $data->{ $a } = $val;
1138 }
1139 }
1140 else
1141 {
1142 160 $data->{ $key } = $val;
1143 }
1144 }
1145  
1146 6 1;
1147 # NOTE: POD
1148 __END__
↑ Summary