44 |
|
|
45 |
sub readConf { |
sub readConf { |
46 |
my ($obj) = @_; |
my ($obj) = @_; |
47 |
$obj->{libconf}->readConf(); |
$obj->{libconf}->readConf; |
48 |
} |
} |
49 |
|
|
50 |
sub writeConf { |
sub writeConf { |
51 |
my ($obj) = @_; |
my ($obj) = @_; |
52 |
$obj->{libconf}->writeConf(); |
$obj->{libconf}->writeConf; |
53 |
} |
} |
54 |
|
|
55 |
|
|
59 |
|
|
60 |
sub TIEHASH { |
sub TIEHASH { |
61 |
my ($pkg, $libconf, $data_description, $data_mapping) = @_; |
my ($pkg, $libconf, $data_description, $data_mapping) = @_; |
62 |
debug; |
debug(); |
63 |
bless { |
bless { |
64 |
libconf => $libconf, |
libconf => $libconf, |
65 |
_data_description => $data_description, |
_data_description => $data_description, |
69 |
|
|
70 |
sub CLEAR { |
sub CLEAR { |
71 |
my ($obj) = @_; |
my ($obj) = @_; |
72 |
debug; |
debug(); |
73 |
$obj->{libconf}->clear(); |
$obj->{libconf}->clear; |
74 |
} |
} |
75 |
|
|
76 |
#sub DESTROY { |
#sub DESTROY { |
78 |
|
|
79 |
sub DELETE { |
sub DELETE { |
80 |
my ($obj, $key) = @_; |
my ($obj, $key) = @_; |
81 |
debug "key: $key"; |
debug("key: $key"); |
82 |
my @pos = $obj->{libconf}->findAtomPos( { type => 'SECTION', sections => [], section_name => $key }); |
my @pos = $obj->{libconf}->findAtomPos( { type => 'SECTION', sections => [], section_name => $key }); |
83 |
foreach (@pos) { |
foreach (@pos) { |
84 |
$obj->{libconf}->deleteSection($_, 1); |
$obj->{libconf}->deleteSection($_, 1); |
87 |
|
|
88 |
sub FIRSTKEY { |
sub FIRSTKEY { |
89 |
my ($obj) = @_; |
my ($obj) = @_; |
90 |
debug; |
debug(); |
91 |
my $atom = $obj->{libconf}->getAtom(0); |
my $atom = $obj->{libconf}->getAtom(0); |
92 |
$atom->{type} eq 'SECTION' or die "atom n° 0 is not a section\n"; |
$atom->{type} eq 'SECTION' or die "atom n° 0 is not a section\n"; |
93 |
$atom->{section_name}; |
$atom->{section_name}; |
95 |
|
|
96 |
sub EXISTS { |
sub EXISTS { |
97 |
my ($obj, $key) = @_; |
my ($obj, $key) = @_; |
98 |
debug "key : $key"; |
debug("key : $key"); |
99 |
my $pos = $obj->{libconf}->findAtomPos( { type => 'SECTION', sections => [], section_name => $key }); |
my $pos = $obj->{libconf}->findAtomPos( { type => 'SECTION', sections => [], section_name => $key }); |
100 |
defined $pos; |
defined $pos; |
101 |
} |
} |
102 |
|
|
103 |
sub NEXTKEY { |
sub NEXTKEY { |
104 |
my ($obj, $lastkey) = @_; |
my ($obj, $lastkey) = @_; |
105 |
debug "lastkey : $lastkey"; |
debug("lastkey : $lastkey"); |
106 |
my @pos = $obj->{libconf}->findAtomPos( { type => 'SECTION', sections => [] }); |
my @pos = $obj->{libconf}->findAtomPos( { type => 'SECTION', sections => [] }); |
107 |
my $i = 0; |
my $i = 0; |
108 |
my $index; |
my $index; |
118 |
|
|
119 |
sub STORE { |
sub STORE { |
120 |
my ($obj, $key, $value) = @_; |
my ($obj, $key, $value) = @_; |
121 |
debug "key : $key - value : $value"; |
debug("key : $key - value : $value"); |
122 |
ref $value eq 'HASH' or die 'trying to store something else than hash ref'; |
ref $value eq 'HASH' or die 'trying to store something else than hash ref'; |
123 |
my $index; |
my $index; |
124 |
my $pos = $obj->{libconf}->findAtomPos({ type => 'SECTION', section_name => $key, sections => [] }); |
my $pos = $obj->{libconf}->findAtomPos({ type => 'SECTION', section_name => $key, sections => [] }); |
130 |
|
|
131 |
sub FETCH { |
sub FETCH { |
132 |
my ($obj, $key) = @_; |
my ($obj, $key) = @_; |
133 |
debug "key : $key"; |
debug("key : $key"); |
134 |
$key eq 'libconf' and return $obj->{libconf}; |
$key eq 'libconf' and return $obj->{libconf}; |
135 |
substr($key, 0, 1) eq '_' and return $obj->{$key}; |
substr($key, 0, 1) eq '_' and return $obj->{$key}; |
136 |
my $section_position = $obj->{libconf}->findAtomPos( { type => 'SECTION', section_name => $key, sections => [ ] }); |
my $section_position = $obj->{libconf}->findAtomPos( { type => 'SECTION', section_name => $key, sections => [ ] }); |
146 |
|
|
147 |
sub TIEHASH { |
sub TIEHASH { |
148 |
my ($pkg, $libconf, $beginning) = @_; |
my ($pkg, $libconf, $beginning) = @_; |
149 |
debug "beginning : $beginning"; |
debug("beginning : $beginning"); |
150 |
my $atom = $libconf->getAtom($beginning); |
my $atom = $libconf->getAtom($beginning); |
151 |
my @depth = @{$atom->{sections}}; |
my @depth = @{$atom->{sections}}; |
152 |
scalar(keys %{$depth[0]}) == 0 and shift @depth; |
scalar(keys %{$depth[0]}) == 0 and shift @depth; |
153 |
push @depth, { name => $atom->{section_name} }; |
push @depth, { name => $atom->{section_name} }; |
154 |
|
|
155 |
my $key = $beginning+1; |
my $key = $beginning+1; |
156 |
foreach ($beginning+1..$libconf->size()-1) { |
foreach ($beginning+1..$libconf->size-1) { |
157 |
my $atom = $libconf->getAtom($_); |
my $atom = $libconf->getAtom($_); |
158 |
@{$atom->{sections}} > @depth and next; |
@{$atom->{sections}} > @depth and next; |
159 |
Libconf::compare_depth($atom->{sections}, \@depth) or last; |
Libconf::compare_depth($atom->{sections}, \@depth) or last; |
166 |
sections => \@depth, |
sections => \@depth, |
167 |
lastatom => $key, |
lastatom => $key, |
168 |
); |
); |
169 |
debug "firstatom : $hash{firstatom} - lastatom : $hash{lastatom}"; |
debug("firstatom : $hash{firstatom} - lastatom : $hash{lastatom}"); |
170 |
return bless \%hash, $pkg; |
return bless \%hash, $pkg; |
171 |
} |
} |
172 |
|
|
173 |
sub CLEAR { |
sub CLEAR { |
174 |
my ($obj) = @_; |
my ($obj) = @_; |
175 |
debug; |
debug(); |
176 |
$obj->{lastatom} -= $obj->{libconf}->clearSection($obj->{firstatom}, 1); |
$obj->{lastatom} -= $obj->{libconf}->clearSection($obj->{firstatom}, 1); |
177 |
$obj->{lastatom} == $obj->{firstatom} or die "removed atoms number is wrong"; |
$obj->{lastatom} == $obj->{firstatom} or die "removed atoms number is wrong"; |
178 |
} |
} |
179 |
|
|
180 |
sub DELETE { |
sub DELETE { |
181 |
my ($obj, $key) = @_; |
my ($obj, $key) = @_; |
182 |
debug "key : $key"; |
debug("key : $key"); |
183 |
my @pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $key }, |
my @pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $key }, |
184 |
$obj->{firstatom}+1, $obj->{lastatom}-1 |
$obj->{firstatom}+1, $obj->{lastatom}-1 |
185 |
); |
); |
191 |
|
|
192 |
sub FIRSTKEY { |
sub FIRSTKEY { |
193 |
my ($obj) = @_; |
my ($obj) = @_; |
194 |
debug; |
debug(); |
195 |
$obj->{firstatom} + 1 == $obj->{lastatom} and return undef; |
$obj->{firstatom} + 1 == $obj->{lastatom} and return undef; |
196 |
my $atom = $obj->{libconf}->getAtom($obj->{firstatom}+1); |
my $atom = $obj->{libconf}->getAtom($obj->{firstatom}+1); |
197 |
$atom->{type} eq 'KEY_VALUE' and return $atom->{key}; |
$atom->{type} eq 'KEY_VALUE' and return $atom->{key}; |
200 |
|
|
201 |
sub EXISTS { |
sub EXISTS { |
202 |
my ($obj, $key) = @_; |
my ($obj, $key) = @_; |
203 |
debug "key : $key"; |
debug("key : $key"); |
204 |
my $pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $key }, |
my $pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $key }, |
205 |
$obj->{firstatom}+1, $obj->{lastatom}-1 |
$obj->{firstatom}+1, $obj->{lastatom}-1 |
206 |
); |
); |
209 |
|
|
210 |
sub NEXTKEY { |
sub NEXTKEY { |
211 |
my ($obj, $lastkey) = @_; |
my ($obj, $lastkey) = @_; |
212 |
debug "SectionWrapper - NEXTKEY - lastkey : $lastkey"; |
debug("SectionWrapper - NEXTKEY - lastkey : $lastkey"); |
213 |
my $pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $lastkey }, |
my $pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $lastkey }, |
214 |
$obj->{firstatom}+1, $obj->{lastatom}-1 |
$obj->{firstatom}+1, $obj->{lastatom}-1 |
215 |
); |
); |
219 |
|
|
220 |
sub STORE { |
sub STORE { |
221 |
my ($obj, $key, $value) = @_; |
my ($obj, $key, $value) = @_; |
222 |
debug "key : $key - value : $value"; |
debug("key : $key - value : $value"); |
223 |
#ref $value eq 'HASH' or die 'trying to store anything else than hash ref'; |
#ref $value eq 'HASH' or die 'trying to store anything else than hash ref'; |
224 |
ref $value eq '' or die "try to store a hash in a kery_value atom"; |
ref $value eq '' or die "try to store a hash in a kery_value atom"; |
225 |
my $pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $key }, |
my $pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $key }, |
237 |
|
|
238 |
sub FETCH { |
sub FETCH { |
239 |
my ($obj, $key) = @_; |
my ($obj, $key) = @_; |
240 |
debug "key : $key\n"; |
debug("key : $key\n"); |
241 |
my $pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $key }, |
my $pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $key }, |
242 |
$obj->{firstatom}+1, $obj->{lastatom}-1 |
$obj->{firstatom}+1, $obj->{lastatom}-1 |
243 |
); |
); |