line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Maker::Option; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
48
|
use utf8; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
57
|
|
4
|
9
|
|
|
9
|
|
252
|
use warnings; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
216
|
|
5
|
9
|
|
|
9
|
|
43
|
use strict; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
307
|
|
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
51
|
use Carp; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
536
|
|
8
|
|
|
|
|
|
|
|
9
|
9
|
|
|
9
|
|
47
|
use Config::Maker; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
569
|
|
10
|
9
|
|
|
9
|
|
5819
|
use Config::Maker::Type; |
|
9
|
|
|
|
|
318
|
|
|
9
|
|
|
|
|
584
|
|
11
|
9
|
|
|
9
|
|
117
|
use Config::Maker::Path; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
1751
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use overload |
14
|
|
|
|
|
|
|
'cmp' => \&Config::Maker::truecmp, |
15
|
|
|
|
|
|
|
'<=>' => \&Config::Maker::truecmp, |
16
|
827
|
|
|
827
|
|
11584
|
'""' => sub { $_[0]->{-value}; }, |
17
|
|
|
|
|
|
|
'/' => sub { |
18
|
0
|
0
|
|
0
|
|
0
|
croak "Can't \"divide by\" option" if $_[2]; |
19
|
0
|
|
|
|
|
0
|
$_[0]->get($_[1]); |
20
|
|
|
|
|
|
|
}, |
21
|
|
|
|
|
|
|
'&{}' => sub { |
22
|
0
|
|
|
0
|
|
0
|
my $self = $_[0]; |
23
|
0
|
|
|
0
|
|
0
|
sub { $self->get(@_); }; |
|
0
|
|
|
|
|
0
|
|
24
|
|
|
|
|
|
|
}, |
25
|
9
|
|
|
9
|
|
54
|
fallback => 1; |
|
9
|
|
|
|
|
64
|
|
|
9
|
|
|
|
|
141
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _ref(\%$;$) { |
28
|
3036
|
|
|
3036
|
|
5123
|
my ($hash, $key, $default) = @_; |
29
|
3036
|
100
|
|
|
|
7692
|
if(exists $hash->{$key}) { |
|
|
50
|
|
|
|
|
|
30
|
2111
|
|
|
|
|
5049
|
my $rv = $hash->{$key}; |
31
|
2111
|
|
|
|
|
3987
|
delete $hash->{$key}; |
32
|
2111
|
|
|
|
|
8072
|
return $rv; |
33
|
|
|
|
|
|
|
} elsif(@_ == 3) { |
34
|
925
|
|
|
|
|
8472
|
return $default; |
35
|
|
|
|
|
|
|
} else { |
36
|
0
|
|
|
|
|
0
|
croak "Mandatory argument $key not specified"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _flatten { |
41
|
698
|
100
|
|
|
|
3425
|
map { |
42
|
1021
|
|
|
1021
|
|
3623
|
ref($_) eq 'ARRAY' ? |
43
|
|
|
|
|
|
|
_flatten(@$_) : |
44
|
|
|
|
|
|
|
$_; |
45
|
|
|
|
|
|
|
} @_; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
1012
|
|
|
1012
|
0
|
3344
|
my ($class, %args) = @_; |
50
|
1012
|
|
|
|
|
4198
|
my $type = _ref(%args, '-type'); |
51
|
|
|
|
|
|
|
|
52
|
1012
|
|
|
|
|
3659
|
my $self = { |
53
|
|
|
|
|
|
|
-type => $type, |
54
|
|
|
|
|
|
|
-value => _ref(%args, '-value', ''), |
55
|
|
|
|
|
|
|
-children => _ref(%args, '-children', []), |
56
|
|
|
|
|
|
|
}; |
57
|
1012
|
50
|
|
|
|
3279
|
croak "Unknown arguments: " . join(', ', keys %args) |
58
|
|
|
|
|
|
|
if %args; |
59
|
1012
|
|
|
|
|
3823
|
bless $self, $class; |
60
|
|
|
|
|
|
|
|
61
|
1012
|
|
|
|
|
1858
|
$self->{-children} = [_flatten(@{$self->{-children}})]; |
|
1012
|
|
|
|
|
5992
|
|
62
|
|
|
|
|
|
|
|
63
|
1012
|
|
|
|
|
1641
|
foreach my $child (@{$self->{-children}}) { |
|
1012
|
|
|
|
|
3296
|
|
64
|
689
|
|
|
|
|
2576
|
$child->{-parent} = $self; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
1012
|
|
|
|
|
1482
|
foreach my $check (@{$type->{checks}}) { |
|
1012
|
|
|
|
|
11589
|
|
68
|
1601
|
|
|
|
|
23938
|
&$check($self); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
1012
|
|
|
|
|
1812
|
foreach my $action (@{$type->{actions}}) { |
|
1012
|
|
|
|
|
2933
|
|
72
|
30
|
|
|
|
|
178
|
&$action($self); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
1012
|
|
|
|
|
4369
|
DBG("Instantiated $type"); |
76
|
1012
|
|
|
|
|
5253
|
$self; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub get { |
80
|
591
|
|
|
591
|
1
|
1325
|
my ($self, $path) = @_; |
81
|
591
|
|
|
|
|
3311
|
$path = Config::Maker::Path->make($path); |
82
|
591
|
|
|
|
|
16227
|
my $res = $path->find($self); |
83
|
591
|
100
|
|
|
|
5718
|
return wantarray ? @$res : $res->[0]; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get1 { |
87
|
192
|
|
|
192
|
1
|
370
|
my ($self, $path) = @_; |
88
|
192
|
|
|
|
|
755
|
$path = Config::Maker::Path->make($path); |
89
|
192
|
|
|
|
|
747
|
my $res = $path->find($self); |
90
|
192
|
50
|
|
|
|
559
|
Carp::croak "$path should have exactly one result" if $#$res; |
91
|
192
|
|
|
|
|
1099
|
return $res->[0]; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub getval { |
95
|
135
|
|
|
135
|
1
|
311
|
my ($self, $path, $default) = @_; |
96
|
135
|
|
|
|
|
1596
|
$path = Config::Maker::Path->make($path); |
97
|
135
|
|
|
|
|
514
|
my $res = $path->find($self); |
98
|
135
|
50
|
|
|
|
425
|
Carp::croak "$path should have at most one result" if @$res > 1; |
99
|
135
|
100
|
|
|
|
2893
|
@$res ? $res->[0]->{-value} : $default; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub type { |
103
|
0
|
|
|
0
|
0
|
|
$_[0]->{-type}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub id { |
107
|
0
|
|
|
0
|
0
|
|
"$_[0]->{-type}:$_[0]->{-value}"; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |