/
README
210 lines (156 loc) · 4.36 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
NAME
Config::Dot::Array - Module for simple configure file parsing with
arrays.
SYNOPSIS
my $cnf = Config::Dot::Array->new(%params);
my $struct_hr = $cnf->parse($string_or_array_ref);
$cnf->reset;
my $serialized = $cnf->serialize;
METHODS
"new"
Constructor.
* "callback"
Callback code for adding parameter. Callback arguments are:
$key_ar - Reference to array with keys.
$value - Key value.
Default is undef.
* "config"
Reference to hash structure with default config data. This is
hash of hashes or arrays structure.
Default value is reference to blank hash.
* "set_conflicts"
Set conflicts detection as error.
Default value is 1.
"parse"
my $struct_hr = $cnf->parse($string_or_array_ref);
Parse string $string_or_array_ref or reference to array
$string_or_array_ref and returns structure.
Returns reference to hash.
"reset"
$cnf->reset;
Reset content in class (config parameter).
Returns undef.
"serialize"
my $serialized = $cnf->serialize;
Serialize 'config' parameter hash to output.
Returns string.
PARAMETER_FILE
# Comment.
# blabla
# White space.
/^\s*$/
# Parameters.
# Key must be '[-\w\.:,]+'.
# Separator is '='.
key=val
key2.subkey.subkey=val
# Arrays.
key3=val1
key3=val2
ERRORS
new():
Bad 'config' parameter.
Parameter 'callback' isn't code reference.
From Class::Utils::set_params():
Unknown parameter '%s'.
parse():
Bad key '%s' in string '%s' at line '%s'.
From Config::Utils::hash_array():
Conflict in '%s'.
EXAMPLE1
use strict;
use warnings;
use Config::Dot::Array;
use Dumpvalue;
# Object.
my $struct_hr = Config::Dot::Array->new->parse(<<'END');
key1=value1
key2=value2
key2=value3
key3.subkey1=value4
key3.subkey1=value5
END
# Dump
my $dump = Dumpvalue->new;
$dump->dumpValues($struct_hr);
# Output:
# 0 HASH(0x9970430)
# 'key1' => 'value1'
# 'key2' => ARRAY(0x9970660)
# 0 'value2'
# 1 'value3'
# 'key3' => HASH(0x9970240)
# 'subkey1' => ARRAY(0xa053658)
# 0 'value4'
# 1 'value5'
EXAMPLE2
use strict;
use warnings;
use Config::Dot::Array;
# Object with data.
my $c = Config::Dot::Array->new(
'config' => {
'key1' => {
'subkey1' => 'value1',
},
'key2' => [
'value2',
'value3',
],
},
);
# Serialize.
print $c->serialize."\n";
# Output:
# key1=subkey1.value1
# key2=value2
# key2=value3
EXAMPLE3
use strict;
use warnings;
use Config::Dot::Array;
use Dumpvalue;
# Object.
my $struct_hr = Config::Dot::Array->new(
'callback' => sub {
my ($key_ar, $value) = @_;
if ($key_ar->[0] eq 'key3' && $key_ar->[1] eq 'subkey1'
&& $value eq 'value3') {
return 'FOOBAR';
}
return $value;
},
)->parse(<<'END');
key1=value1
key2=value2
key3.subkey1=value3
key3.subkey1=value4
END
# Dump
my $dump = Dumpvalue->new;
$dump->dumpValues($struct_hr);
# Output:
# 0 HASH(0x87d05e8)
# 'key1' => 'value1'
# 'key2' => 'value2'
# 'key3' => HASH(0x87e3840)
# 'subkey1' => ARRAY(0x87e6f68)
# 0 'FOOBAR'
# 1 'value4'
DEPENDENCIES
Class::Utils, Config::Utils, English, Error::Pure, Readonly.
SEE ALSO
Config::Dot
Module for simple configure file parsing.
Config::Utils
Common config utilities.
REPOSITORY
<https://github.com/michal-josef-spacek/Config-Dot-Array>
AUTHOR
Michal Josef Špaček <mailto:skim@cpan.org>
<http://skim.cz>
LICENSE AND COPYRIGHT
© 2011-2023 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.09