| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
3
|
|
|
3
|
|
608749
|
#line 1 |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
105
|
|
|
2
|
3
|
|
|
3
|
|
17
|
use strict; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
154
|
|
|
3
|
|
|
|
|
|
|
use warnings; |
|
4
|
|
|
|
|
|
|
package Data::OptList; |
|
5
|
3
|
|
|
3
|
|
76
|
BEGIN { |
|
6
|
|
|
|
|
|
|
$Data::OptList::VERSION = '0.107'; |
|
7
|
|
|
|
|
|
|
} |
|
8
|
|
|
|
|
|
|
# ABSTRACT: parse and validate simple name/value option pairs |
|
9
|
3
|
|
|
3
|
|
18
|
|
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
52
|
|
|
10
|
3
|
|
|
3
|
|
3217
|
use List::Util (); |
|
|
3
|
|
|
|
|
10533
|
|
|
|
3
|
|
|
|
|
86
|
|
|
11
|
3
|
|
|
3
|
|
2136
|
use Params::Util (); |
|
|
3
|
|
|
|
|
99
|
|
|
|
3
|
|
|
|
|
182
|
|
|
12
|
|
|
|
|
|
|
use Sub::Install 0.921 (); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %test_for; |
|
16
|
3
|
|
|
3
|
|
2311
|
BEGIN { |
|
17
|
|
|
|
|
|
|
%test_for = ( |
|
18
|
|
|
|
|
|
|
CODE => \&Params::Util::_CODELIKE, ## no critic |
|
19
|
|
|
|
|
|
|
HASH => \&Params::Util::_HASHLIKE, ## no critic |
|
20
|
|
|
|
|
|
|
ARRAY => \&Params::Util::_ARRAYLIKE, ## no critic |
|
21
|
|
|
|
|
|
|
SCALAR => \&Params::Util::_SCALAR0, ## no critic |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
|
0
|
|
|
sub __is_a { |
|
26
|
|
|
|
|
|
|
my ($got, $expected) = @_; |
|
27
|
0
|
0
|
|
0
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return List::Util::first { __is_a($got, $_) } @$expected if ref $expected; |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
return defined ( |
|
31
|
|
|
|
|
|
|
exists($test_for{$expected}) |
|
32
|
|
|
|
|
|
|
? $test_for{$expected}->($got) |
|
33
|
|
|
|
|
|
|
: Params::Util::_INSTANCE($got, $expected) ## no critic |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
0
|
1
|
|
sub mkopt { |
|
38
|
|
|
|
|
|
|
my ($opt_list) = shift; |
|
39
|
0
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my ($moniker, $require_unique, $must_be); # the old positional args |
|
41
|
|
|
|
|
|
|
my $name_test; |
|
42
|
0
|
0
|
0
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
if (@_ == 1 and Params::Util::_HASHLIKE($_[0])) { |
|
44
|
0
|
|
|
|
|
|
my $arg = $_[0]; |
|
45
|
|
|
|
|
|
|
($moniker, $require_unique, $must_be, $name_test) |
|
46
|
|
|
|
|
|
|
= @$arg{ qw(moniker require_unique must_be name_test) }; |
|
47
|
0
|
|
|
|
|
|
} else { |
|
48
|
|
|
|
|
|
|
($moniker, $require_unique, $must_be) = @_; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
0
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$moniker = 'unnamed' unless defined $moniker; |
|
52
|
0
|
0
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return [] unless $opt_list; |
|
54
|
0
|
|
0
|
0
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$name_test ||= sub { ! ref $_[0] }; |
|
56
|
0
|
0
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
$opt_list = [ |
|
58
|
|
|
|
|
|
|
map { $_ => (ref $opt_list->{$_} ? $opt_list->{$_} : ()) } keys %$opt_list |
|
59
|
|
|
|
|
|
|
] if ref $opt_list eq 'HASH'; |
|
60
|
0
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my @return; |
|
62
|
|
|
|
|
|
|
my %seen; |
|
63
|
0
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
for (my $i = 0; $i < @$opt_list; $i++) { ## no critic |
|
65
|
0
|
|
|
|
|
|
my $name = $opt_list->[$i]; |
|
66
|
|
|
|
|
|
|
my $value; |
|
67
|
0
|
0
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
if ($require_unique) { |
|
69
|
|
|
|
|
|
|
Carp::croak "multiple definitions provided for $name" if $seen{$name}++; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
0
|
0
|
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
if ($i == $#$opt_list) { $value = undef; } |
|
|
0
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
elsif (not defined $opt_list->[$i+1]) { $value = undef; $i++ } |
|
74
|
0
|
|
|
|
|
|
elsif ($name_test->($opt_list->[$i+1])) { $value = undef; } |
|
75
|
|
|
|
|
|
|
else { $value = $opt_list->[++$i] } |
|
76
|
0
|
0
|
0
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
if ($must_be and defined $value) { |
|
78
|
0
|
|
|
|
|
|
unless (__is_a($value, $must_be)) { |
|
79
|
0
|
|
|
|
|
|
my $ref = ref $value; |
|
80
|
|
|
|
|
|
|
Carp::croak "$ref-ref values are not valid in $moniker opt list"; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
0
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
push @return, [ $name => $value ]; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
0
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return \@return; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
|
|
0
|
1
|
|
sub mkopt_hash { |
|
92
|
0
|
0
|
|
|
|
|
my ($opt_list, $moniker, $must_be) = @_; |
|
93
|
|
|
|
|
|
|
return {} unless $opt_list; |
|
94
|
0
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
$opt_list = mkopt($opt_list, $moniker, 1, $must_be); |
|
|
0
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my %hash = map { $_->[0] => $_->[1] } @$opt_list; |
|
97
|
|
|
|
|
|
|
return \%hash; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
101
|
3
|
|
|
3
|
|
23
|
BEGIN { |
|
102
|
|
|
|
|
|
|
*import = Sub::Install::exporter { |
|
103
|
|
|
|
|
|
|
exports => [qw(mkopt mkopt_hash)], |
|
104
|
|
|
|
|
|
|
}; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |