line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::Choose::ValidateOptions; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
39
|
use warnings; |
|
3
|
|
|
|
|
28
|
|
|
3
|
|
|
|
|
371
|
|
4
|
3
|
|
|
3
|
|
44
|
use strict; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
168
|
|
5
|
3
|
|
|
3
|
|
91
|
use 5.10.0; |
|
3
|
|
|
|
|
33
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.762'; |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
36
|
use Exporter qw( import ); |
|
3
|
|
|
|
|
18
|
|
|
3
|
|
|
|
|
363
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw( validate_options ); |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
57
|
use Carp qw( croak ); |
|
3
|
|
|
|
|
23
|
|
|
3
|
|
|
|
|
2342
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub validate_options { |
17
|
113
|
|
|
113
|
0
|
246
|
my ( $valid, $opt, $caller ) = @_; |
18
|
113
|
50
|
|
|
|
240
|
return if ! defined $opt; # |
19
|
113
|
50
|
|
|
|
205
|
if ( ! defined $caller ) { # |
20
|
0
|
|
|
|
|
0
|
$caller = ''; |
21
|
|
|
|
|
|
|
}; |
22
|
113
|
|
|
|
|
358
|
for my $key ( keys %$opt ) { |
23
|
152
|
50
|
|
|
|
321
|
if ( ! exists $valid->{$key} ) { |
24
|
0
|
|
|
|
|
0
|
croak "$caller: '$key' is not a valid option name"; |
25
|
|
|
|
|
|
|
} |
26
|
152
|
100
|
|
|
|
353
|
next if ! defined $opt->{$key}; |
27
|
115
|
100
|
|
|
|
1265
|
if ( $valid->{$key} =~ /^Array/ ) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
28
|
16
|
50
|
|
|
|
45
|
croak "$caller: option '$key' => the passed value has to be an ARRAY reference." if ref $opt->{$key} ne 'ARRAY'; |
29
|
16
|
50
|
|
|
|
35
|
if ( $valid->{$key} eq 'Array_Int' ) { |
30
|
16
|
|
|
|
|
34
|
for ( @{$opt->{$key}} ) { |
|
16
|
|
|
|
|
45
|
|
31
|
28
|
50
|
|
|
|
52
|
defined or croak "$caller: option '$key' => undefined array element"; |
32
|
28
|
50
|
|
|
|
123
|
/^[0-9]+\z/ or croak "$caller: option '$key' => $_ is an invalid array element"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
elsif ( $valid->{$key} =~ /^Regexp/ ) { |
37
|
0
|
0
|
|
|
|
|
croak "$caller: option '$key' => the passed value has to be a regex quoted with the 'qr' operator." if ref $opt->{$key} ne 'Regexp'; |
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
|
|
|
|
|
|
|
1; |