| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Connector::Proxy::Config::Std |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Proxy class for reading Config::Std configuration |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# Written by Scott Hardin and Martin Bartosch for the OpenXPKI project 2012 |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
package Connector::Proxy::Config::Std; |
|
8
|
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
285372
|
use strict; |
|
|
2
|
|
|
|
|
30
|
|
|
|
2
|
|
|
|
|
56
|
|
|
10
|
2
|
|
|
2
|
|
18
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
50
|
|
|
11
|
2
|
|
|
2
|
|
10
|
use English; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
17
|
|
|
12
|
2
|
|
|
2
|
|
1960
|
use Config::Std; |
|
|
2
|
|
|
|
|
37017
|
|
|
|
2
|
|
|
|
|
14
|
|
|
13
|
2
|
|
|
2
|
|
1626
|
use Data::Dumper; |
|
|
2
|
|
|
|
|
12981
|
|
|
|
2
|
|
|
|
|
176
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
982
|
use Moose; |
|
|
2
|
|
|
|
|
901225
|
|
|
|
2
|
|
|
|
|
16
|
|
|
16
|
|
|
|
|
|
|
extends 'Connector::Proxy'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _build_config { |
|
19
|
2
|
|
|
2
|
|
8
|
my $self = shift; |
|
20
|
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
4
|
my $config; |
|
22
|
2
|
|
|
|
|
46
|
read_config($self->LOCATION(), $config); |
|
23
|
2
|
|
|
|
|
6289
|
$self->_config($config); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub get { |
|
28
|
22
|
|
|
22
|
1
|
40
|
my $self = shift; |
|
29
|
22
|
|
|
|
|
75
|
my @path = $self->_build_path_with_prefix( shift ); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Config::Std does not allow nested data structures, emulate that |
|
32
|
|
|
|
|
|
|
# by separating last element from path and using that as key |
|
33
|
|
|
|
|
|
|
# in the section defined by the remaining prefix |
|
34
|
22
|
|
|
|
|
44
|
my $key = pop @path; |
|
35
|
22
|
|
|
|
|
57
|
my $section = $self->_build_section_name_from_path( @path); |
|
36
|
|
|
|
|
|
|
|
|
37
|
22
|
|
|
|
|
400
|
return $self->_config()->{$section}->{$key}; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _get_node { |
|
41
|
|
|
|
|
|
|
|
|
42
|
3
|
|
|
3
|
|
5
|
my $self = shift; |
|
43
|
3
|
|
|
|
|
12
|
my @path = $self->_build_path_with_prefix( shift ); |
|
44
|
3
|
|
|
|
|
12
|
my $fullpath = $self->_build_section_name_from_path( @path); |
|
45
|
3
|
|
|
|
|
57
|
return $self->_config()->{$fullpath}; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub get_size { |
|
50
|
|
|
|
|
|
|
|
|
51
|
1
|
|
|
1
|
1
|
9
|
my $self = shift; |
|
52
|
1
|
|
|
|
|
5
|
my $node = $self->get( shift ); |
|
53
|
|
|
|
|
|
|
|
|
54
|
1
|
50
|
|
|
|
4
|
if (!defined $node) { |
|
55
|
0
|
|
|
|
|
0
|
return 0; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
1
|
50
|
|
|
|
13
|
if (ref $node ne "ARRAY") { |
|
59
|
0
|
|
|
|
|
0
|
die "requested path looks not like a list"; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
2
|
return scalar @{$node}; |
|
|
1
|
|
|
|
|
6
|
|
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get_list { |
|
67
|
|
|
|
|
|
|
|
|
68
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
|
69
|
1
|
|
|
|
|
2
|
my $path = shift; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# List is similar to scalar, the last path item is a hash key |
|
72
|
|
|
|
|
|
|
# in the section of the remaining prefix |
|
73
|
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
7
|
my $node = $self->get( $path ); |
|
75
|
|
|
|
|
|
|
|
|
76
|
1
|
50
|
|
|
|
5
|
if (!defined $node) { |
|
77
|
0
|
|
|
|
|
0
|
return $self->_node_not_exists( $path ); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
1
|
50
|
|
|
|
5
|
if (ref $node ne "ARRAY") { |
|
81
|
0
|
|
|
|
|
0
|
die "requested path looks not like a hash"; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
1
|
|
|
|
|
2
|
return @{$node}; |
|
|
1
|
|
|
|
|
6
|
|
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub get_keys { |
|
88
|
|
|
|
|
|
|
|
|
89
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
|
90
|
1
|
|
|
|
|
7
|
my $node = $self->_get_node( shift ); |
|
91
|
|
|
|
|
|
|
|
|
92
|
1
|
50
|
|
|
|
5
|
if (!defined $node) { |
|
93
|
0
|
|
|
|
|
0
|
return @{[]}; |
|
|
0
|
|
|
|
|
0
|
|
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
1
|
50
|
|
|
|
5
|
if (ref $node ne "HASH") { |
|
97
|
0
|
|
|
|
|
0
|
die "requested path looks not like a hash"; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
1
|
|
|
|
|
3
|
return keys (%{$node}); |
|
|
1
|
|
|
|
|
6
|
|
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub get_hash { |
|
103
|
|
|
|
|
|
|
|
|
104
|
2
|
|
|
2
|
1
|
598
|
my $self = shift; |
|
105
|
2
|
|
|
|
|
6
|
my $path = shift; |
|
106
|
|
|
|
|
|
|
|
|
107
|
2
|
|
|
|
|
6
|
my $node = $self->_get_node( $path ); |
|
108
|
|
|
|
|
|
|
|
|
109
|
2
|
50
|
|
|
|
8
|
if (!defined $node) { |
|
110
|
0
|
|
|
|
|
0
|
return $self->_node_not_exists($path); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
2
|
50
|
|
|
|
6
|
if (ref $node ne "HASH") { |
|
114
|
0
|
|
|
|
|
0
|
die "requested path looks not like a hash"; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
2
|
|
|
|
|
12
|
return $node; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub get_meta { |
|
121
|
|
|
|
|
|
|
|
|
122
|
20
|
|
|
20
|
1
|
30
|
my $self = shift; |
|
123
|
20
|
|
|
|
|
30
|
my $origin = shift; |
|
124
|
|
|
|
|
|
|
|
|
125
|
20
|
|
|
|
|
48
|
my @path = $self->_build_path_with_prefix( $origin ); |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# We dont have a real tree, so we look if there is a config entry |
|
128
|
|
|
|
|
|
|
# that has the full path as key |
|
129
|
|
|
|
|
|
|
|
|
130
|
20
|
|
|
|
|
52
|
my $section = $self->_build_section_name_from_path( @path ); |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# As top node iteration is not supported we report a connector |
|
133
|
20
|
100
|
|
|
|
44
|
if (!$section) { |
|
134
|
1
|
|
|
|
|
16
|
return { 'TYPE' => 'connector'}; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# This is either a hash or undef |
|
138
|
19
|
|
|
|
|
352
|
my $node = $self->_config()->{$section}; |
|
139
|
19
|
|
|
|
|
24
|
my $meta; |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Array and scalar exist one level above |
|
142
|
19
|
100
|
|
|
|
46
|
if (!defined $node) { |
|
|
|
50
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
|
144
|
14
|
|
|
|
|
25
|
my $key = pop @path; |
|
145
|
14
|
|
|
|
|
27
|
$section = $self->_build_section_name_from_path( @path ); |
|
146
|
14
|
|
|
|
|
239
|
$node = $self->_config()->{$section}->{$key}; |
|
147
|
|
|
|
|
|
|
|
|
148
|
14
|
100
|
|
|
|
34
|
if (!defined $node) { |
|
149
|
6
|
|
|
|
|
31
|
return $self->_node_not_exists( \@path ); |
|
150
|
|
|
|
|
|
|
} |
|
151
|
8
|
100
|
|
|
|
24
|
if (ref $node eq '') { |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
152
|
7
|
|
|
|
|
21
|
$meta = {TYPE => "scalar", VALUE => $node }; |
|
153
|
|
|
|
|
|
|
} elsif (ref $node eq "SCALAR") { |
|
154
|
|
|
|
|
|
|
# I guess thats not supported |
|
155
|
0
|
|
|
|
|
0
|
$meta = {TYPE => "reference", VALUE => $$node }; |
|
156
|
|
|
|
|
|
|
} elsif (ref $node eq "ARRAY") { |
|
157
|
1
|
|
|
|
|
5
|
$meta = {TYPE => "list", VALUE => $node }; |
|
158
|
|
|
|
|
|
|
} else { |
|
159
|
0
|
|
|
|
|
0
|
die "Unsupported node type"; |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
} elsif (ref $node eq "HASH") { |
|
162
|
5
|
|
|
|
|
20
|
$meta = {TYPE => "hash" }; |
|
163
|
|
|
|
|
|
|
} else { |
|
164
|
0
|
|
|
|
|
0
|
die "Unsupported node type"; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
13
|
|
|
|
|
51
|
return $meta; |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub exists { |
|
170
|
|
|
|
|
|
|
|
|
171
|
4
|
|
|
4
|
1
|
10
|
my $self = shift; |
|
172
|
|
|
|
|
|
|
|
|
173
|
4
|
|
|
|
|
13
|
my @path = $self->_build_path_with_prefix( shift ); |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# No path always exists |
|
176
|
4
|
50
|
|
|
|
11
|
if (!@path) { |
|
177
|
0
|
|
|
|
|
0
|
return 1; |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# Test if it is a section |
|
181
|
4
|
|
|
|
|
11
|
my $section = $self->_build_section_name_from_path( @path ); |
|
182
|
4
|
100
|
|
|
|
74
|
if ($self->_config()->{$section}) { |
|
183
|
1
|
|
|
|
|
7
|
return 1; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# Test if it is a node |
|
187
|
3
|
|
|
|
|
6
|
my $key = pop @path; |
|
188
|
3
|
|
|
|
|
9
|
$section = $self->_build_section_name_from_path( @path ); |
|
189
|
3
|
100
|
|
|
|
54
|
if (defined $self->_config()->{$section}->{$key}) { |
|
190
|
2
|
|
|
|
|
11
|
return 1; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
1
|
|
|
|
|
4
|
return 0; |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# might be refined to use a section delimiter different from connector |
|
198
|
|
|
|
|
|
|
sub _build_section_name_from_path { |
|
199
|
|
|
|
|
|
|
|
|
200
|
66
|
|
|
66
|
|
95
|
my $self = shift; |
|
201
|
66
|
|
|
|
|
1354
|
return join( $self->DELIMITER() , @_ ); |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
|
|
204
|
2
|
|
|
2
|
|
16163
|
no Moose; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
13
|
|
|
205
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
1; |
|
208
|
|
|
|
|
|
|
__END__ |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 Name |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Connector::Proxy::Config::Std |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 Description |