lib/Getopt/Class.pm

filter: Statementstmt 77.9% 459 / 589 Branchbran 49.4% 165 / 334 Conditioncond 37.9% 119 / 314 MC/DCmcdc 14.0% 24 / 171 Subroutinesub 80.7% 63 / 78 Podpod 94.4% 17 / 18 totaltotal 56.3% 847 / 1504 CC 298 SCAR 52.7
CC
298
Cov
60%
AUTOLOAD
922.3
init
335.6
check_class_data
146.9
CRAP 195.0
« blib/lib/Getopt/Class.pm ↑ Summary
1 ##----------------------------------------------------------------------------
2 ## Getopt::Long with Class - ~/lib/m
3 ## Version v1.1.5
4 ## Copyright(c) 2025 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2020/04/25
7 ## Modified 2026/07/04
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 {
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.1.5';
Subroutine BEGIN: called CC=1 SCAR=0.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 {
36 6 ▶ my $self = shift( @_ );
Subroutine init: called CC=78 SCAR=58.2
Pod documented
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 0 6 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 {
126 0 ▶ my( $value ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
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 {
135 0 ▶ my( $value ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
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 {
144 3 ▶ my( $value ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
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 {
154 0 ▶ my( $option, $value ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
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 {
162 3 ▶ my( $option, $value ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
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: 12 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
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
294 132 ▶ if( $def->{min} )
Branch: 1 branch
BranchTrueFalseTotal
if ($def->{"min"}) 6 126 132
295 {
296 # If there is no max, it would be for example s{1,}
297 # 2nd formatter is %s because it could be blank. %d would translate to 0 when blank.
298 6 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
299 6 $suff .= sprintf('{%d,%s}', @$def{ qw( min max ) } );
300 }
301
302 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
303 {
304 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'." ) );
305 }
306 132 push( @$params, $opt . $suff );
307 }
308 6 $self->options( $opts );
309 6 $self->parameters( $params );
310 6 $self->{getopt} = Getopt::Long::Parser->new;
311 6 return( $self );
312 }
313  
314 sub check_class_data
315 {
316 1 ▶ my $self = shift( @_ );
Subroutine check_class_data: called CC=28 SCAR=49.9
Pod documented
317 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
318 1 ▶ return( $self->error( "Class provided '$class' is not a string." ) ) if( ref( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1 1
319 1 my $p = {};
320 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
321 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
322 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
323 1 my $errors =
324 {
325 missing => {},
326 regexp => {},
327 };
328 1 foreach my $f ( sort( keys( %$dict ) ) )
329 {
330 4 my $def = $dict->{ $f };
331 4 ▶ my $n = $def->{name} ? $def->{name} : $f;
Branch: 1 branch
BranchTrueFalseTotal
$def->{'name'} ? : 1 3 4
332 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
333 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
334 {
335 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
336 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
337 0 ( $def->{type} eq 'array' && !scalar( @{$v->{ $f }} ) ) )
338 {
339 0 $errors->{missing}->{ $f } = "$f ($n) is missing";
340 0 next;
341 }
342 }
343 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
344 {
345 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
346 {
347 0 $errors->{regexp}->{ $f } = "$f ($n) " . $def->{error};
348 }
349 elsif( $def->{type} eq 'array' )
350 {
351 1 my $sub_err = [];
352 1 foreach my $this ( @{$v->{ $f }} )
353 {
354 1 ▶ if( $this !~ /$def->{re}/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($this =~ /$def->{"re"}/) 1 0 1
355 {
356 1 push( @$sub_err, $this );
357 }
358 }
359 1 $errors->{regexp}->{ $f } = join( ', ', @$sub_err ) . ' ' . $def->{error};
360 }
361 }
362 ▶ 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
363 {
364 0 $errors->{regexp}->{ $f } = "$f ($n) " . $def->{error};
365 }
366 }
367 1 return( $errors );
368 }
369  
370 sub class
371 {
372 4 ▶ my $self = shift( @_ );
Subroutine class: called CC=15 SCAR=27.9
Pod documented
373 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
374 4 ▶ return( $self->error( "Class provided '$class' is not a string." ) ) if( ref( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 4 4
375 4 my $classes = $self->classes;
376 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
377 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
378 4 my $dict = $self->dictionary;
379 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
380 4 foreach my $k ( sort( keys( %$dict ) ) )
381 {
382 88 my $def = $dict->{ $k };
383 88 ▶ next if( !exists( $def->{class} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $def->{"class"} 68 20 88
384 20 my $class_names = $def->{class};
385 20 my $k2 = $k;
386 20 $k2 =~ tr/-/_/;
387 20 foreach my $class ( @$class_names )
388 {
389 # Create the class if it doe snot exists yet
390 32 ▶ $classes->{ $class } = {} if( !exists( $classes->{ $class } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $classes->{$class} 4 28 32
391 32 my $this = $classes->{ $class };
392 # Then add the property and it definition hash
393 32 $this->{ $k2 } = $def;
394 # If there are any alias, we add them too
395 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
396 {
397 32 foreach my $f ( @{$def->{alias}} )
398 {
399 32 my $f2 = $f;
400 32 $f2 =~ tr/-/_/;
401 32 $this->{ $f } = $this->{ $f2 } = $def;
402 }
403 }
404 }
405 }
406 4 ▶ return( $self->error( "No class \"$class\" was found." ) ) if( !exists( $classes->{ $class } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $classes->{$class} 0 4 4
407 4 return( $classes->{ $class } );
408 }
409  
410 4 ▶sub classes { return( shift->_set_get_hash( 'classes', @_ ) ); }
Subroutine classes: called CC=1 SCAR=0.0
Pod documented
411  
412 sub class_properties
413 {
414 2 ▶ my $self = shift( @_ );
Subroutine class_properties: called CC=2 SCAR=7.0
Pod documented
415 2 my $class = shift( @_ );
416 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
417 2 my $fields = [];
418 2 my $ref = $self->class( $class );
419 2 my $props = [ sort( keys( %$ref ) ) ];
420 2 return( Module::Generic::Array->new( $props ) );
421 }
422  
423 sub configure
424 {
425 6 ▶ my $self = shift( @_ );
Subroutine configure: called CC=6 SCAR=18.9
Pod documented
426 6 ▶ return( $self ) if( $self->{configured} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"configured"} 0 6 6
427 6 my $conf = [];
428 6 ▶ $conf = shift( @_ ) if( ref( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 6 6
429 6 ▶ $conf = $self->configure_options if( !scalar( @$conf ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$conf 6 0 6
430 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
431 6 local $@;
432 # try-catch
433 eval
434 6 {
435 6 $getopt->configure( @$conf );
436 6 $self->{configured} = 1;
437 };
438 6 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 6 6
439 {
440 0 return( $self->error( "An error occurred while configuration Getlong::Opt: $@" ) );
441 }
442 6 return( $self );
443 }
444  
445 6 ▶sub configure_errors { return( shift->_set_get_array_as_object( 'configure_errors', @_ ) ); }
Subroutine configure_errors: called CC=1 SCAR=0.0
Pod documented
446  
447 6 ▶sub configure_options { return( shift->_set_get_array_as_object( 'configure_options', @_ ) ); }
Subroutine configure_options: called CC=1 SCAR=0.0
Pod documented
448  
449 28 ▶sub dictionary { return( shift->_set_get_hash( 'dictionary', @_ ) ); }
Subroutine dictionary: called CC=1 SCAR=0.0
Pod documented
450  
451 sub exec
452 {
453 6 ▶ my $self = shift( @_ );
Subroutine exec: called CC=26 SCAR=44.4
Pod documented
454 6 ▶ $self->configure || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->configure or return 0 6 6
455 6 my $errors = [];
456 6 my $missing = [];
457 6 my $dict = $self->dictionary;
458 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
459 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
460 6 my $opts = $self->options;
461 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
462 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
463 6 my $params = $self->parameters;
464 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
465 6 ▶ return( $self->error( "Somehow, the parameters array is empty!" ) ) if( !scalar( @$params ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$params 0 6 6
466 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
467 6 my $required = $self->required;
468 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
469
470 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
471
472 local $Getopt::Long::SIG{ '__DIE__' } = sub
473 {
474 0 ▶ push( @$errors, join( '', @_ ) );
Subroutine __ANON__: not called CC=1 SCAR=6.9
475 6 };
476 local $Getopt::Long::SIG{ '__WARN__' } = sub
477 {
478 0 ▶ push( @$errors, join( '', @_ ) );
Subroutine __ANON__: not called CC=1 SCAR=6.9
479 6 };
480 6 $self->configure_errors( $errors );
481
482 6 $tie->enable(1);
483 $getopt->getoptions( $opts, @$params ) || do
484 6 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
$getopt->getoptions($opts, @$params) or do { my $usage = $self->usage; return &$usage() if ref $usage eq "CODE"; return } 0 6 6
485 0 my $usage = $self->usage;
486 0 ▶ return( $usage->() ) if( ref( $usage ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $usage eq "CODE" 0 0 0
487 0 return;
488 };
489
490 6 foreach my $key ( @$required )
491 {
492 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};})) 0 0 0
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
010
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 table0%0/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
493 ( !defined( $opts->{ $key } ) ||
494 !length( $opts->{ $key } ) ||
495 $opts->{ $key } =~ /^[[:blank:]]*$/ ||
496 ( ref( $opts->{ $key } ) eq 'SCALAR' &&
497 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
498 ) ||
499 (
500 ref( $opts->{ $key } ) eq 'ARRAY' &&
501 0 !scalar( @{$opts->{ $key }} )
502 )
503 )
504 )
505 {
506 1 push( @$missing, $key );
507 }
508 }
509 6 $self->missing( $missing );
510
511 # Make sure we can access each of the options dictionary definition not just from the original key, but also from any of it aliases
512 6 my $aliases = $self->{aliases};
513 6 foreach my $k ( keys( %$dict ) )
514 {
515 132 my $def = $dict->{ $k };
516 132 $aliases->{ $k } = $def;
517 132 foreach my $a ( @{$def->{alias}} )
518 {
519 210 $aliases->{ $a } = $def;
520 }
521 }
522 6 $tie->enable(1);
523
524 6 $self->postprocess;
525
526 # return( $opts );
527 # e return a Getopt::Class::Values object, so we can call the option values hash key as method:
528 # $object->metadata / $object->metadata( $some_hash );
529 # instead of:
530 # $object->{metadata}
531 # return( $opts );
532 my $o = Getopt::Class::Values->new({
533 data => $opts,
534 dict => $dict,
535 aliases => $aliases,
536 debug => $self->{debug},
537 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
538 6 return( $o );
539 }
540  
541 sub get_class_values
542 {
543 1 ▶ my $self = shift( @_ );
Subroutine get_class_values: called CC=16 SCAR=32.6
Pod documented
544 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
545 1 ▶ return( $self->error( "Class provided '$class' is not a string." ) ) if( ref( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1 1
546 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
547 1 my $opts = $self->options;
548 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
549 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
550 1 my $v = {};
551 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
552 1 foreach my $f ( sort( keys( %$this_dict ) ) )
553 {
554 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
555 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
556 {
557 0 ▶ $v->{ $f } = $opts->{ $f } if( scalar( keys( %{$opts->{ $f }} ) ) > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$$opts{$f};} > 0 0 0 0
558 }
559 elsif( $ref eq 'array' )
560 {
561 1 ▶ $v->{ $f } = $opts->{ $f } if( scalar( @{$opts->{ $f }} ) > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$opts->{$f};} > 0 1 0 1
562 }
563 elsif( !length( $ref ) )
564 {
565 3 ▶ $v->{ $f } = $opts->{ $f } if( length( $opts->{ $f } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $opts->{$f} 0 3 3
566 }
567 }
568 1 return( $v );
569 }
570  
571 12 ▶sub getopt { return( shift->_set_get_object( 'getopt', 'Getopt::Long::Parser', @_ ) ); }
Subroutine getopt: called CC=1 SCAR=0.0
Pod documented
572  
573 7 ▶sub missing { return( shift->_set_get_array_as_object( 'missing', @_ ) ); }
Subroutine missing: called CC=1 SCAR=0.0
Pod documented
574  
575 19 ▶sub options { return( shift->_set_get_hash( 'options', @_ ) ); }
Subroutine options: called CC=1 SCAR=0.0
Pod documented
576  
577 12 ▶sub parameters { return( shift->_set_get_array_as_object( 'parameters', @_ ) ); }
Subroutine parameters: called CC=1 SCAR=0.0
Pod documented
578  
579 sub postprocess
580 {
581 6 ▶ my $self = shift( @_ );
Subroutine postprocess: called CC=35 SCAR=44.8
Pod undocumented
582 6 my $dict = $self->dictionary;
583 6 my $opts = $self->options;
584 6 foreach my $k ( sort( keys( %$dict ) ) )
585 {
586 132 my $def = $dict->{ $k };
587 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
588 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
589
590 107 ▶ if( ( $def->{type} eq 'date' || $def->{type} eq 'datetime' ) && length( $opts->{ $k } ) )
Branch: 10 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
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
591 {
592 2 my $dt = $self->_parse_timestamp( $opts->{ $k } );
593 2 ▶ return( $self->pass_error ) if( !defined( $dt ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dt 0 2 2
594 2 ▶ $opts->{ $k } = $dt if( $dt );
Branch: 1 branch
BranchTrueFalseTotal
if $dt 2 0 2
595 }
596 elsif( $def->{type} eq 'array' )
597 {
598 6 $opts->{ $k } = Module::Generic::Array->new( $opts->{ $k } );
599 }
600 ▶ 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
601 $def->{type} eq 'string-hash' )
602 {
603 6 $opts->{ $k } = $self->_set_get_hash_as_object( $k, $opts->{ $k } );
604 }
605 elsif( $def->{type} eq 'boolean' )
606 {
607 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
608 exists( $def->{mirror}->{value} ) )
609 {
610 3 $opts->{ $k } = $def->{mirror}->{value};
611 }
612 54 ▶ $opts->{ $k } = ( $opts->{ $k } ? $self->true : $self->false );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{$k} ? : 41 13 54
613 }
614 ▶ 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
615 {
616 14 $opts->{ $k } = Module::Generic::Scalar->new( $opts->{ $k } );
617 }
618 ▶ 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
619 {
620 # Even though this is a number, this was set as a scalar reference, so we need to dereference it
621 7 ▶ if( $self->_is_scalar( $opts->{ $k } ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_scalar($opts->{$k})) { } 6 1 7
622 {
623 6 $opts->{ $k } = Module::Generic::Scalar->new( $opts->{ $k } );
624 }
625 else
626 {
627 1 $opts->{ $k } = $self->_set_get_number( $k, $opts->{ $k } );
628 }
629 }
630 ▶ 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
631 {
632 0 $opts->{ $k } = file( $opts->{ $k } );
633 }
634 elsif( $def->{type} eq 'file-array' )
635 {
636 0 my $arr = Module::Generic::Array->new;
637 0 foreach( @{$opts->{ $k }} )
638 {
639 0 push( @$arr, file( $_ ) );
640 }
641 0 $opts->{ $k } = $arr;
642 }
643 elsif( $def->{type} eq 'uri' )
644 {
645 0 ▶ my $uri_class = exists( $def->{package} ) ? $def->{package} : 'URI';
Branch: 1 branch
BranchTrueFalseTotal
exists $def->{'package'} ? : 0 0 0
646 0 $opts->{ $k } = $uri_class->new( $opts->{ $k } );
647 }
648 elsif( $def->{type} eq 'uri-array' )
649 {
650 0 ▶ my $uri_class = exists( $def->{package} ) ? $def->{package} : 'URI';
Branch: 1 branch
BranchTrueFalseTotal
exists $def->{'package'} ? : 0 0 0
651 0 my $arr = Module::Generic::Array->new;
652 0 foreach( @{$opts->{ $k }} )
653 {
654 0 push( @$arr, $uri_class->new( $_ ) );
655 }
656 0 $opts->{ $k } = $arr;
657 }
658 }
659 6 return( $self );
660 }
661  
662 7 ▶sub required { return( shift->_set_get_array_as_object( 'required', @_ ) ); }
Subroutine required: called CC=1 SCAR=0.0
Pod documented
663  
664 0 ▶sub usage { return( shift->_set_get_code( 'usage', @_ ) ); }
Subroutine usage: not called CC=1 SCAR=6.9
Pod documented
665  
666 # NOTE: Getopt::Class::Values package
667 package Getopt::Class::Values;
668 BEGIN
669 {
670 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
671 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
672 6 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
673 };
674  
675 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
676 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
677  
678 sub new
679 {
680 6 ▶ my $that = shift( @_ );
Subroutine new: called CC=2 SCAR=7.1
681 6 my %hash = ();
682 6 my $obj = tie( %hash, 'Getopt::Class::Repository' );
683 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
684 6 $obj->enable( 1 );
685 6 return( $self );
686 }
687  
688 9 ▶sub debug { return( shift->_set_get_number( 'debug', @_ ) ); }
Subroutine debug: called CC=1 SCAR=0.0
689  
690 sub init
691 {
692 6 ▶ my $self = shift( @_ );
Subroutine init: called CC=17 SCAR=33.8
693 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
694 6 $self->{data} = {};
695 6 $self->{dict} = {};
696 6 $self->{aliases} = {};
697 # Can only set properties that exist
698 6 $self->{_init_strict} = 1;
699 6 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error( $self->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error($self->error) 0 6 6
700 6 ▶ return( $self->error( "No dictionary as provided." ) ) if( !$self->{dict} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dict"} 0 6 6
701 6 ▶ return( $self->error( "No dictionary as provided." ) ) if( !$self->{aliases} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"aliases"} 0 6 6
702 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
703 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
704 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.") 0 6 6
705 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
706 6 my $call_offset = 0;
707 6 ▶ while( my @call_data = caller( $call_offset ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my(@call_data) = caller $call_offset) 12 0 12
708 {
709 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) 0 6 6
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
710 {
711 6 $call_offset++;
712 6 next;
713 }
714 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
715 0 $call_offset++;
716 }
717 6 my $bitmask = ( caller( $call_offset ) )[9];
718 6 my $offset = $warnings::Offsets{uninitialized};
719 6 my $should_display_warning = vec( $bitmask, $offset, 1 );
720 6 $self->{warnings} = $should_display_warning;
721 6 return( $self );
722 }
723  
724 0 ▶sub verbose { return( shift->_set_get_number( 'verbose', @_ ) ); }
Subroutine verbose: not called CC=1 SCAR=6.9
725  
726 # NOTE: AUTOLOAD
727 AUTOLOAD
728 {
729 10 ▶ my( $method ) = our $AUTOLOAD =~ /([^:]+)$/;
Subroutine AUTOLOAD: called CC=38 SCAR=68.3
730 6 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
731 10 my $self = shift( @_ );
732 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
733 # Options dictionary
734 10 my $dict = $self->{dict};
735 # Values provided on command line
736 10 my $data = $self->{data};
737 # printf( STDERR "AUTOLOAD: \$data has %d items and property '$method' has value '%s'\n", scalar( keys( %$self ) ), $self->{ $method } );
738 # return if( !CORE::exists( $data->{ $method } ) );
739 10 ▶ return if( !CORE::exists( $self->{ $method } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$method} 0 10 10
740 10 my $f = $method;
741 # Dictionary definition for this particular option field
742 10 my $def = $dict->{ $f };
743 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
744 !defined( $def->{type} ) )
745 {
746 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
747 10 return( $self->_set_get_scalar( $f, @_ ) );
748 }
749 ▶ 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
750 {
751 0 return( $self->_set_get_boolean( $f, @_ ) );
752 }
753 ▶ 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
754 $def->{type} eq 'scalar' ||
755 Scalar::Util::reftype( $self->{ $f } ) eq 'SCALAR' )
756 {
757 0 return( $self->_set_get_scalar_as_object( $f, @_ ) );
758 }
759 ▶ 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
760 $def->{type} eq 'number' ||
761 $def->{type} eq 'numeric' ||
762 $def->{type} eq 'float' ||
763 $def->{type} eq 'decimal' )
764 {
765 0 return( $self->_set_get_number( $f, @_ ) );
766 }
767 ▶ 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
768 $def->{type} eq 'datetime' )
769 {
770 0 return( $self->_set_get_datetime( $f, @_ ) );
771 }
772 elsif( $def->{type} eq 'array' )
773 {
774 0 return( $self->_set_get_array_as_object( $f, @_ ) );
775 }
776 ▶ 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
777 $def->{type} eq 'string-hash' )
778 {
779 0 return( $self->_set_get_hash_as_object( $f, @_ ) );
780 }
781 elsif( $def->{type} eq 'code' )
782 {
783 0 return( $self->_set_get_code( $f, @_ ) );
784 }
785 elsif( $def->{type} eq 'file' )
786 {
787 0 return( $self->_set_get_file( $f, @_ ) );
788 }
789 elsif( $def->{type} eq 'file-array' )
790 {
791 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
792 {
793 0 my $arr = Module::Generic::Array->new;
794 0 foreach( @_ )
795 {
796 0 push( @$arr, file( $_ ) );
797 }
798 0 $self->{ $f } = $arr;
799 }
800 0 return( $self->_set_get_array_as_object( $f ) );
801 }
802 elsif( $def->{type} eq 'uri' )
803 {
804 0 ▶ my $uri_class = exists( $def->{package} ) ? $def->{package} : 'URI';
Branch: 1 branch
BranchTrueFalseTotal
exists $def->{'package'} ? : 0 0 0
805 0 return( $self->_set_get_uri( { field => $f, class => $uri_class }, @_ ) );
806 }
807 elsif( $def->{type} eq 'uri-array' )
808 {
809 0 ▶ my $uri_class = exists( $def->{package} ) ? $def->{package} : 'URI';
Branch: 1 branch
BranchTrueFalseTotal
exists $def->{'package'} ? : 0 0 0
810 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
811 {
812 0 my $arr = Module::Generic::Array->new;
813 0 foreach( @_ )
814 {
815 0 push( @$arr, $uri_class->new( $_ ) );
816 }
817 0 $self->{ $f } = $arr;
818 }
819 0 return( $self->_set_get_uri( { field => $f, class => $uri_class } ) );
820 }
821 elsif( $def->{type} eq 'uri' )
822 {
823 0 return( $self->_set_get_uri( $f, @_ ) );
824 }
825 elsif( $def->{type} eq 'uri-array' )
826 {
827 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
828 {
829 0 my $arr = Module::Generic::Array->new;
830 0 foreach( @_ )
831 {
832 0 push( @$arr, file( $_ ) );
833 }
834 0 $self->{ $f } = $arr;
835 }
836 0 return( $self->_set_get_array_as_object( $f ) );
837 }
838 else
839 {
840 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
841 0 return( $self->_set_get_scalar( $f, @_ ) );
842 }
843 };
844  
845 # NOTE: Getopt::Class::Repository package
846 package Getopt::Class::Repository;
847 BEGIN
848 {
849 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
850 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
851 6 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
852 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
853 };
854  
855 # tie( %self, 'Getopt::Class::Repository' );
856 # Used by Getopt::Class::Values to ensure that whether the data are accessed as methods or as hash keys,
857 # in either way it returns the option data
858 # Actually option data are stored in the Getopt::Class::Values object data property
859 sub TIEHASH
860 {
861 6 ▶ my $self = shift( @_ );
Subroutine TIEHASH: called CC=2 SCAR=7.6
862 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
863 6 return( bless( { data => {} } => $class ) );
864 }
865  
866 sub CLEAR
867 {
868 0 ▶ my $self = shift( @_ );
Subroutine CLEAR: not called CC=1 SCAR=6.9
869 0 my $data = $self->{data};
870 0 my $caller = caller;
871 0 %$data = ();
872 }
873  
874 sub DELETE
875 {
876 0 ▶ my $self = shift( @_ );
Subroutine DELETE: not called CC=3 SCAR=24.8
877 0 my $data = $self->{data};
878 0 my $key = shift( @_ );
879 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
880 {
881 0 CORE::delete( $self->{ $key } );
882 }
883 else
884 {
885 0 CORE::delete( $data->{ $key } );
886 }
887 }
888  
889 sub EXISTS
890 {
891 1377 ▶ my $self = shift( @_ );
Subroutine EXISTS: called CC=3 SCAR=11.0
892 1377 my $data = $self->{data};
893 1377 my $key = shift( @_ );
894 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
895 {
896 78 CORE::exists( $self->{ $key } );
897 }
898 else
899 {
900 1299 CORE::exists( $data->{ $key } );
901 }
902 }
903  
904 sub FETCH
905 {
906 1375 ▶ my $self = shift( @_ );
Subroutine FETCH: called CC=3 SCAR=11.0
907 1375 my $data = $self->{data};
908 1375 my $key = shift( @_ );
909 1375 my $caller = caller;
910 # print( STDERR "FETCH($caller)[enable=$self->{enable}] <- '$key''\n" );
911 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
912 {
913 # print( STDERR "FETCH($caller)[enable=$self->{enable}] <- '$key' <- '$self->{$key}'\n" );
914 514 return( $self->{ $key } )
915 }
916 else
917 {
918 # print( STDERR "FETCH($caller)[enable=$self->{enable}] <- '$key' <- '$self->{$key}'\n" );
919 861 return( $data->{ $key } );
920 }
921 }
922  
923 sub FIRSTKEY
924 {
925 0 ▶ my $self = shift( @_ );
Subroutine FIRSTKEY: not called CC=3 SCAR=24.8
926 0 my $data = $self->{data};
927 0 my @keys = ();
928 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
929 {
930 0 @keys = keys( %$self );
931 }
932 else
933 {
934 0 @keys = keys( %$data );
935 }
936 0 $self->{ITERATOR} = \@keys;
937 0 return( shift( @keys ) );
938 }
939  
940 sub NEXTKEY
941 {
942 0 ▶ my $self = shift( @_ );
Subroutine NEXTKEY: not called CC=2 SCAR=17.9
943 0 my $data = $self->{data};
944 0 ▶ my $keys = ref( $self->{ITERATOR} ) ? $self->{ITERATOR} : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'ITERATOR'} ? : 0 0 0
945 0 return( shift( @$keys ) );
946 }
947  
948 sub SCALAR
949 {
950 7 ▶ my $self = shift( @_ );
Subroutine SCALAR: called CC=3 SCAR=11.0
951 7 my $data = $self->{data};
952 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
953 {
954 6 return( scalar( keys( %$self ) ) );
955 }
956 else
957 {
958 1 return( scalar( keys( %$data ) ) );
959 }
960 }
961  
962 sub STORE
963 {
964 136 ▶ my $self = shift( @_ );
Subroutine STORE: called CC=3 SCAR=11.0
965 136 my $data = $self->{data};
966 136 my( $key, $val ) = @_;
967 # print( STDERR "STORE($caller)[enable=$self->{enable}] -> '$key'\n" );
968 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
969 {
970 # print( STDERR "STORE($caller)[enable=$self->{enable}] -> '$key' -> '$val'\n" );
971 126 $self->{ $key } = $val;
972 }
973 else
974 {
975 # print( STDERR "STORE($caller)[enable=$self->{enable}] -> '$key' -> '$val'\n" );
976 10 $data->{ $key } = $val;
977 }
978 }
979  
980 sub enable
981 {
982 18 ▶ my $self = shift( @_ );
Subroutine enable: called CC=2 SCAR=7.0
983 18 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 18 0 18
984 {
985 18 $self->{enable} = shift( @_ );
986 }
987 18 return( $self->{enable} );
988 }
989  
990 # NOTE: Getopt::Class::Alias package
991 # This is an alternative to perl feature of refealiasing
992 # https://metacpan.org/pod/perlref#Assigning-to-References
993 package Getopt::Class::Alias;
994 BEGIN
995 {
996 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
997 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
998 6 ▶ use parent -norequire, qw( Getopt::Class::Repository Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
999 6 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
1000 };
1001  
1002 # tie( %$opts, 'Getopt::Class::Alias', $dictionary );
1003 sub TIEHASH
1004 {
1005 # $this is actually the HASH tied
1006 6 ▶ my $this = shift( @_ );
Subroutine TIEHASH: called CC=17 SCAR=37.8
1007 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
1008 # Valid options are:
1009 # dict: options dictionary
1010 # debug
1011 6 my $opts = {};
1012 6 ▶ $opts = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 6 0 6
1013 # print( STDERR __PACKAGE__ . "::TIEHASH() called with following arguments: '", join( ', ', @_ ), "'.\n" );
1014 6 my $call_offset = 0;
1015 6 ▶ while( my @call_data = caller( $call_offset ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my(@call_data) = caller $call_offset) 18 6 24
1016 {
1017 # 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] );
1018 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) 12 0 12
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
1019 {
1020 # print( STDERR "Skipping package $call_data[0]\n" );
1021 18 $call_offset++;
1022 18 next;
1023 }
1024 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
1025 0 $call_offset++;
1026 }
1027 # print( STDERR "Using offset $call_offset with bitmask ", ( caller( $call_offset ) )[9], "\n" );
1028 6 my $bitmask = ( caller( $call_offset - 1 ) )[9];
1029 6 my $offset = $warnings::Offsets{uninitialized};
1030 # print( STDERR "Caller (2)'s bitmask is '$bitmask', warnings offset is '$offset' and vector is '", vec( $bitmask, $offset, 1 ), "'.\n" );
1031 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
1032
1033 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
1034 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
1035 {
1036 #warn( "Dictionary provided is not an hash reference.\n" ) if( $should_display_warning );
1037 #return;
1038 0 return( __PACKAGE__->error({ message => "Dictionary provided is not an hash reference.", no_return_null_object => 1 }) );
1039 }
1040 elsif( !scalar( keys( %$dict ) ) )
1041 {
1042 #warn( "The dictionary hash reference provided is empty.\n" ) if( $should_display_warning );
1043 #return;
1044 0 return( __PACKAGE__->error( "The dictionary hash reference provided is empty." ) );
1045 }
1046
1047 my $aliases = $opts->{aliases} || do
1048 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
1049 #warn( "No aliases map was provided to Getopt::Class:Alias\n" ) if( $should_display_warning );
1050 #return;
1051 0 return( __PACKAGE__->error( "No aliases map was provided to Getopt::Class:Alias" ) );
1052 };
1053 6 ▶ if( Scalar::Util::reftype( $aliases ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($aliases) ne "HASH") 0 6 6
1054 {
1055 #warn( "Aliases map provided is not an hash reference.\n" ) if( $should_display_warning );
1056 #return;
1057 0 return( __PACKAGE__->error( "Aliases map provided is not an hash reference." ) );
1058 }
1059 my $hash =
1060 {
1061 data => {},
1062 dict => $dict,
1063 aliases => $aliases,
1064 warnings => $should_display_warning,
1065 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
1066 # _data_repo => 'data',
1067 colour_open => '<',
1068 colour_close => '>',
1069 };
1070 6 return( bless( $hash => $class ) );
1071 }
1072  
1073 sub FETCH
1074 {
1075 1322 ▶ my $self = shift( @_ );
Subroutine FETCH: called CC=1 SCAR=0.0
1076 1322 my $data = $self->{data};
1077 # my $dict = $self->{dict};
1078 1322 my $key = shift( @_ );
1079 # my $def = $dict->{ $key };
1080 1322 return( $data->{ $key } );
1081 }
1082  
1083 sub STORE
1084 {
1085 262 ▶ my $self = shift( @_ );
Subroutine STORE: called CC=13 SCAR=32.4
1086 262 my $class = ref( $self );
1087 262 my $data = $self->{data};
1088 # Aliases contains both the original dictionary key and all its aliases
1089 262 my $aliases = $self->{aliases};
1090 262 my( $pack, $file, $line ) = caller;
1091 262 my( $key, $val ) = @_;
1092 6 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1093 262 my $dict = $self->{dict};
1094 262 my $enabled = $self->{enable};
1095 my $fallback = sub
1096 {
1097 0 ▶ my( $k, $v ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1098 0 $data->{ $k } = $v;
1099 262 };
1100 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
1101 {
1102 my $def = $aliases->{ $key } || do
1103 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
1104 0 ▶ CORE::warn( "No dictionary definition found for \"$key\".\n" ) if( $self->{warnings} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"warnings"} 0 0 0
1105 0 return( $fallback->( $key, $val ) );
1106 };
1107 102 ▶ if( !$self->_is_array( $def->{alias} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_array($def->{"alias"})) 0 102 102
1108 {
1109 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
1110 0 return( $fallback->( $key, $val ) );
1111 }
1112 my $alias = $def->{alias} || do
1113 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
1114 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
1115 0 return( $fallback->( $key, $val ) );
1116 };
1117 102 ▶ if( Scalar::Util::reftype( $alias ) ne 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($alias) ne "ARRAY") 0 102 102
1118 {
1119 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
1120 0 return( $fallback->( $key, $val ) );
1121 }
1122 102 $data->{ $key } = $val;
1123 102 foreach my $a ( @$alias )
1124 {
1125 172 ▶ next if( $a eq $key );
Branch: 1 branch
BranchTrueFalseTotal
if $a eq $key 102 70 172
1126 # We do not set the value, if for some reason, the user would have removed this key
1127 # $data->{ $a } = $val if( CORE::exists( $data->{ $a } ) );
1128 70 $data->{ $a } = $val;
1129 }
1130 }
1131 else
1132 {
1133 160 $data->{ $key } = $val;
1134 }
1135 }
1136  
1137 6 1;
1138 # NOTE: POD
1139 __END__
« blib/lib/Getopt/Class.pm ↑ Summary