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
|
|
311098
|
use strict; |
|
2
|
|
|
|
|
28
|
|
|
2
|
|
|
|
|
58
|
|
10
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
51
|
|
11
|
2
|
|
|
2
|
|
9
|
use English; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
21
|
|
12
|
2
|
|
|
2
|
|
2067
|
use Config::Std; |
|
2
|
|
|
|
|
39582
|
|
|
2
|
|
|
|
|
11
|
|
13
|
2
|
|
|
2
|
|
1503
|
use Data::Dumper; |
|
2
|
|
|
|
|
14551
|
|
|
2
|
|
|
|
|
159
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
1123
|
use Moose; |
|
2
|
|
|
|
|
958031
|
|
|
2
|
|
|
|
|
14
|
|
16
|
|
|
|
|
|
|
extends 'Connector::Proxy'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _build_config { |
19
|
2
|
|
|
2
|
|
8
|
my $self = shift; |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
4
|
my $config; |
22
|
2
|
|
|
|
|
63
|
read_config($self->LOCATION(), $config); |
23
|
2
|
|
|
|
|
5421
|
$self->_config($config); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub get { |
28
|
22
|
|
|
22
|
1
|
48
|
my $self = shift; |
29
|
22
|
|
|
|
|
61
|
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
|
|
|
|
|
53
|
my $key = pop @path; |
35
|
22
|
|
|
|
|
52
|
my $section = $self->_build_section_name_from_path( @path); |
36
|
|
|
|
|
|
|
|
37
|
22
|
|
|
|
|
494
|
return $self->_config()->{$section}->{$key}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _get_node { |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
3
|
|
5
|
my $self = shift; |
43
|
3
|
|
|
|
|
9
|
my @path = $self->_build_path_with_prefix( shift ); |
44
|
3
|
|
|
|
|
10
|
my $fullpath = $self->_build_section_name_from_path( @path); |
45
|
3
|
|
|
|
|
68
|
return $self->_config()->{$fullpath}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub get_size { |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
1
|
1
|
20
|
my $self = shift; |
52
|
1
|
|
|
|
|
4
|
my $node = $self->get( shift ); |
53
|
|
|
|
|
|
|
|
54
|
1
|
50
|
|
|
|
6
|
if (!defined $node) { |
55
|
0
|
|
|
|
|
0
|
return 0; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
1
|
50
|
|
|
|
10
|
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
|
|
|
|
|
7
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get_list { |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
69
|
1
|
|
|
|
|
3
|
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
|
|
|
|
|
4
|
my $node = $self->get( $path ); |
75
|
|
|
|
|
|
|
|
76
|
1
|
50
|
|
|
|
12
|
if (!defined $node) { |
77
|
0
|
|
|
|
|
0
|
return $self->_node_not_exists( $path ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
1
|
50
|
|
|
|
10
|
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
|
|
|
|
|
6
|
my $node = $self->_get_node( shift ); |
91
|
|
|
|
|
|
|
|
92
|
1
|
50
|
|
|
|
6
|
if (!defined $node) { |
93
|
0
|
|
|
|
|
0
|
return @{[]}; |
|
0
|
|
|
|
|
0
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
1
|
50
|
|
|
|
4
|
if (ref $node ne "HASH") { |
97
|
0
|
|
|
|
|
0
|
die "requested path looks not like a hash"; |
98
|
|
|
|
|
|
|
} |
99
|
1
|
|
|
|
|
2
|
return keys (%{$node}); |
|
1
|
|
|
|
|
5
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub get_hash { |
103
|
|
|
|
|
|
|
|
104
|
2
|
|
|
2
|
1
|
788
|
my $self = shift; |
105
|
2
|
|
|
|
|
5
|
my $path = shift; |
106
|
|
|
|
|
|
|
|
107
|
2
|
|
|
|
|
6
|
my $node = $self->_get_node( $path ); |
108
|
|
|
|
|
|
|
|
109
|
2
|
50
|
|
|
|
17
|
if (!defined $node) { |
110
|
0
|
|
|
|
|
0
|
return $self->_node_not_exists($path); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
2
|
50
|
|
|
|
9
|
if (ref $node ne "HASH") { |
114
|
0
|
|
|
|
|
0
|
die "requested path looks not like a hash"; |
115
|
|
|
|
|
|
|
} |
116
|
2
|
|
|
|
|
17
|
return $node; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub get_meta { |
121
|
|
|
|
|
|
|
|
122
|
20
|
|
|
20
|
1
|
36
|
my $self = shift; |
123
|
20
|
|
|
|
|
35
|
my $origin = shift; |
124
|
|
|
|
|
|
|
|
125
|
20
|
|
|
|
|
57
|
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
|
|
|
|
|
55
|
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
|
|
|
|
69
|
if (!$section) { |
134
|
1
|
|
|
|
|
7
|
return { 'TYPE' => 'connector'}; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# This is either a hash or undef |
138
|
19
|
|
|
|
|
418
|
my $node = $self->_config()->{$section}; |
139
|
19
|
|
|
|
|
30
|
my $meta; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Array and scalar exist one level above |
142
|
19
|
100
|
|
|
|
71
|
if (!defined $node) { |
|
|
50
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
14
|
|
|
|
|
30
|
my $key = pop @path; |
145
|
14
|
|
|
|
|
31
|
$section = $self->_build_section_name_from_path( @path ); |
146
|
14
|
|
|
|
|
303
|
$node = $self->_config()->{$section}->{$key}; |
147
|
|
|
|
|
|
|
|
148
|
14
|
100
|
|
|
|
38
|
if (!defined $node) { |
149
|
6
|
|
|
|
|
43
|
return $self->_node_not_exists( \@path ); |
150
|
|
|
|
|
|
|
} |
151
|
8
|
100
|
|
|
|
27
|
if (ref $node eq '') { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
152
|
7
|
|
|
|
|
54
|
$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
|
|
|
|
|
4
|
$meta = {TYPE => "list", VALUE => $node }; |
158
|
|
|
|
|
|
|
} else { |
159
|
0
|
|
|
|
|
0
|
die "Unsupported node type"; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} elsif (ref $node eq "HASH") { |
162
|
5
|
|
|
|
|
17
|
$meta = {TYPE => "hash" }; |
163
|
|
|
|
|
|
|
} else { |
164
|
0
|
|
|
|
|
0
|
die "Unsupported node type"; |
165
|
|
|
|
|
|
|
} |
166
|
13
|
|
|
|
|
54
|
return $meta; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub exists { |
170
|
|
|
|
|
|
|
|
171
|
4
|
|
|
4
|
1
|
11
|
my $self = shift; |
172
|
|
|
|
|
|
|
|
173
|
4
|
|
|
|
|
15
|
my @path = $self->_build_path_with_prefix( shift ); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# No path always exists |
176
|
4
|
50
|
|
|
|
13
|
if (!@path) { |
177
|
0
|
|
|
|
|
0
|
return 1; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# Test if it is a section |
181
|
4
|
|
|
|
|
10
|
my $section = $self->_build_section_name_from_path( @path ); |
182
|
4
|
100
|
|
|
|
89
|
if ($self->_config()->{$section}) { |
183
|
1
|
|
|
|
|
5
|
return 1; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# Test if it is a node |
187
|
3
|
|
|
|
|
6
|
my $key = pop @path; |
188
|
3
|
|
|
|
|
8
|
$section = $self->_build_section_name_from_path( @path ); |
189
|
3
|
100
|
|
|
|
65
|
if (defined $self->_config()->{$section}->{$key}) { |
190
|
2
|
|
|
|
|
10
|
return 1; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
1
|
|
|
|
|
5
|
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
|
|
99
|
my $self = shift; |
201
|
66
|
|
|
|
|
1637
|
return join( $self->DELIMITER() , @_ ); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
2
|
|
|
2
|
|
17368
|
no Moose; |
|
2
|
|
|
|
|
5
|
|
|
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 |