lib/Getopt/Class.pm

filter: Statementstmt 73.6% 534 / 725 Branchbran 36.9% 179 / 484 Conditioncond 35.3% 119 / 337 MC/DCmcdc 11.8% 22 / 185 Subroutinesub 81.0% 77 / 95 Podpod 94.4% 17 / 18 totaltotal 51.4% 948 / 1844 CC 378 SCAR 70.2
CC
378
Cov
54%
configure
4950.6
init
229.3
AUTOLOAD
172.2
CRAP 1115.4
↑ Summary blib/lib/Getopt/Class.pm »
1 ##----------------------------------------------------------------------------
2 ## Getopt::Long with Class - ~/lib/Getopt/Class.pm
3 ## Version v0.104.2
4 ## Copyright(c) 2023 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2020/04/25
7 ## Modified 2023/10/11
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;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶ use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 6 ▶ use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 6 ▶ use Module::Generic::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶ use Module::Generic::File qw( file );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶ use Module::Generic::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 6 ▶ use Nice::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 6 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 6 ▶ our $VERSION = 'v0.104.2';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 };
32  
33 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 sub init
37 {
38 6 ▶ my $self = shift( @_ );
Subroutine init: called CC=70 SCAR=54.3
Pod documented
39 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
40 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
41 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
42 6 $self->{configured} = 0;
43 6 $self->{classes} = {};
44 6 $self->{missing} = [];
45 6 $self->{colour_open} = '<';
46 6 $self->{colour_close} = '>';
47 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
48 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
49 6 $self->dictionary( $dict );
50
51 # Set the aliases hash reference used to contain each of the option aliases,e ach pointing to the same dictionary definition
52 6 $self->{aliases} = {};
53
54 # Tie'ing will make sure that values set for a key or its aliases are populated to other aliases
55 # Getopt::Long already does it, but this takes care of synchronising values for all aliases AFTER Getopt::Long has processed the options
56 # So that if the user change an option value using an alias:, e.g.:
57 # last_name => { type => 'string', alias => [qw( surname )] }
58 # last_name and surname would have the same value set thanks to Getopt::Long
59 # --last-name = 'Einstein';
60 # But if, after, the user does something like:
61 # $opts->{surname} = 'Doe';
62 # $opts->{last_name} would still be 'Einstein'
63 # Getopt::Class::Alias ensures the values for aliases and original key are the same seamlessly
64 # The way tie works means we must tie en empty hash, because we cannot tie an already populated hash sadly enough
65 6 my %options = ();
66 my $tie = tie( %options, 'Getopt::Class::Alias',
67 {
68 dict => $dict,
69 aliases => $self->{aliases},
70 # debug => $self->{debug}
71 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
72
73 6 $self->{configure_options} = [qw( no_ignore_case no_auto_abbrev auto_version auto_help )];
74 6 my $opts = \%options;
75 6 my $params = [];
76  
77 6 foreach my $k ( sort( keys( %$dict ) ) )
78 {
79 114 my $k2_dash = $k;
80 114 $k2_dash =~ tr/_/-/;
81 114 my $k2_under = $k;
82 114 $k2_under =~ tr/-/_/;
83
84 114 my $def = $dict->{ $k };
85 114 ▶ next if( $def->{__no_value_assign} );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"__no_value_assign"} 0 114 114
86  
87 # Do some pre-processing work for booleans
88 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
89 {
90 42 my $mirror_opt;
91 # If this is a boolean, add their counterpart, if necessary
92 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
93 !exists( $dict->{ 'without_' . substr( $k, 5 ) } ) )
94 {
95 0 $mirror_opt = 'without_' . substr( $k, 5 );
96 }
97 ▶ 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
98 !exists( $dict->{ 'with_' . substr( $k, 8 ) } ) )
99 {
100 6 $mirror_opt = 'with_' . substr( $k, 8 );
101 }
102 ▶ 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
103 !exists( $dict->{ 'disable_' . substr( $k, 7 ) } ) )
104 {
105 6 $mirror_opt = 'disable_' . substr( $k, 7 );
106 }
107 ▶ 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
108 !exists( $dict->{ 'enable_' . substr( $k, 8 ) } ) )
109 {
110 6 $mirror_opt = 'enable_' . substr( $k, 8 );
111 }
112
113 42 ▶ if( defined( $mirror_opt ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mirror_opt) 18 24 42
114 {
115 18 my $false = 0;
116 my $val = exists( $def->{default} )
117 # ? ( Scalar::Util::reftype( $def->{default} // '' ) eq 'SCALAR' || ref( $def->{default} // '' ) eq 'CODE' )
118 ? ( $self->_is_scalar( $def->{default} ) || $self->_is_code( $def->{default} ) || ref( $def->{default} ) )
119 ? $def->{default}
120 : \$def->{default}
121 : exists( $def->{code} )
122 ? $def->{code}
123 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
124 18 my $copy = Clone::clone( $def );
125 18 $dict->{ $mirror_opt } = $copy;
126 $def->{mirror} = { name => $mirror_opt, toggle => sub
127 {
128 0 ▶ my( $value ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
129 0 $opts->{ $mirror_opt } = int( !$value );
130 18 }};
131 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
132 # A code is used for this boolean, so we create an anon sub that call this sub just like Getopt::Long would
133 18 ▶ if( ref( $val ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq 'CODE') { } 0 18 18
134 {
135 $copy->{mirror} = { name => $k, toggle => sub
136 {
137 0 ▶ my( $value ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
138 0 $val->( $k, int( !$value ) );
139 0 }};
140 }
141 # Otherwise, we create a sub that set the mirror value
142 else
143 {
144 $copy->{mirror} = { name => $k, toggle => sub
145 {
146 3 ▶ my( $value ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
147 3 $opts->{ $k } = int( !$value );
148 18 }};
149 }
150 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
151 # We remove it, because they would be assigned by Getopt::Long even if not triggered and this would bother us.
152 18 delete( $def->{default} );
153 18 delete( $copy->{default} );
154 $def->{default} = sub
155 {
156 0 ▶ my( $option, $value ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
157 0 ▶ return if( $def->{mirror}->{is_set} );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"mirror"}{"is_set"} 0 0 0
158 0 $def->{mirror}->{value} = $value;
159 0 $def->{mirror}->{is_set}++;
160 0 $def->{mirror}->{toggle}->( $value );
161 18 };
162 $copy->{default} = sub
163 {
164 3 ▶ my( $option, $value ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
165 3 ▶ return if( $copy->{mirror}->{is_set} );
Branch: 1 branch
BranchTrueFalseTotal
if $copy->{"mirror"}{"is_set"} 0 3 3
166 3 $copy->{mirror}->{value} = $value;
167 3 $copy->{mirror}->{is_set}++;
168 3 $copy->{mirror}->{toggle}->( $value );
169 18 };
170 18 $def->{__no_value_assign} = 1;
171 }
172 }
173 }
174
175 # Build the options parameters
176 6 foreach my $k ( sort( keys( %$dict ) ) )
177 {
178 132 my $k2_dash = $k;
179 132 $k2_dash =~ tr/_/-/;
180 132 my $k2_under = $k;
181 132 $k2_under =~ tr/-/_/;
182
183 132 my $def = $dict->{ $k };
184
185 132 my $opt_name = [ $k2_under ];
186 # If the dictionary element is given with dash, e.g. some-thing, we replace it with some_thing, which is our standard
187 # and we set some-thing as an alias
188 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
189 {
190 0 $dict->{ $k2_under } = CORE::delete( $dict->{ $k } );
191 0 $k = $k2_under;
192 }
193 # 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
194 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
195  
196 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
197 {
198 18 $def->{alias} = [$def->{alias}];
199 }
200 # Add the given aliases, if any
201 132 ▶ if( $self->_is_array( $def->{alias} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($def->{"alias"})) 18 114 132
202 {
203 18 ▶ push( @$opt_name, @{$def->{alias}} ) if( scalar( @{$def->{alias}} ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$def->{"alias"};} 18 0 18
204 # push( @$opt_name, $k2_under ) if( !scalar( grep( /^$k2_under$/, @{$def->{alias}} ) ) );
205 }
206 # Now, also add the original key-something and key_something to the alias, so we can find them from one of the aliases
207 # When we do exec, we'll be able to find all the aliases
208 132 ▶ $def->{alias} = [] if( !CORE::exists( $def->{alias} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $def->{"alias"} 114 18 132
209 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
210 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
211 132 $def->{alias} = Module::Generic::Array->new( $def->{alias} );
212
213 132 my $opt = join( '|', @$opt_name );
214 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
215 {
216 84 $opts->{ $k2_under } = $def->{default};
217 }
218 else
219 {
220 48 $opts->{ $k2_under } = '';
221 }
222 132 my $suff = '';
223 132 ▶ if( $def->{type} eq 'string' )
Branch: 11 branches
BranchTrueFalseTotal
if ($def->{'type'} eq 'string') { } 24 108 132
elsif ($def->{'type'} eq 'string-hash') { } 6 102 108
elsif ($def->{'type'} eq 'array' or $def->{'type'} eq 'file-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') { } 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
224 {
225 24 $suff = '=s';
226 }
227 elsif( $def->{type} eq 'string-hash' )
228 {
229 6 $suff = '=s%';
230 }
231 ▶ elsif( $def->{type} eq 'array' || $def->{type} eq 'file-array' )
Condition66%2/3
$def->{"type"} eq "array" or $def->{"type"} eq "file-array"
l!l&&r!l&&!r
6096
MC/DC50%1/2
$def->{"type"} eq "array" or $def->{"type"} eq "file-array"
$def->{"type"} eq "array" $def->{"type"} eq "file-array"
Truth table66%2/3
A or B
A= $def->{"type"} eq "array"B= $def->{"type"} eq "file-array"
ABresult
1X1
011
000
232 {
233 6 $suff = '=s@';
234 6 ▶ $opts->{ $k2_under } = [] unless( length( $def->{default} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $def->{"default"} 0 6 6
235 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
236 }
237 elsif( $def->{type} eq 'boolean' )
238 {
239 60 $suff = '!';
240 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
241 ref( $def->{code} ) eq 'CODE' &&
242 # Will not override if a code ref is already assigned
243 ref( $opts->{ $k2_under } // '' ) ne 'CODE' )
244 {
245 0 $opts->{ $k2_under } = $def->{code};
246 }
247 }
248 elsif( $def->{type} eq 'hash' )
249 {
250 0 $suff = '=s%';
251 0 ▶ $opts->{ $k2_under } = {} unless( length( $def->{default} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $def->{"default"} 0 0 0
252 }
253 ▶ 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
254 {
255 18 $opts->{ $k2_under } = $def->{code};
256 }
257 elsif( $def->{type} eq 'integer' )
258 {
259 12 $suff = '=i';
260 }
261 elsif( $def->{type} eq 'decimal' )
262 {
263 0 $suff .= '=f';
264 }
265 ▶ 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
266 {
267 6 $suff = '=s';
268 }
269 elsif( $def->{type} eq 'code' )
270 {
271 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
272 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
273 0 $opts->{ $k2_under } = $def->{code};
274 }
275 elsif( $def->{type} eq 'file' )
276 {
277 0 $suff = '=s';
278 }
279
280 132 ▶ if( $def->{min} )
Branch: 1 branch
BranchTrueFalseTotal
if ($def->{"min"}) 6 126 132
281 {
282 # If there is no max, it would be for example s{1,}
283 # 2nd formatter is %s because it could be blank. %d would translate to 0 when blank.
284 6 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
285 6 $suff .= sprintf('{%d,%s}', @$def{ qw( min max ) } );
286 }
287
288 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
289 {
290 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'." ) );
291 }
292 132 push( @$params, $opt . $suff );
293 }
294 6 $self->options( $opts );
295 6 $self->parameters( $params );
296 6 $self->{getopt} = Getopt::Long::Parser->new;
297 6 return( $self );
298 }
299  
300 sub check_class_data
301 {
302 1 ▶ my $self = shift( @_ );
Subroutine check_class_data: called CC=28 SCAR=49.9
Pod documented
303 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
304 1 ▶ return( $self->error( "Class provided '$class' is not a string." ) ) if( ref( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1 1
305 1 my $p = {};
306 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
307 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
308 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
309 1 my $errors =
310 {
311 missing => {},
312 regexp => {},
313 };
314 1 foreach my $f ( sort( keys( %$dict ) ) )
315 {
316 4 my $def = $dict->{ $f };
317 4 ▶ my $n = $def->{name} ? $def->{name} : $f;
Branch: 1 branch
BranchTrueFalseTotal
$def->{'name'} ? : 1 3 4
318 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
319 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
320 {
321 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
322 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
323 0 ( $def->{type} eq 'array' && !scalar( @{$v->{ $f }} ) ) )
324 {
325 0 $errors->{missing}->{ $f } = "$f ($n) is missing";
326 0 next;
327 }
328 }
329 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
330 {
331 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
332 {
333 0 $errors->{regexp}->{ $f } = "$f ($n) " . $def->{error};
334 }
335 elsif( $def->{type} eq 'array' )
336 {
337 1 my $sub_err = [];
338 1 foreach my $this ( @{$v->{ $f }} )
339 {
340 1 ▶ if( $this !~ /$def->{re}/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($this =~ /$def->{"re"}/) 1 0 1
341 {
342 1 push( @$sub_err, $this );
343 }
344 }
345 1 $errors->{regexp}->{ $f } = join( ', ', @$sub_err ) . ' ' . $def->{error};
346 }
347 }
348 ▶ 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
349 {
350 0 $errors->{regexp}->{ $f } = "$f ($n) " . $def->{error};
351 }
352 }
353 1 return( $errors );
354 }
355  
356 sub class
357 {
358 4 ▶ my $self = shift( @_ );
Subroutine class: called CC=15 SCAR=27.9
Pod documented
359 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
360 4 ▶ return( $self->error( "Class provided '$class' is not a string." ) ) if( ref( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 4 4
361 4 my $classes = $self->classes;
362 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
363 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
364 4 my $dict = $self->dictionary;
365 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
366 4 foreach my $k ( sort( keys( %$dict ) ) )
367 {
368 88 my $def = $dict->{ $k };
369 88 ▶ next if( !exists( $def->{class} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $def->{"class"} 68 20 88
370 20 my $class_names = $def->{class};
371 20 my $k2 = $k;
372 20 $k2 =~ tr/-/_/;
373 20 foreach my $class ( @$class_names )
374 {
375 # Create the class if it doe snot exists yet
376 32 ▶ $classes->{ $class } = {} if( !exists( $classes->{ $class } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $classes->{$class} 4 28 32
377 32 my $this = $classes->{ $class };
378 # Then add the property and it definition hash
379 32 $this->{ $k2 } = $def;
380 # If there are any alias, we add them too
381 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
382 {
383 32 foreach my $f ( @{$def->{alias}} )
384 {
385 32 my $f2 = $f;
386 32 $f2 =~ tr/-/_/;
387 32 $this->{ $f } = $this->{ $f2 } = $def;
388 }
389 }
390 }
391 }
392 4 ▶ return( $self->error( "No class \"$class\" was found." ) ) if( !exists( $classes->{ $class } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $classes->{$class} 0 4 4
393 4 return( $classes->{ $class } );
394 }
395  
396 4 ▶sub classes { return( shift->_set_get_hash( 'classes', @_ ) ); }
Subroutine classes: called CC=1 SCAR=0.0
Pod documented
397  
398 sub class_properties
399 {
400 2 ▶ my $self = shift( @_ );
Subroutine class_properties: called CC=2 SCAR=7.0
Pod documented
401 2 my $class = shift( @_ );
402 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
403 2 my $fields = [];
404 2 my $ref = $self->class( $class );
405 2 my $props = [ sort( keys( %$ref ) ) ];
406 2 return( Module::Generic::Array->new( $props ) );
407 }
408  
409 sub configure
410 {
411 6 ▶ my $self = shift( @_ );
Subroutine configure: called CC=100 SCAR=85.1
Pod documented
412 6 ▶ return( $self ) if( $self->{configured} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"configured"} 0 6 6
413 6 my $conf = [];
414 6 ▶ $conf = shift( @_ ) if( ref( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 6 6
415 6 ▶ $conf = $self->configure_options if( !scalar( @$conf ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$conf 6 0 6
416 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
417 6 ▶ try
Subroutine __ANON__: not called CC=2 SCAR=8.4
Branch: 3 branches
BranchTrueFalseTotal
unless defined $Nice::Try::NEED_TO_RETURN 6 0 6
if ($INC{"threads.pm"} and not exists $INC{"forks.pm"}) 0 6 6
wantarray ? : 0 0 0
Condition33%1/3
$INC{"threads.pm"} and not exists $INC{"forks.pm"}
!ll&&!rl&&r
600
MC/DC0%0/2
$INC{"threads.pm"} and not exists $INC{"forks.pm"}
$INC{"threads.pm"} not exists $INC{"forks.pm"}
Truth table33%1/3
A and not(B)
A= $INC{"threads.pm"}B= not exists $INC{"forks.pm"}
ABresult
0X0
100
111
418 6 ▶ {
Subroutine __ANON__: called CC=17 SCAR=48.4
419 6 $getopt->configure( @$conf );
420 6 $self->{configured} = 1;
421 }
422 6 ▶ catch( $e )
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine __ANON__: not called CC=1 SCAR=3.4
Branch: 34 branches
BranchTrueFalseTotal
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 6 6
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
&$Nice::Try::TRY ? : 0 0 0
if scalar @Nice::Try::VOID 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 6 6
elsif (defined $Nice::Try::WANTARRAY) { } 6 0 6
if defined $Nice::Try::LAST_VAL 0 0 0
length $@ ? : 0 6 6
unless builtin::blessed($@) 6 0 6
if ($Nice::Try::DIED) 0 6 6
if ($Nice::Try::HAS_CATCH) 0 0 0
if not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL 0 6 6
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 6 6
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 6 6
elsif (defined $Nice::Try::WANTARRAY) { } 6 0 6
Condition37%3/8
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
600
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
!ll
60
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
600
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC0%0/1
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
not defined $Nice::Try::WANTARRAY
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
Truth table33%1/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table50%1/2
not(A)
A= not defined $Nice::Try::WANTARRAY
Aresult
00
11
Truth table33%1/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
423 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=22.4
424 0 return( $self->error( "An error occurred while configuration Getlong::Opt: $e" ) );
425 6 ▶ }
Subroutine BEGIN: called CC=1 SCAR=5.3
Subroutine BEGIN: called CC=1 SCAR=5.3
Subroutine BEGIN: called CC=1 SCAR=5.3
Branch: 56 branches
BranchTrueFalseTotal
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 0 0
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
&$Nice::Try::CATCH ? : 0 0 0
if scalar @Nice::Try::VOID 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 0 0
elsif (defined $Nice::Try::WANTARRAY) { } 0 0 0
if $@ 0 0 0
if (defined $Nice::Try::CATCH_DIED) 0 6 6
if (defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq 'return' and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa('Nice::Try::SENTINEL')) { } 0 6 6
elsif (scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa('Nice::Try::SENTINEL')) { } 0 6 6
if defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return" 0 0 0
if (not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return") 0 0 0
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 0 0
if ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
if (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__NEXT__') { } 0 0 0
elsif (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__LAST__') { } 0 0 0
elsif (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__REDO__') { } 0 0 0
elsif (defined $Nice::Try::BREAK and $Nice::Try::BREAK eq 'return') { } 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::WANTARRAY ? : 0 0 0
$Nice::Try::WANTARRAY ? : 0 0 0
scalar @Nice::Try::VOID > 1 ? : 0 0 0
if (defined $Nice::Try::BREAK) 0 6 6
if ($Nice::Try::BREAK eq 'next') { } 0 0 0
elsif ($Nice::Try::BREAK eq 'last') { } 0 0 0
elsif ($Nice::Try::BREAK eq 'redo') { } 0 0 0
scalar @Nice::Try::LAST_VAL > 1 ? : 0 6 6
if not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL 0 0 0
Condition14%7/50
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
000
defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq "return" and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
060
defined $Nice::Try::WANTARRAY or defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
l!l&&r!l&&!r
600
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
000
not builtin::blessed($Nice::Try::RETVAL[0]) or builtin::blessed($Nice::Try::RETVAL[0]) and not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
l!l&&r!l&&!r
006
builtin::blessed($Nice::Try::RETVAL[0]) and not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
060
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
000
not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return"
l!l&&r!l&&!r
000
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
000
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__NEXT__"
!ll&&!rl&&r
000
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__LAST__"
!ll&&!rl&&r
000
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__REDO__"
!ll&&!rl&&r
000
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
000
scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
060
not builtin::blessed($Nice::Try::VOID[0]) or builtin::blessed($Nice::Try::VOID[0]) and not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
l!l&&r!l&&!r
006
builtin::blessed($Nice::Try::VOID[0]) and not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
060
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
!ll
00
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC0%0/6
defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq "return" and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
defined $Nice::Try::WANTARRAY defined $Nice::Try::BREAK $Nice::Try::BREAK eq "return" not builtin::blessed($Nice::Try::RETVAL[0]) builtin::blessed($Nice::Try::RETVAL[0]) not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
MC/DC0%0/2
not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return"
not defined $Nice::Try::BREAK $Nice::Try::BREAK eq "return"
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__NEXT__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__NEXT__"
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__LAST__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__LAST__"
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__REDO__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__REDO__"
MC/DC0%0/4
scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
scalar @Nice::Try::VOID not builtin::blessed($Nice::Try::VOID[0]) builtin::blessed($Nice::Try::VOID[0]) not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
MC/DC0%0/1
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
not defined $Nice::Try::WANTARRAY
Truth table0%0/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table10%1/10
A or B and C and not(D) or E and not(F)
A= defined $Nice::Try::WANTARRAYB= defined $Nice::Try::BREAKC= $Nice::Try::BREAK eq "return"D= not builtin::blessed($Nice::Try::RETVAL[0])E= builtin::blessed($Nice::Try::RETVAL[0])F= not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
ABCDEFresult
00XXXX0
010XXX0
1XX00X0
1XX0100
01100X0
0110100
1XX1XX1
1XX0111
0111XX1
0110111
Truth table0%0/3
not(A) or B
A= not defined $Nice::Try::BREAKB= $Nice::Try::BREAK eq "return"
ABresult
1X1
011
000
Truth table0%0/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__NEXT__"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__LAST__"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__REDO__"
ABresult
0X0
100
111
Truth table20%1/5
A and not(B) or C and not(D)
A= scalar @Nice::Try::VOIDB= not builtin::blessed($Nice::Try::VOID[0])C= builtin::blessed($Nice::Try::VOID[0])D= not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
Truth table0%0/2
not(A)
A= not defined $Nice::Try::WANTARRAY
Aresult
00
11
426 6 return( $self );
427 }
428  
429 6 ▶sub configure_errors { return( shift->_set_get_array_as_object( 'configure_errors', @_ ) ); }
Subroutine configure_errors: called CC=1 SCAR=0.0
Pod documented
430  
431 6 ▶sub configure_options { return( shift->_set_get_array_as_object( 'configure_options', @_ ) ); }
Subroutine configure_options: called CC=1 SCAR=0.0
Pod documented
432  
433 28 ▶sub dictionary { return( shift->_set_get_hash( 'dictionary', @_ ) ); }
Subroutine dictionary: called CC=1 SCAR=0.0
Pod documented
434  
435 sub exec
436 {
437 6 ▶ my $self = shift( @_ );
Subroutine exec: called CC=26 SCAR=44.4
Pod documented
438 6 ▶ $self->configure || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->configure or return 0 6 6
439 6 my $errors = [];
440 6 my $missing = [];
441 6 my $dict = $self->dictionary;
442 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
443 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
444 6 my $opts = $self->options;
445 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
446 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
447 6 my $params = $self->parameters;
448 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
449 6 ▶ return( $self->error( "Somehow, the parameters array is empty!" ) ) if( !scalar( @$params ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$params 0 6 6
450 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
451 6 my $required = $self->required;
452 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
453
454 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
455
456 local $Getopt::Long::SIG{ '__DIE__' } = sub
457 {
458 0 ▶ push( @$errors, join( '', @_ ) );
Subroutine __ANON__: not called CC=1 SCAR=6.9
459 6 };
460 local $Getopt::Long::SIG{ '__WARN__' } = sub
461 {
462 0 ▶ push( @$errors, join( '', @_ ) );
Subroutine __ANON__: not called CC=1 SCAR=6.9
463 6 };
464 6 $self->configure_errors( $errors );
465
466 6 $tie->enable(1);
467 $getopt->getoptions( $opts, @$params ) || do
468 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
469 0 my $usage = $self->usage;
470 0 ▶ return( $usage->() ) if( ref( $usage ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $usage eq "CODE" 0 0 0
471 0 return;
472 };
473
474 6 foreach my $key ( @$required )
475 {
476 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
477 ( !defined( $opts->{ $key } ) ||
478 !length( $opts->{ $key } ) ||
479 $opts->{ $key } =~ /^[[:blank:]]*$/ ||
480 ( ref( $opts->{ $key } ) eq 'SCALAR' &&
481 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
482 ) ||
483 (
484 ref( $opts->{ $key } ) eq 'ARRAY' &&
485 0 !scalar( @{$opts->{ $key }} )
486 )
487 )
488 )
489 {
490 1 push( @$missing, $key );
491 }
492 }
493 6 $self->missing( $missing );
494
495 # Make sure we can access each of the options dictionary definition not just from the original key, but also from any of it aliases
496 6 my $aliases = $self->{aliases};
497 6 foreach my $k ( keys( %$dict ) )
498 {
499 132 my $def = $dict->{ $k };
500 132 $aliases->{ $k } = $def;
501 132 foreach my $a ( @{$def->{alias}} )
502 {
503 210 $aliases->{ $a } = $def;
504 }
505 }
506 6 $tie->enable(1);
507
508 6 $self->postprocess;
509
510 # return( $opts );
511 # e return a Getopt::Class::Values object, so we can call the option values hash key as method:
512 # $object->metadata / $object->metadata( $some_hash );
513 # instead of:
514 # $object->{metadata}
515 # return( $opts );
516 my $o = Getopt::Class::Values->new({
517 data => $opts,
518 dict => $dict,
519 aliases => $aliases,
520 debug => $self->{debug},
521 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
522 6 return( $o );
523 }
524  
525 sub get_class_values
526 {
527 1 ▶ my $self = shift( @_ );
Subroutine get_class_values: called CC=16 SCAR=32.6
Pod documented
528 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
529 1 ▶ return( $self->error( "Class provided '$class' is not a string." ) ) if( ref( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1 1
530 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
531 1 my $opts = $self->options;
532 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
533 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
534 1 my $v = {};
535 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
536 1 foreach my $f ( sort( keys( %$this_dict ) ) )
537 {
538 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
539 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
540 {
541 0 ▶ $v->{ $f } = $opts->{ $f } if( scalar( keys( %{$opts->{ $f }} ) ) > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$$opts{$f};} > 0 0 0 0
542 }
543 elsif( $ref eq 'array' )
544 {
545 1 ▶ $v->{ $f } = $opts->{ $f } if( scalar( @{$opts->{ $f }} ) > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$opts->{$f};} > 0 1 0 1
546 }
547 elsif( !length( $ref ) )
548 {
549 3 ▶ $v->{ $f } = $opts->{ $f } if( length( $opts->{ $f } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $opts->{$f} 0 3 3
550 }
551 }
552 1 return( $v );
553 }
554  
555 12 ▶sub getopt { return( shift->_set_get_object( 'getopt', 'Getopt::Long::Parser', @_ ) ); }
Subroutine getopt: called CC=1 SCAR=0.0
Pod documented
556  
557 7 ▶sub missing { return( shift->_set_get_array_as_object( 'missing', @_ ) ); }
Subroutine missing: called CC=1 SCAR=0.0
Pod documented
558  
559 19 ▶sub options { return( shift->_set_get_hash( 'options', @_ ) ); }
Subroutine options: called CC=1 SCAR=0.0
Pod documented
560  
561 12 ▶sub parameters { return( shift->_set_get_array_as_object( 'parameters', @_ ) ); }
Subroutine parameters: called CC=1 SCAR=0.0
Pod documented
562  
563 sub postprocess
564 {
565 6 ▶ my $self = shift( @_ );
Subroutine postprocess: called CC=24 SCAR=33.9
Pod undocumented
566 6 my $dict = $self->dictionary;
567 6 my $opts = $self->options;
568 6 foreach my $k ( sort( keys( %$dict ) ) )
569 {
570 132 my $def = $dict->{ $k };
571 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
572 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
573
574 107 ▶ if( ( $def->{type} eq 'date' || $def->{type} eq 'datetime' ) && length( $opts->{ $k } ) )
Branch: 8 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') { } 14 25 39
elsif ($def->{'type'} eq 'integer' or $def->{'decimal'}) { } 7 18 25
elsif ($def->{'type'} eq 'file') { } 0 18 18
elsif ($def->{'type'} eq 'file-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
575 {
576 2 my $dt = $self->_parse_timestamp( $opts->{ $k } );
577 2 ▶ return( $self->pass_error ) if( !defined( $dt ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dt 0 2 2
578 2 ▶ $opts->{ $k } = $dt if( $dt );
Branch: 1 branch
BranchTrueFalseTotal
if $dt 2 0 2
579 }
580 elsif( $def->{type} eq 'array' )
581 {
582 6 $opts->{ $k } = Module::Generic::Array->new( $opts->{ $k } );
583 }
584 ▶ 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
585 $def->{type} eq 'string-hash' )
586 {
587 6 $opts->{ $k } = $self->_set_get_hash_as_object( $k, $opts->{ $k } );
588 }
589 elsif( $def->{type} eq 'boolean' )
590 {
591 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
592 exists( $def->{mirror}->{value} ) )
593 {
594 3 $opts->{ $k } = $def->{mirror}->{value};
595 }
596 54 ▶ $opts->{ $k } = ( $opts->{ $k } ? $self->true : $self->false );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{$k} ? : 41 13 54
597 }
598 elsif( $def->{type} eq 'string' )
599 {
600 14 $opts->{ $k } = Module::Generic::Scalar->new( $opts->{ $k } );
601 }
602 ▶ elsif( $def->{type} eq 'integer' || $def->{decimal} )
Condition66%2/3
$def->{"type"} eq "integer" or $def->{"decimal"}
l!l&&r!l&&!r
7018
MC/DC50%1/2
$def->{"type"} eq "integer" or $def->{"decimal"}
$def->{"type"} eq "integer" $def->{"decimal"}
Truth table66%2/3
A or B
A= $def->{"type"} eq "integer"B= $def->{"decimal"}
ABresult
1X1
011
000
603 {
604 # Even though this is a number, this was set as a scalar reference, so we need to dereference it
605 7 ▶ if( $self->_is_scalar( $opts->{ $k } ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_scalar($opts->{$k})) { } 6 1 7
606 {
607 6 $opts->{ $k } = Module::Generic::Scalar->new( $opts->{ $k } );
608 }
609 else
610 {
611 1 $opts->{ $k } = $self->_set_get_number( $k, $opts->{ $k } );
612 }
613 }
614 elsif( $def->{type} eq 'file' )
615 {
616 0 $opts->{ $k } = file( $opts->{ $k } );
617 }
618 elsif( $def->{type} eq 'file-array' )
619 {
620 0 my $arr = Module::Generic::Array->new;
621 0 foreach( @{$opts->{ $k }} )
622 {
623 0 push( @$arr, file( $_ ) );
624 }
625 0 $opts->{ $k } = $arr;
626 }
627 }
628 6 return( $self );
629 }
630  
631 7 ▶sub required { return( shift->_set_get_array_as_object( 'required', @_ ) ); }
Subroutine required: called CC=1 SCAR=0.0
Pod documented
632  
633 0 ▶sub usage { return( shift->_set_get_code( 'usage', @_ ) ); }
Subroutine usage: not called CC=1 SCAR=6.9
Pod documented
634  
635 # NOTE: Getopt::Class::Values package
636 package Getopt::Class::Values;
637 BEGIN
638 {
639 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
640 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
641 6 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
642 6 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
643 };
644  
645 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
646 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
647  
648 sub new
649 {
650 6 ▶ my $that = shift( @_ );
Subroutine new: called CC=2 SCAR=7.1
651 6 my %hash = ();
652 6 my $obj = tie( %hash, 'Getopt::Class::Repository' );
653 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
654 6 $obj->enable( 1 );
655 6 return( $self );
656 }
657  
658 9 ▶sub debug { return( shift->_set_get_number( 'debug', @_ ) ); }
Subroutine debug: called CC=1 SCAR=0.0
659  
660 sub init
661 {
662 6 ▶ my $self = shift( @_ );
Subroutine init: called CC=16 SCAR=32.2
663 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
664 6 $self->{data} = {};
665 6 $self->{dict} = {};
666 6 $self->{aliases} = {};
667 # Can only set properties that exist
668 6 $self->{_init_strict} = 1;
669 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
670 6 ▶ return( $self->error( "No dictionary as provided." ) ) if( !$self->{dict} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dict"} 0 6 6
671 6 ▶ return( $self->error( "No dictionary as provided." ) ) if( !$self->{aliases} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"aliases"} 0 6 6
672 6 ▶ return( $self->error( "Dictionary provided is not an hash reference." ) ) if( !$self->_is_hash( $self->{dict} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($self->{"dict"}) 0 6 6
673 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
674 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
675 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
676 6 my $call_offset = 0;
677 6 ▶ while( my @call_data = caller( $call_offset ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my(@call_data) = caller $call_offset) 12 0 12
678 {
679 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
680 {
681 6 $call_offset++;
682 6 next;
683 }
684 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
685 0 $call_offset++;
686 }
687 6 my $bitmask = ( caller( $call_offset ) )[9];
688 6 my $offset = $warnings::Offsets{uninitialized};
689 6 my $should_display_warning = vec( $bitmask, $offset, 1 );
690 6 $self->{warnings} = $should_display_warning;
691 6 return( $self );
692 }
693  
694 0 ▶sub verbose { return( shift->_set_get_number( 'verbose', @_ ) ); }
Subroutine verbose: not called CC=1 SCAR=6.9
695  
696 AUTOLOAD
697 {
698 10 ▶ my( $method ) = our $AUTOLOAD =~ /([^:]+)$/;
Subroutine AUTOLOAD: called CC=20 SCAR=51.5
699 6 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
700 10 my $self = shift( @_ );
701 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
702 # Options dictionary
703 10 my $dict = $self->{dict};
704 # Values provided on command line
705 10 my $data = $self->{data};
706 # printf( STDERR "AUTOLOAD: \$data has %d items and property '$method' has value '%s'\n", scalar( keys( %$self ) ), $self->{ $method } );
707 # return if( !CORE::exists( $data->{ $method } ) );
708 10 ▶ return if( !CORE::exists( $self->{ $method } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$method} 0 10 10
709 10 my $f = $method;
710 # Dictionary definition for this particular option field
711 10 my $def = $dict->{ $f };
712 10 ▶ if( !exists( $def->{type} ) ||
Branch: 8 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 builtin::reftype($self->{$f}) eq 'SCALAR') { } 0 0 0
elsif ($def->{'type'} eq 'integer' 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
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
713 !defined( $def->{type} ) )
714 {
715 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
716 10 return( $self->_set_get_scalar( $f, @_ ) );
717 }
718 ▶ 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
719 {
720 0 return( $self->_set_get_boolean( $f, @_ ) );
721 }
722 ▶ elsif( $def->{type} eq 'string' ||
Condition0%0/3
$def->{"type"} eq "string" or builtin::reftype($self->{$f}) eq "SCALAR"
l!l&&r!l&&!r
000
MC/DC0%0/2
$def->{"type"} eq "string" or builtin::reftype($self->{$f}) eq "SCALAR"
$def->{"type"} eq "string" builtin::reftype($self->{$f}) eq "SCALAR"
Truth table0%0/3
A or B
A= $def->{"type"} eq "string"B= builtin::reftype($self->{$f}) eq "SCALAR"
ABresult
1X1
011
000
723 Scalar::Util::reftype( $self->{ $f } ) eq 'SCALAR' )
724 {
725 0 return( $self->_set_get_scalar_as_object( $f, @_ ) );
726 }
727 ▶ elsif( $def->{type} eq 'integer' ||
Condition0%0/3
$def->{"type"} eq "integer" or $def->{"type"} eq "decimal"
l!l&&r!l&&!r
000
MC/DC0%0/2
$def->{"type"} eq "integer" or $def->{"type"} eq "decimal"
$def->{"type"} eq "integer" $def->{"type"} eq "decimal"
Truth table0%0/3
A or B
A= $def->{"type"} eq "integer"B= $def->{"type"} eq "decimal"
ABresult
1X1
011
000
728 $def->{type} eq 'decimal' )
729 {
730 0 return( $self->_set_get_number( $f, @_ ) );
731 }
732 ▶ 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
733 $def->{type} eq 'datetime' )
734 {
735 0 return( $self->_set_get_datetime( $f, @_ ) );
736 }
737 elsif( $def->{type} eq 'array' )
738 {
739 0 return( $self->_set_get_array_as_object( $f, @_ ) );
740 }
741 ▶ 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
742 $def->{type} eq 'string-hash' )
743 {
744 0 return( $self->_set_get_hash_as_object( $f, @_ ) );
745 }
746 elsif( $def->{type} eq 'code' )
747 {
748 0 return( $self->_set_get_code( $f, @_ ) );
749 }
750 else
751 {
752 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
753 0 return( $self->_set_get_scalar( $f, @_ ) );
754 }
755 };
756  
757 # NOTE: Getopt::Class::Repository package
758 package Getopt::Class::Repository;
759 BEGIN
760 {
761 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
762 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
763 6 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
764 6 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
765 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
766 };
767  
768 # tie( %self, 'Getopt::Class::Repository' );
769 # Used by Getopt::Class::Values to ensure that whether the data are accessed as methods or as hash keys,
770 # in either way it returns the option data
771 # Actually option data are stored in the Getopt::Class::Values object data property
772 sub TIEHASH
773 {
774 6 ▶ my $self = shift( @_ );
Subroutine TIEHASH: called CC=2 SCAR=7.6
775 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
776 6 return( bless( { data => {} } => $class ) );
777 }
778  
779 sub CLEAR
780 {
781 0 ▶ my $self = shift( @_ );
Subroutine CLEAR: not called CC=1 SCAR=6.9
782 0 my $data = $self->{data};
783 0 my $caller = caller;
784 0 %$data = ();
785 }
786  
787 sub DELETE
788 {
789 0 ▶ my $self = shift( @_ );
Subroutine DELETE: not called CC=3 SCAR=24.8
790 0 my $data = $self->{data};
791 0 my $key = shift( @_ );
792 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
793 {
794 0 CORE::delete( $self->{ $key } );
795 }
796 else
797 {
798 0 CORE::delete( $data->{ $key } );
799 }
800 }
801  
802 sub EXISTS
803 {
804 1377 ▶ my $self = shift( @_ );
Subroutine EXISTS: called CC=3 SCAR=11.0
805 1377 my $data = $self->{data};
806 1377 my $key = shift( @_ );
807 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
808 {
809 78 CORE::exists( $self->{ $key } );
810 }
811 else
812 {
813 1299 CORE::exists( $data->{ $key } );
814 }
815 }
816  
817 sub FETCH
818 {
819 1374 ▶ my $self = shift( @_ );
Subroutine FETCH: called CC=3 SCAR=11.0
820 1374 my $data = $self->{data};
821 1374 my $key = shift( @_ );
822 1374 my $caller = caller;
823 # print( STDERR "FETCH($caller)[enable=$self->{enable}] <- '$key''\n" );
824 1374 ▶ if( caller eq VALUES_CLASS || !$self->{enable} )
Branch: 1 branch
BranchTrueFalseTotal
if (caller eq 'Getopt::Class::Value' or not $self->{'enable'}) { } 514 860 1374
Condition66%2/3
caller eq "Getopt::Class::Value" or not $self->{"enable"}
l!l&&r!l&&!r
0514860
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
825 {
826 # print( STDERR "FETCH($caller)[enable=$self->{enable}] <- '$key' <- '$self->{$key}'\n" );
827 514 return( $self->{ $key } )
828 }
829 else
830 {
831 # print( STDERR "FETCH($caller)[enable=$self->{enable}] <- '$key' <- '$self->{$key}'\n" );
832 860 return( $data->{ $key } );
833 }
834 }
835  
836 sub FIRSTKEY
837 {
838 0 ▶ my $self = shift( @_ );
Subroutine FIRSTKEY: not called CC=3 SCAR=24.8
839 0 my $data = $self->{data};
840 0 my @keys = ();
841 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
842 {
843 0 @keys = keys( %$self );
844 }
845 else
846 {
847 0 @keys = keys( %$data );
848 }
849 0 $self->{ITERATOR} = \@keys;
850 0 return( shift( @keys ) );
851 }
852  
853 sub NEXTKEY
854 {
855 0 ▶ my $self = shift( @_ );
Subroutine NEXTKEY: not called CC=2 SCAR=17.9
856 0 my $data = $self->{data};
857 0 ▶ my $keys = ref( $self->{ITERATOR} ) ? $self->{ITERATOR} : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'ITERATOR'} ? : 0 0 0
858 0 return( shift( @$keys ) );
859 }
860  
861 sub SCALAR
862 {
863 7 ▶ my $self = shift( @_ );
Subroutine SCALAR: called CC=3 SCAR=11.0
864 7 my $data = $self->{data};
865 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
866 {
867 6 return( scalar( keys( %$self ) ) );
868 }
869 else
870 {
871 1 return( scalar( keys( %$data ) ) );
872 }
873 }
874  
875 sub STORE
876 {
877 136 ▶ my $self = shift( @_ );
Subroutine STORE: called CC=3 SCAR=11.0
878 136 my $data = $self->{data};
879 136 my( $key, $val ) = @_;
880 # print( STDERR "STORE($caller)[enable=$self->{enable}] -> '$key'\n" );
881 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
882 {
883 # print( STDERR "STORE($caller)[enable=$self->{enable}] -> '$key' -> '$val'\n" );
884 126 $self->{ $key } = $val;
885 }
886 else
887 {
888 # print( STDERR "STORE($caller)[enable=$self->{enable}] -> '$key' -> '$val'\n" );
889 10 $data->{ $key } = $val;
890 }
891 }
892  
893 sub enable
894 {
895 18 ▶ my $self = shift( @_ );
Subroutine enable: called CC=2 SCAR=7.0
896 18 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 18 0 18
897 {
898 18 $self->{enable} = shift( @_ );
899 }
900 18 return( $self->{enable} );
901 }
902  
903 # NOTE: Getopt::Class::Alias package
904 # This is an alternative to perl feature of refealiasing
905 # https://metacpan.org/pod/perlref#Assigning-to-References
906 package Getopt::Class::Alias;
907 BEGIN
908 {
909 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
910 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
911 6 ▶ use parent -norequire, qw( Getopt::Class::Repository Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
912 6 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
913 6 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
914 };
915  
916 # tie( %$opts, 'Getopt::Class::Alias', $dictionary );
917 sub TIEHASH
918 {
919 # $this is actually the HASH tied
920 6 ▶ my $this = shift( @_ );
Subroutine TIEHASH: called CC=17 SCAR=37.8
921 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
922 # Valid options are:
923 # dict: options dictionary
924 # debug
925 6 my $opts = {};
926 6 ▶ $opts = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 6 0 6
927 # print( STDERR __PACKAGE__ . "::TIEHASH() called with following arguments: '", join( ', ', @_ ), "'.\n" );
928 6 my $call_offset = 0;
929 6 ▶ while( my @call_data = caller( $call_offset ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my(@call_data) = caller $call_offset) 18 6 24
930 {
931 # 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] );
932 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
933 {
934 # print( STDERR "Skipping package $call_data[0]\n" );
935 18 $call_offset++;
936 18 next;
937 }
938 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
939 0 $call_offset++;
940 }
941 # print( STDERR "Using offset $call_offset with bitmask ", ( caller( $call_offset ) )[9], "\n" );
942 6 my $bitmask = ( caller( $call_offset - 1 ) )[9];
943 6 my $offset = $warnings::Offsets{uninitialized};
944 # print( STDERR "Caller (2)'s bitmask is '$bitmask', warnings offset is '$offset' and vector is '", vec( $bitmask, $offset, 1 ), "'.\n" );
945 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
946
947 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
948 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
949 {
950 #warn( "Dictionary provided is not an hash reference.\n" ) if( $should_display_warning );
951 #return;
952 0 return( __PACKAGE__->error({ message => "Dictionary provided is not an hash reference.", no_return_null_object => 1 }) );
953 }
954 elsif( !scalar( keys( %$dict ) ) )
955 {
956 #warn( "The dictionary hash reference provided is empty.\n" ) if( $should_display_warning );
957 #return;
958 0 return( __PACKAGE__->error( "The dictionary hash reference provided is empty." ) );
959 }
960
961 my $aliases = $opts->{aliases} || do
962 6 ▶ {
Condition33%1/3
$opts->{'aliases'} || do {
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
963 #warn( "No aliases map was provided to Getopt::Class:Alias\n" ) if( $should_display_warning );
964 #return;
965 0 return( __PACKAGE__->error( "No aliases map was provided to Getopt::Class:Alias" ) );
966 };
967 6 ▶ if( Scalar::Util::reftype( $aliases ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($aliases) ne "HASH") 0 6 6
968 {
969 #warn( "Aliases map provided is not an hash reference.\n" ) if( $should_display_warning );
970 #return;
971 0 return( __PACKAGE__->error( "Aliases map provided is not an hash reference." ) );
972 }
973 my $hash =
974 {
975 data => {},
976 dict => $dict,
977 aliases => $aliases,
978 warnings => $should_display_warning,
979 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
980 # _data_repo => 'data',
981 colour_open => '<',
982 colour_close => '>',
983 };
984 6 return( bless( $hash => $class ) );
985 }
986  
987 sub FETCH
988 {
989 1321 ▶ my $self = shift( @_ );
Subroutine FETCH: called CC=1 SCAR=0.0
990 1321 my $data = $self->{data};
991 # my $dict = $self->{dict};
992 1321 my $key = shift( @_ );
993 # my $def = $dict->{ $key };
994 1321 return( $data->{ $key } );
995 }
996  
997 sub STORE
998 {
999 262 ▶ my $self = shift( @_ );
Subroutine STORE: called CC=17 SCAR=36.7
1000 262 my $class = ref( $self );
1001 262 my $data = $self->{data};
1002 # Aliases contains both the original dictionary key and all its aliases
1003 262 my $aliases = $self->{aliases};
1004 262 my( $pack, $file, $line ) = caller;
1005 262 my( $key, $val ) = @_;
1006 262 ▶ $self->message_colour( 3, "Called from line $line in file \"$file\" for property \"<green>$key</>\" with reference (<black on white>", ref( $val ), "</>) and value \"<red>" . ( $val // 'undef' ) . "</>\">" );
Condition50%1/2
$val // "undef"
l!l
2620
MC/DC0%0/1
$val // "undef"
$val
Truth table50%1/2
A
A= $val
Aresult
11
00
1007 262 my $dict = $self->{dict};
1008 262 my $enabled = $self->{enable};
1009 my $fallback = sub
1010 {
1011 0 ▶ my( $k, $v ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1012 0 $data->{ $k } = $v;
1013 262 };
1014 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
1015 {
1016 my $def = $aliases->{ $key } || do
1017 102 ▶ {
Condition33%1/3
$aliases->{$key} || do {
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
1018 0 ▶ CORE::warn( "No dictionary definition found for \"$key\".\n" ) if( $self->{warnings} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"warnings"} 0 0 0
1019 0 return( $fallback->( $key, $val ) );
1020 };
1021 102 ▶ if( !$self->_is_array( $def->{alias} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_array($def->{"alias"})) 0 102 102
1022 {
1023 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
1024 0 return( $fallback->( $key, $val ) );
1025 }
1026 my $alias = $def->{alias} || do
1027 102 ▶ {
Condition33%1/3
$def->{'alias'} || do {
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
1028 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
1029 0 return( $fallback->( $key, $val ) );
1030 };
1031 # $self->messagef_colour( 3, 'Found alias "{green}' . $alias . '{/}" with %d elements: {green}"%s"{/}', scalar( @$alias ), $alias->join( "', '" ) );
1032 102 $self->messagef_colour( 3, "Found alias '<green>$alias</>' with %d elements: <green>'%s'</>", scalar( @$alias ), $alias->join( "', '" ) );
1033 102 ▶ if( Scalar::Util::reftype( $alias ) ne 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($alias) ne "ARRAY") 0 102 102
1034 {
1035 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
1036 0 return( $fallback->( $key, $val ) );
1037 }
1038 102 ▶ $self->message_colour( 3, "Setting primary property \"<green>${key}</>\" to value \"<black on white>" . ( $val // '' ) . "</>\"." );
Condition50%1/2
$val // ""
l!l
1020
MC/DC0%0/1
$val // ""
$val
Truth table50%1/2
A
A= $val
Aresult
11
00
1039 102 $data->{ $key } = $val;
1040 102 foreach my $a ( @$alias )
1041 {
1042 172 ▶ next if( $a eq $key );
Branch: 1 branch
BranchTrueFalseTotal
if $a eq $key 102 70 172
1043 # We do not set the value, if for some reason, the user would have removed this key
1044 70 ▶ $self->message_colour( 3, "Setting alias \"<green>${a}</>\" to value \"<val black on white>", ( $val // '' ), "</>\" (ref=", ref( $val // '' ), ")." );
Condition50%2/4
$val // ""
l!l
700
$val // ""
l!l
700
MC/DC0%0/1
$val // ""
$val
MC/DC0%0/1
$val // ""
$val
Truth table50%1/2
A
A= $val
Aresult
11
00
Truth table50%1/2
A
A= $val
Aresult
11
00
1045 # $data->{ $a } = $val if( CORE::exists( $data->{ $a } ) );
1046 70 $data->{ $a } = $val;
1047 }
1048 }
1049 else
1050 {
1051 160 $data->{ $key } = $val;
1052 }
1053 }
1054  
1055 6 1;
1056 # NOTE: POD
1057 __END__
1058 6 ▶ 
Subroutine BEGIN: called CC=1 SCAR=0.0
1059 =encoding utf-8
1060  
1061 6 ▶=head1 NAME
Subroutine CHECK: called CC=2 SCAR=6.9
1062  
1063 Getopt::Class - Extended dictionary version of Getopt::Long
1064  
1065 6 =head1 SYNOPSIS
1066 6  
1067 6 ▶ use Getopt::Class;
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<:scalar", \$nice_try_data_block_str or die $! 0 6 6
1068 6 ▶ our $DEBUG = 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
1069 6 ▶ our $VERBOSE = 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
1070 6 our $VERSION = '0.1';
1071 my $dict =
1072 {
1073 create_user => { type => 'boolean', alias => [qw(create_person create_customer)], action => 1 },
1074 6 create_product => { type => 'boolean', action => 1 },
1075 debug => { type => 'integer', default => \$DEBUG },
1076 # Can be enabled with --enable-recurse
1077 disable_recurse => { type => 'boolean', default => 1 },
1078 # Can be disabled also with --disable-logging
1079 enable_logging => { type => 'boolean', default => 0 },
1080 help => { type => 'code', code => sub{ pod2usage(1); }, alias => '?', action => 1 },
1081 man => { type => 'code', code => sub{ pod2usage( -exitstatus => 0, -verbose => 2 ); }, action => 1 },
1082 quiet => { type => 'boolean', default => 0, alias => 'silent' },
1083 verbose => { type => 'boolean', default => \$VERBOSE, alias => 'v' },
1084 version => { type => 'code', code => sub{ printf( "v%.2f\n", $VERSION ); }, action => 1 },
1085
1086 api_server => { type => 'string', default => 'api.example.com' },
1087 api_version => { type => 'string', default => 1 },
1088 as_admin => { type => 'boolean' },
1089 dry_run => { type => 'boolean', default => 0 },
1090
1091 # Can be enabled also with --with-zlib
1092 without_zlib => { type => 'integer', default => 1 },
1093
1094 name => { type => 'string', class => [qw( person product )] },
1095 created => { type => 'datetime', class => [qw( person product )] },
1096 define => { type => 'string-hash', default => {} },
1097 langs => { type => 'array', class => [qw( person product )], re => qr/^[a-z]{2}([_|-][A-Z]{2})?/, min => 1, default => [qw(en)] },
1098 currency => { type => 'string', class => [qw(product)], name => 'currency', re => qr/^[a-z]{3}$/, error => "must be a three-letter iso 4217 value" },
1099 age => { type => 'integer', class => [qw(person)], name => 'age', },
1100 path => { type => 'file' },
1101 skip => { type => 'file-array' },
1102 };
1103
1104 # Assuming command line arguments like:
1105 prog.pl --create-user --name Bob --langs fr ja --age 30 --created now --debug 3 \
1106 --path ./here/some/where --skip ./bad/directory ./not/here ./avoid/me/
1107  
1108 my $opt = Getopt::Class->new({
1109 dictionary => $dict,
1110 }) || die( Getopt::Class->error, "\n" );
1111 my $opts = $opt->exec || die( $opt->error, "\n" );
1112 $opt->required( [qw( name langs )] );
1113 my $err = $opt->check_class_data( 'person' );
1114 printf( "User is %s and is %d years old\n", $opts{qw( name age )} ) if( $opts->{debug} );
1115  
1116 # Get all the properties for class person
1117 my $props = $opt->class_properties( 'person' );
1118  
1119 # Get values collected for class 'person'
1120 if( $opts->{create_user} )
1121 {
1122 my $values = $opt->get_class_values( 'person' );
1123 # Having collected the values for our class of properties, and making sure all
1124 # required are here, we can add them to database or make api calls, etc
1125 }
1126 elsif( $opts->{create_product} )
1127 {
1128 # etc...
1129 }
1130
1131 # Or you can also access those values as object methods
1132 if( $opts->create_product )
1133 {
1134 $opts->langs->push( 'en_GB' ) if( !$opts->langs->length );
1135 printf( "Created on %s\n", $opts->created->iso8601 );
1136 }
1137  
1138 =head1 VERSION
1139  
1140 v0.104.2
1141  
1142 =head1 DESCRIPTION
1143  
1144 L<Getopt::Class> is a lightweight wrapper around L<Getopt::Long> that implements the idea of class of properties and makes it easier and powerful to set up L<Getopt::Long>. This module is particularly useful if you want to provide several sets of options for different features or functions of your program. For example, you may have a part of your program that deals with user while another deals with product. Each of them needs their own properties to be provided.
1145  
1146 =head1 CONSTRUCTOR
1147  
1148 =head2 new
1149  
1150 To instantiate a new L<Getopt::Class> object, pass an hash reference of following parameters:
1151  
1152 =over 4
1153  
1154 =item * C<dictionary>
1155  
1156 This is required. It must contain a key value pair where the value is an anonymous hash reference that can contain the following parameters:
1157  
1158 =over 8
1159  
1160 =item * C<alias>
1161  
1162 This is an array reference of alternative options that can be used in an interchangeable way
1163  
1164 my $dict =
1165 {
1166 last_name => { type => 'string', alias => [qw( family_name surname )] },
1167 };
1168 # would make it possible to use either of the following combinations
1169 --last-name Doe
1170 # or
1171 --surname Doe
1172 # or
1173 --family-name Doe
1174  
1175 =item * C<default>
1176  
1177 This contains the default value. For a string, this could be anything, and also a reference to a scalar, such as:
1178  
1179 our $DEBUG = 0;
1180 my $dict =
1181 {
1182 debug => { type => 'integer', default => \$DEBUG },
1183 };
1184  
1185 It can also be used to provide default value for an array, such as:
1186  
1187 my $dict =
1188 {
1189 langs => { type => 'array', class => [qw( person product )], re => qr/^[a-z]{2}([_|-][A-Z]{2})?/, min => 1, default => [qw(en)] },
1190 };
1191  
1192 But beware that if you provide a value, it will not superseed the existing default value, but add it on top of it, so
1193  
1194 --langs en fr ja
1195  
1196 would not produce an array with C<en>, C<fr> and C<ja> entries, but an array such as:
1197  
1198 ['en', 'en', 'fr', 'ja' ]
1199  
1200 because the initial default value is not replaced when one is provided. This is a design from L<Getopt::Long> and although I could circumvent this, I a not sure I should.
1201  
1202 =item * C<error>
1203  
1204 A string to be used to set an error by L</"check_class_data">. Typically the string should provide meaningful information as to what the data should normally be. For example:
1205  
1206 my $dict =
1207 {
1208 currency => { type => 'string', class => [qw(product)], name => 'currency', re => qr/^[a-z]{3}$/, error => "must be a three-letter iso 4217 value" },
1209 };
1210  
1211 =item * C<file>
1212  
1213 This type will mark the value as a directory or file path and will become a L<Module::Generic::File> object.
1214  
1215 This is particularly convenient when the user provided you with a relative path, such as:
1216  
1217 ./my_prog.pl --debug 3 --path ./here/
1218  
1219 And if you are not very careful and inadvertently change directory like when using L<File::Find>, then this relative path could lead to some unpleasant surprise.
1220  
1221 Setting this argument type to C<file> ensure the resulting value is a L<Module::Generic::File>, whose underlying file or directory will be resolved to their absolute path.
1222  
1223 =item * C<file-array>
1224  
1225 Same as I<file> argument type, but allows multiple value saved as an array. For example:
1226  
1227 ./my_prog.pl --skip ./not/here ./avoid/me/ ./skip/this/directory
1228  
1229 This would result in the option property I<skip> being an L<array object|Module::Generic::Array> containing 3 entries.
1230  
1231 =item * C<max>
1232  
1233 This is well explained in L<Getopt::Long/"Options with multiple values">
1234  
1235 It serves "to specify the minimal and maximal number of arguments an option takes".
1236  
1237 =item * C<min>
1238  
1239 Same as above
1240  
1241 =item * C<re>
1242  
1243 This must be a regular expression and is used by L</"check_class_data"> to check the sanity of the data provided by the user.
1244 So, for example:
1245  
1246 my $dict =
1247 {
1248 currency => { type => 'string', class => [qw(product)], name => 'currency', re => qr/^[a-z]{3}$/, error => "must be a three-letter iso 4217 value" },
1249 };
1250  
1251 then the user calls your program with, among other options:
1252  
1253 --currency euro
1254  
1255 would set an error that can be retrieved as an output of L</"check_class_data">
1256  
1257 =item * C<required>
1258  
1259 Set this to true or false (1 or 0) to instruct L</"check_class_data"> whether to check if it is missing or not.
1260  
1261 This is an alternative to the L</"required"> method which is used at an earlier stage, during L</"exec">
1262  
1263 =item * C<type>
1264  
1265 Type can be C<array>, C<boolean>, C<code>, C<datetime>, C<decimal>, C<file>, C<hash>, C<integer>, C<string>, C<string-hash>
1266  
1267 Type C<hash> is convenient for free key-value pair such as:
1268  
1269 --define customer_id=10 --define transaction_id 123
1270  
1271 would result for C<define> with an anonymous hash as value containing C<customer_id> with value C<10> and C<transaction_id> with value C<123>
1272  
1273 Type code implies an anonymous sub routine and should be accompanied with the attribute I<code>, such as:
1274  
1275 { type => 'code', code => sub{ pod2usage(1); exit( 0 ) }, alias => '?', action => 1 },
1276  
1277 If type is C<boolean> and the key is either C<with>, C<without>, C<enable>, C<disable>, their counterpart will automatically be available as well, such as you can do, as show in the excerpt in the synopsis above:
1278  
1279 --enable-recurse --with-zlib
1280  
1281 Be careful though. If, in your dictionary, as shown in the synopsis, you defined C<without_zlib> with a default value of true, then using the option C<--with-zlib> will set that value to false. So in your application, you would need to check like this:
1282  
1283 if( $opts->{without_zlib} )
1284 {
1285 # Do something
1286 }
1287 else
1288 {
1289 # Do something else
1290 }
1291  
1292 Also as seen in the example above, you can add additional properties to be used in your program, here such as C<action> that could be used to identify all options that are used to trigger an action or a call to a sub routine.
1293  
1294 =back
1295  
1296 =item * C<debug>
1297  
1298 This takes an integer, and is used to set the level of debugging. Anything under 3 will not provide anything meaningful.
1299  
1300 =back
1301  
1302 =head1 METHODS
1303  
1304 =head2 check_class_data
1305  
1306 Provided with a string corresponding to a class name, this will check the data provided by the user.
1307  
1308 Currently this means it checks if the data is present when the attribute I<required> is set, and it checks the data against a regular expression if one is provided with the attribute I<re>
1309  
1310 It returns an hash reference with 2 keys: I<missing> and I<regexp>. Each with an anonymous hash reference with key matching the option name and the value the error string. So:
1311  
1312 my $dict =
1313 {
1314 name => { type => 'string', class => [qw( person product )], required => 1 },
1315 langs => { type => 'array', class => [qw( person product )], re => qr/^[a-z]{2}([_|-][A-Z]{2})?/, min => 1, default => [qw(en)] },
1316 };
1317  
1318 Assuming your user calls your program without C<--name> and with C<--langs FR EN> this would have L</"check_class_data"> return the following data structure:
1319  
1320 $errors =
1321 {
1322 missing => { name => "name (name) is missing" },
1323 regexp => { langs => "langs (langs) does not match requirements" },
1324 };
1325  
1326 =head2 class
1327  
1328 Provided with a string representing a property class, and this returns an hash reference of all the dictionary entries matching this class
1329  
1330 =head2 classes
1331  
1332 This returns an hash reference containing class names, each of which has an anonymous hash reference with corresponding dictionary entries
1333  
1334 =head2 class_properties
1335  
1336 Provided with a string representing a class name, this returns an array reference of options, a.k.a. class properties.
1337  
1338 The array reference is a L<Module::Generic::Array> object.
1339  
1340 =head2 configure
1341  
1342 This calls L<Getopt::Long/"configure"> with the L</"configure_options">.
1343  
1344 It can be overriden by calling L</"configure"> with an array reference.
1345  
1346 If there is an error, it will return undef and set an L</"error"> accordingly.
1347  
1348 Otherwise, it returns the L<Getopt::Class> object, so it can be chained.
1349  
1350 =head2 configure_errors
1351  
1352 This returns an array reference of the errors generated by L<Getopt::Long> upon calling L<Getopt::Long/"getoptions"> by L</"exec">
1353  
1354 The array is an L<Module::Generic::Array> object
1355  
1356 =head2 configure_options
1357  
1358 This returns an array reference of the L<Getopt::Long> configuration options upon calling L<Getopt::Long/"configure"> by method L</"configure">
1359  
1360 The array is an L<Module::Generic::Array> object
1361  
1362 =head2 dictionary
1363  
1364 This returns the hash reference representing the dictionary set when the object was instantiated. See L</"new"> method.
1365  
1366 =head2 error
1367  
1368 Return the last error set as a L<Module::Generic::Exception> object. Because the object can be stringified, you can do directly:
1369  
1370 die( $opt->error, "\n" ); # with a stack trace
1371  
1372 or
1373  
1374 die( sprintf( "Error occurred at line %d in file %s with message %s\n", $opt->error->line, $opt->error->file, $opt->error->message ) );
1375  
1376 =head2 exec
1377  
1378 This calls L<Getopt::Long/"getoptions"> with the L</"options"> hash reference and the L</"parameters"> array reference and after having called L</"configure"> to configure L<Getopt::Long> with the proper parameters according to the dictionary provided at the time of object instantiation.
1379  
1380 If there are any L<Getopt::Long> error, they can be retrieved with method L</"configure_errors">
1381  
1382 my $opt = Getopt::Class->new({ dictionary => $dict }) || die( Getopt::Class->error );
1383 my $opts = $opt->exec || die( $opt->error );
1384 if( $opt->configure_errors->length > 0 )
1385 {
1386 # do something about it
1387 }
1388  
1389 If any required options have been specified with the method L</"required">, it will check any missing option then and set an array of those missing options that can be retrieved with method L</"missing">
1390  
1391 This method makes sure that any option can be accessed with underscore or dash whichever, so a dictionary entry such as:
1392  
1393 my $dict =
1394 {
1395 create_customer => { type => 'boolean', alias => [qw(create_client create_user)], action => 1 },
1396 };
1397  
1398 can be called by your user like:
1399  
1400 ---create-customer
1401 # or
1402 --create-client
1403 # or
1404 --create-user
1405  
1406 because a duplicate entry with the underscore replaced by a dash is created (actually it's an alias of one to another). So you can say in your program:
1407  
1408 my $opts = $opt->exec || die( $opt->error );
1409 if( $opts->{create_user} )
1410 {
1411 # do something
1412 }
1413  
1414 L</"exec"> returns an hash reference whose properties can be accessed directly, but those properties can also be accessed as methods.
1415  
1416 This is made possible because the hash reference returned is a blessed object from L<Getopt::Class::Values> and provides an object oriented access to all the option values.
1417  
1418 A string is an object from L<Module::Generic::Scalar>
1419  
1420 $opts->customer_name->index( 'Doe' ) != -1
1421  
1422 A boolean is an object from L<Module::Generic::Boolean>
1423  
1424 An integer or decimal is an object from L<Text::Number>
1425  
1426 A date/dateime value is an object from L<DateTime>
1427  
1428 $opts->created->iso8601 # 2020-05-01T17:10:20
1429  
1430 An hash reference is an object created with L<Module::Generic/"_set_get_hash_as_object">
1431  
1432 $opts->metadata->transaction_id
1433  
1434 An array reference is an object created with L<Module::Generic/"_set_get_array_as_object">
1435  
1436 $opts->langs->push( 'en_GB' ) if( !$opts->langs->exists( 'en_GB' ) );
1437 $opts->langs->forEach(sub{
1438 $self->active_user_lang( shift( @_ ) );
1439 });
1440  
1441 Whatever the object type of the option value is based on the dictionary definitions you provide to L</"new">
1442  
1443 =head2 get_class_values
1444  
1445 Provided with a string representing a property class, and this returns an hash reference of all the key-value pairs provided by your user. So:
1446  
1447 my $dict =
1448 {
1449 create_customer => { type => 'boolean', alias => [qw(create_client create_user)], action => 1 },
1450 name => { type => 'string', class => [qw( person product )] },
1451 created => { type => 'datetime', class => [qw( person product )] },
1452 define => { type => 'string-hash', default => {} },
1453 langs => { type => 'array', class => [qw( person product )], re => qr/^[a-z]{2}([_|-][A-Z]{2})?/, min => 1, default => [] },
1454 currency => { type => 'string', class => [qw(product)], name => 'currency', re => qr/^[a-z]{3}$/, error => "must be a three-letter iso 4217 value" },
1455 age => { type => 'integer', class => [qw(person)], name => 'age', },
1456 };
1457  
1458 Then the user calls your program with:
1459  
1460 --create-user --name Bob --age 30 --langs en ja --created now
1461  
1462 # In your app
1463 my $opt = Getopt::Class->new({ dictionary => $dict }) || die( Getopt::Class->error );
1464 my $opts = $opt->exec || die( $opt->error );
1465 # $vals being an hash reference as a subset of all the values returned in $opts above
1466 my $vals = $opt->get_class_values( 'person' )
1467 # returns an hash only with keys name, age, langs and created
1468  
1469 =head2 getopt
1470  
1471 Sets or get the L<Getopt::Long::Parser> object. You can provide yours if you want but beware that certain options are necessary for L<Getopt::Class> to work. You can check those options with the method L</"configure_options">
1472  
1473 =head2 missing
1474  
1475 Returns an array of missing options. The array reference returned is a L<Module::Generic::Array> object, so you can do thins like
1476  
1477 if( $opt->missing->length > 0 )
1478 {
1479 # do something
1480 }
1481  
1482 =head2 options
1483  
1484 Returns an hash reference of options created by L</"new"> based on the dictionary you provide. This hash reference is used by L</"exec"> to call L<Getopt::Long/"getoptions">
1485  
1486 =head2 parameters
1487  
1488 Returns an array reference of parameters created by L</"new"> based on the dictionary you provide. This hash reference is used by L</"exec"> to call L<Getopt::Long/"getoptions">
1489  
1490 This array reference is a L<Module::Generic::Array> object
1491  
1492 =head2 required
1493  
1494 Set or get the array reference of required options. This returns a L<Module::Generic::Array> object.
1495  
1496 =head2 usage
1497  
1498 Set or get the anonymous subroutine or sub routine reference used to show the user the proper usage of your program.
1499  
1500 This is called by L</"exec"> after calling L<Getopt::Long/"getoptions"> if there is an error, i.e. if L<Getopt::Long/"getoptions"> does not return a true value.
1501  
1502 If you use object to call the sub routine usage, I recommend using the module L<curry>
1503  
1504 If this is not set, L</"exec"> will simply return undef or an empty list depending on the calling context.
1505  
1506 =head1 ERROR HANDLING
1507  
1508 This module never dies, or at least not by design. If an error occurs, each method returns undef and sets an error that can be retrieved with the method L</"error">
1509  
1510 =head1 AUTHOR
1511  
1512 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
1513  
1514 =head1 SEE ALSO
1515  
1516 L<Getopt::Long>
1517  
1518 =head1 COPYRIGHT & LICENSE
1519  
1520 Copyright (c) 2019-2020 DEGUEST Pte. Ltd.
1521  
1522 You can use, copy, modify and redistribute this package and associated
1523 files under the same terms as Perl itself.
1524  
1525 =cut
↑ Summary blib/lib/Getopt/Class.pm »