| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Config::Hierarchical::Tie::ReadOnly ; |
|
3
|
|
|
|
|
|
|
|
|
4
|
9
|
|
|
9
|
|
52
|
use strict; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
330
|
|
|
5
|
9
|
|
|
9
|
|
52
|
use warnings ; |
|
|
9
|
|
|
|
|
21
|
|
|
|
9
|
|
|
|
|
441
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN |
|
8
|
|
|
|
|
|
|
{ |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
9
|
|
|
9
|
|
53
|
use vars qw ($VERSION @ISA @EXPORT_OK %EXPORT_TAGS); |
|
|
9
|
|
|
|
|
23
|
|
|
|
9
|
|
|
|
|
850
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
9
|
|
|
9
|
|
22
|
$VERSION = '0.01' ; |
|
14
|
9
|
|
|
|
|
19
|
@EXPORT_OK = qw (); |
|
15
|
9
|
|
|
|
|
265
|
%EXPORT_TAGS = (); |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
9
|
|
|
9
|
|
48
|
use Carp ; |
|
|
9
|
|
|
|
|
25
|
|
|
|
9
|
|
|
|
|
580
|
|
|
21
|
9
|
|
|
9
|
|
47
|
use base qw(Tie::Hash) ; |
|
|
9
|
|
|
|
|
15
|
|
|
|
9
|
|
|
|
|
8929
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
9
|
|
|
9
|
|
9211
|
use English qw( -no_match_vars ) ; |
|
|
9
|
|
|
|
|
23
|
|
|
|
9
|
|
|
|
|
71
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
9
|
|
|
9
|
|
4633
|
use Readonly ; |
|
|
9
|
|
|
|
|
16
|
|
|
|
9
|
|
|
|
|
5845
|
|
|
26
|
|
|
|
|
|
|
Readonly my $EMPTY_STRING => q{} ; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 NAME |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Config::Hierarchical::Tie::ReadOnly - Access Hierarchical configuration container through a read only hash |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $config = new Config::Hierarchical |
|
36
|
|
|
|
|
|
|
( |
|
37
|
|
|
|
|
|
|
NAME => 'config', |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
CATEGORY_NAMES => ['A', 'B'], |
|
40
|
|
|
|
|
|
|
DEFAULT_CATEGORY => 'B', |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
INITIAL_VALUES => |
|
43
|
|
|
|
|
|
|
[ |
|
44
|
|
|
|
|
|
|
{CATEGORY => 'A', NAME => 'CC1', VALUE => '1'}, |
|
45
|
|
|
|
|
|
|
{CATEGORY => 'B', NAME => 'CC2', VALUE => '2'}, |
|
46
|
|
|
|
|
|
|
{CATEGORY => 'A', NAME => 'CC3', VALUE => '3'}, |
|
47
|
|
|
|
|
|
|
{CATEGORY => 'B', NAME => 'CC4', VALUE => '4'}, |
|
48
|
|
|
|
|
|
|
{CATEGORY => 'A', NAME => 'CC5', VALUE => '5'}, |
|
49
|
|
|
|
|
|
|
] , |
|
50
|
|
|
|
|
|
|
) ; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my %hash ; |
|
53
|
|
|
|
|
|
|
tie %hash, 'Config::Hierarchical::Tie::ReadOnly' => $config ; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my @keys = sort keys %hash ; # qw( CC1 CC2 CC3 CC4 CC5) |
|
56
|
|
|
|
|
|
|
print $hash{CC1} ; # print '1' |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$hash{CC1} = 2 ; # dies, hash is read only |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Creates a read only wrapper around a B<Config::Hierarchical> object. This let's you access the config |
|
63
|
|
|
|
|
|
|
object as a hash. You can use B<{}> access which makes it easy to use the config in interpolated string. |
|
64
|
|
|
|
|
|
|
You can also use B<keys> and B<each> on the tied config. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
but you can't modify the variables, clear the config or delete any variable. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
This is also class is also used to allow you to link a category to an existing Config::Hierarchical object. See |
|
69
|
|
|
|
|
|
|
L<new> in <Config::Hierarchical>. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 DOCUMENTATION |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub TIEHASH |
|
80
|
|
|
|
|
|
|
{ |
|
81
|
0
|
|
|
0
|
|
|
my ($class, @arguments) = @_ ; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 TIEHASH |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
The method invoked by the command tie %hash, class name. Associates a new hash instance with the specified class. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
unless('Config::Hierarchical' eq ref $arguments[0]) |
|
90
|
|
|
|
|
|
|
{ |
|
91
|
0
|
|
|
|
|
|
croak "Argument must be a 'Config::Hierarchical' object!\n" ; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $self = {CONFIG => $arguments[0]} ; |
|
95
|
0
|
|
|
|
|
|
bless($self, $class) ; |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return($self) ; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub STORE |
|
103
|
|
|
|
|
|
|
{ |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
0
|
|
|
my ($this, $key, $value) = @_ ; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 STORE |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Dies as this tie is read only. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my (undef, $filename, $line) = caller() ; |
|
114
|
0
|
|
|
|
|
|
$this->{CONFIG}{INTERACTION}{DIE}->("This hash is read only at '$filename:$line'!\n") ; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub FETCH |
|
120
|
|
|
|
|
|
|
{ |
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
|
|
0
|
|
|
my ($this, $key) = @_ ; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 FETCH |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Retrieve the value associated with the configuration variable passed as argument |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
my (undef, $filename, $line) = caller() ; |
|
131
|
0
|
|
|
|
|
|
return($this->{CONFIG}->Get(NAME => $key, FILE => $filename, LINE => $line)) ; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub FIRSTKEY |
|
137
|
|
|
|
|
|
|
{ |
|
138
|
|
|
|
|
|
|
|
|
139
|
0
|
|
|
0
|
|
|
my ($this) = @_ ; |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 FIRSTKEY |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Return the first key in the hash. Used internally by Perl. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
|
146
|
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
$this->{KEYS} = [$this->{CONFIG}->GetKeys()] ; |
|
148
|
0
|
|
|
|
|
|
$this->{KEY_INDEX} = 0 ; |
|
149
|
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
return $this->{KEYS}[$this->{KEY_INDEX}] ; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub NEXTKEY |
|
156
|
|
|
|
|
|
|
{ |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
0
|
|
|
my ($this, $lastkey) = @_ ; |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 NEXTKEY |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Return the next key in the hash. Used internally by Perl. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
$this->{KEY_INDEX}++ ; |
|
167
|
0
|
|
|
|
|
|
return $this->{KEYS}[$this->{KEY_INDEX}] ; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub EXISTS |
|
173
|
|
|
|
|
|
|
{ |
|
174
|
|
|
|
|
|
|
|
|
175
|
0
|
|
|
0
|
|
|
my ($this, $key) = @_ ; |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 EXISTS |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Verify that key exists within the tied Config::Hierarchical. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
|
182
|
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
return($this->{CONFIG}->Exists(NAME => $key)) ; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub DELETE |
|
189
|
|
|
|
|
|
|
{ |
|
190
|
|
|
|
|
|
|
|
|
191
|
0
|
|
|
0
|
|
|
my ($this, $key) = @_ ; |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 DELETE |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Dies as this tie is read only. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |
|
198
|
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
my (undef, $filename, $line) = caller() ; |
|
200
|
0
|
|
|
|
|
|
$this->{CONFIG}{INTERACTION}{DIE}->("This hash is read only at '$filename:$line'!\n") ; |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub CLEAR |
|
206
|
|
|
|
|
|
|
{ |
|
207
|
|
|
|
|
|
|
|
|
208
|
0
|
|
|
0
|
|
|
my ($this) = @_ ; |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head2 CLEAR |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Dies as this tie is read only. |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |
|
215
|
|
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
|
my (undef, $filename, $line) = caller() ; |
|
217
|
0
|
|
|
|
|
|
$this->{CONFIG}{INTERACTION}{DIE}->("This hash is read only at '$filename:$line'!\n") ; |
|
218
|
|
|
|
|
|
|
} |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub SCALAR |
|
223
|
|
|
|
|
|
|
{ |
|
224
|
|
|
|
|
|
|
|
|
225
|
0
|
|
|
0
|
|
|
my ($this) = @_ ; |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head2 SCALAR |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
returns the number of elements in the tied Config::Hierarchical object. |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=cut |
|
232
|
|
|
|
|
|
|
|
|
233
|
0
|
|
|
|
|
|
return($this->{CONFIG}->GetKeys()) ; |
|
234
|
|
|
|
|
|
|
} |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
1 ; |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
None so far. |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head1 AUTHOR |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Khemir Nadim ibn Hamouda |
|
247
|
|
|
|
|
|
|
CPAN ID: NKH |
|
248
|
|
|
|
|
|
|
mailto:nadim@khemir.net |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Copyright 2007 Khemir Nadim. All rights reserved. |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
This program is free software; you can redistribute |
|
255
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 SUPPORT |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
perldoc Config::Hierarchical |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
You can also look for information at: |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=over 4 |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Config-Hierarchical> |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Please report any bugs or feature requests to L <bug-config-hierarchical@rt.cpan.org>. |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
We will be notified, and then you'll automatically be notified of progress on |
|
276
|
|
|
|
|
|
|
your bug as we make changes. |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=item * Search CPAN |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/Config-Hierarchical> |
|
281
|
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=back |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=cut |
|
288
|
|
|
|
|
|
|
|