Choose/ValidateOptions.pm

filter: Statementstmt 85.7% 30 / 35 Branchbran 57.1% 16 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 74.2% 52 / 70 CC 17 SCAR 32.0
CC
17
Cov
73%
validate_options
31.6
BEGIN
1.0
BEGIN
1.0
CRAP 24.6
« Choose/Opt/Search.pm ↑ Summary Choose/LineFold/PP.pm »
1 package Term::Choose::ValidateOptions;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use 5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '1.780';
8  
9 3 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 our @EXPORT_OK = qw( validate_options );
12  
13 3 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 sub validate_options {
17 113 ▶ my ( $valid, $opt, $caller ) = @_;
Subroutine validate_options: called CC=17 SCAR=34.5
Pod undocumented
18 113 ▶ return if ! defined $opt; #
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt 0 113 113
19 113 ▶ if ( ! defined $caller ) { #
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $caller) 0 113 113
20 0 $caller = '';
21 };
22 113 for my $key ( keys %$opt ) {
23 152 ▶ if ( ! exists $valid->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $valid->{$key}) 0 152 152
24 0 croak "$caller: '$key' is not a valid option name";
25 }
26 152 ▶ next if ! defined $opt->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt->{$key} 37 115 152
27 115 ▶ if ( $valid->{$key} =~ /^Array/ ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($valid->{$key} =~ /^Array/) { } 16 99 115
elsif ($valid->{$key} =~ /^Regexp/) { } 0 99 99
elsif (ref $opt->{$key}) { } 0 99 99
elsif ($valid->{$key} eq 'Str') { } 24 75 99
elsif (not $opt->{$key} =~ /^$valid->{$key}\z/x) { } 0 75 75
28 16 ▶ croak "$caller: option '$key' => the passed value has to be an ARRAY reference." if ref $opt->{$key} ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $opt->{$key} ne "ARRAY" 0 16 16
29 16 ▶ if ( $valid->{$key} eq 'Array_Int' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($valid->{$key} eq "Array_Int") 16 0 16
30 16 for ( @{$opt->{$key}} ) {
31 28 ▶ defined or croak "$caller: option '$key' => undefined array element";
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or croak("${caller}: option '${key}' => undefined array element") 0 28 28
32 28 ▶ /^[0-9]+\z/ or croak "$caller: option '$key' => $_ is an invalid array element";
Branch: 1 branch
BranchTrueFalseTotal
/^[0-9]+\z/ or croak("${caller}: option '${key}' => $_ is an invalid array element") 0 28 28
33 }
34 }
35 }
36 elsif ( $valid->{$key} =~ /^Regexp/ ) {
37 0 ▶ croak "$caller: option '$key' => the passed value has to be a regex quoted with the 'qr' operator." if ref $opt->{$key} ne 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
if ref $opt->{$key} ne "Regexp" 0 0 0
38 }
39 elsif ( ref $opt->{$key} ) {
40 0 croak "$caller: option '$key' => a reference is not a valid value.";
41 }
42 elsif ( $valid->{$key} eq 'Str' ) {
43 }
44 elsif ( $opt->{$key} !~ m/^$valid->{$key}\z/x ) {
45 0 croak "$caller: option '$key' => '$opt->{$key}' is not a valid value.";
46 }
47 }
48 }
49  
50  
51  
52  
53  
54  
55 3 1;
« Choose/Opt/Search.pm ↑ Summary Choose/LineFold/PP.pm »