38 |
|
|
39 |
sub readConf { |
sub readConf { |
40 |
my ($obj) = @_; |
my ($obj) = @_; |
41 |
$obj->{libconf}->readConf(); |
$obj->{libconf}->readConf; |
42 |
} |
} |
43 |
|
|
44 |
sub writeConf { |
sub writeConf { |
45 |
my ($obj) = @_; |
my ($obj) = @_; |
46 |
$obj->{libconf}->writeConf(); |
$obj->{libconf}->writeConf; |
47 |
} |
} |
48 |
|
|
49 |
package Libconf::Glueconf::Resolv::Wrapper; |
package Libconf::Glueconf::Resolv::Wrapper; |
52 |
|
|
53 |
sub TIEHASH { |
sub TIEHASH { |
54 |
my ($pkg, $libconf) = @_; |
my ($pkg, $libconf) = @_; |
55 |
debug; |
debug(); |
56 |
my %hash; |
my %hash; |
57 |
tie my @nameserver_wrapper, 'Libconf::Glueconf::Resolv::Nameserver::Wrapper', $libconf; |
tie my @nameserver_wrapper, 'Libconf::Glueconf::Resolv::Nameserver::Wrapper', $libconf; |
58 |
$hash{nameserver} = \@nameserver_wrapper; |
$hash{nameserver} = \@nameserver_wrapper; |
72 |
|
|
73 |
sub CLEAR { |
sub CLEAR { |
74 |
my ($obj) = @_; |
my ($obj) = @_; |
75 |
debug; |
debug(); |
76 |
$obj->{hash} = {}; |
$obj->{hash} = {}; |
77 |
} |
} |
78 |
|
|
79 |
sub DELETE { |
sub DELETE { |
80 |
my ($obj, $key) = @_; |
my ($obj, $key) = @_; |
81 |
debug "key: $key"; |
debug("key: $key"); |
82 |
delete $obj->{hash}; |
delete $obj->{hash}; |
83 |
} |
} |
84 |
|
|
85 |
sub FIRSTKEY { |
sub FIRSTKEY { |
86 |
my ($obj) = @_; |
my ($obj) = @_; |
87 |
debug; |
debug(); |
|
my $a = keys %{$obj->{hash}}; |
|
88 |
scalar each %{$obj->{hash}}; |
scalar each %{$obj->{hash}}; |
89 |
} |
} |
90 |
|
|
91 |
sub EXISTS { |
sub EXISTS { |
92 |
my ($obj, $key) = @_; |
my ($obj, $key) = @_; |
93 |
debug "key : $key"; |
debug("key : $key"); |
94 |
exists $obj->{hash}; |
exists $obj->{hash}; |
95 |
} |
} |
96 |
|
|
97 |
sub NEXTKEY { |
sub NEXTKEY { |
98 |
my ($obj, $lastkey) = @_; |
my ($obj, $lastkey) = @_; |
99 |
debug "lastkey : $lastkey"; |
debug("lastkey : $lastkey"); |
100 |
scalar each %{$obj->{hash}}; |
scalar each %{$obj->{hash}}; |
101 |
} |
} |
102 |
|
|
103 |
sub STORE { |
sub STORE { |
104 |
my ($obj, $key, $value) = @_; |
my ($obj, $key, $value) = @_; |
105 |
debug "key : $key - value : $value"; |
debug("key : $key - value : $value"); |
106 |
$obj->{hash}{$key} = $value; |
$obj->{hash}{$key} = $value; |
107 |
} |
} |
108 |
|
|
109 |
sub FETCH { |
sub FETCH { |
110 |
my ($obj, $key) = @_; |
my ($obj, $key) = @_; |
111 |
debug "key : $key"; |
debug("key : $key"); |
112 |
$key eq 'libconf' ? $obj->{libconf} : $obj->{hash}{$key}; |
$key eq 'libconf' ? $obj->{libconf} : $obj->{hash}{$key}; |
113 |
} |
} |
114 |
|
|
119 |
|
|
120 |
sub TIEARRAY { |
sub TIEARRAY { |
121 |
my ($pkg, $libconf) = @_; |
my ($pkg, $libconf) = @_; |
122 |
debug; |
debug(); |
123 |
bless { libconf => $libconf }, $pkg; |
bless { libconf => $libconf }, $pkg; |
124 |
} |
} |
125 |
|
|
126 |
sub FETCH { |
sub FETCH { |
127 |
my ($obj, $idx) = @_; |
my ($obj, $idx) = @_; |
128 |
debug "idx : $idx"; |
debug("idx : $idx"); |
129 |
$idx eq 'libconf' and return $obj->{libconf}; |
$idx eq 'libconf' and return $obj->{libconf}; |
130 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
131 |
$obj->{libconf}->getAtom($pos[$idx])->{value}; |
$obj->{libconf}->getAtom($pos[$idx])->{value}; |
133 |
|
|
134 |
sub STORE { |
sub STORE { |
135 |
my ($obj, $idx, $value) = @_; |
my ($obj, $idx, $value) = @_; |
136 |
debug "idx : $idx - value : $value"; |
debug("idx : $idx - value : $value"); |
137 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
138 |
if ($idx > $#pos) { |
if ($idx > $#pos) { |
139 |
$obj->{libconf}->insertAtom($pos[-1]+1, {type => 'VALUE', type2 => 'RESOLV_NAMESERVER', value => $value}); |
$obj->{libconf}->insertAtom($pos[-1]+1, {type => 'VALUE', type2 => 'RESOLV_NAMESERVER', value => $value }); |
140 |
} else { |
} else { |
141 |
$obj->{libconf}->editAtom($pos[$idx], {type => 'VALUE', type2 => 'RESOLV_NAMESERVER', value => $value}); |
$obj->{libconf}->editAtom($pos[$idx], {type => 'VALUE', type2 => 'RESOLV_NAMESERVER', value => $value }); |
142 |
} |
} |
143 |
} |
} |
144 |
|
|
145 |
sub FETCHSIZE { |
sub FETCHSIZE { |
146 |
my ($obj) = @_; |
my ($obj) = @_; |
147 |
debug; |
debug(); |
148 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
149 |
# require Data::Dumper; |
# require Data::Dumper; |
150 |
# print Data::Dumper->Dump([@pos], ['pos']) . "\n"; |
# print Data::Dumper->Dump([@pos], ['pos']) . "\n"; |
151 |
# debug "NAMESERVER Wrapper - FETCHSIZE : " . scalar(@pos) . "\n"; |
# debug("NAMESERVER Wrapper - FETCHSIZE : " . scalar(@pos) . "\n"); |
152 |
scalar(@pos); |
scalar(@pos); |
153 |
} |
} |
154 |
|
|
155 |
sub STORESIZE { |
sub STORESIZE { |
156 |
my ($obj, $count) = @_; |
my ($obj, $count) = @_; |
157 |
debug "count : $count"; |
debug("count : $count"); |
158 |
my $size = $obj->FETCHSIZE(); |
my $size = $obj->FETCHSIZE; |
159 |
if ($count > $size) { |
if ($count > $size) { |
160 |
foreach ($count-$size..$count ) { |
foreach ($count-$size..$count) { |
161 |
$obj->STORE($_, ''); |
$obj->STORE($_, ''); |
162 |
} |
} |
163 |
} elsif ($count < $size) { |
} elsif ($count < $size) { |
164 |
foreach (0..$size-$count-2 ) { |
foreach (0..$size-$count-2) { |
165 |
$obj->POP(); |
$obj->POP; |
166 |
} |
} |
167 |
} |
} |
168 |
} |
} |
169 |
|
|
170 |
sub EXTEND { } |
sub EXTEND {} |
171 |
|
|
172 |
sub EXISTS { |
sub EXISTS { |
173 |
my ($obj, $index) = @_; |
my ($obj, $index) = @_; |
174 |
debug "index : $index"; |
debug("index : $index"); |
175 |
defined $obj->FETCH($index); |
defined $obj->FETCH($index); |
176 |
} |
} |
177 |
|
|
178 |
sub CLEAR { |
sub CLEAR { |
179 |
my $obj = shift; |
my $obj = shift; |
180 |
debug; |
debug(); |
181 |
$obj->{libconf}->deleteAtom($_) foreach $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
$obj->{libconf}->deleteAtom($_) foreach $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
182 |
} |
} |
183 |
|
|
184 |
sub PUSH { |
sub PUSH { |
185 |
my $obj = shift; |
my $obj = shift; |
186 |
my @list = @_; |
my @list = @_; |
187 |
debug "list : [" . join('|', @list) . "]"; |
debug("list : [" . join('|', @list) . "]"); |
188 |
my $last = $obj->FETCHSIZE(); |
my $last = $obj->FETCHSIZE; |
189 |
$obj->STORE($last + $_, $list[$_]) foreach (0..$#list); |
$obj->STORE($last + $_, $list[$_]) foreach (0..$#list); |
190 |
$obj->FETCHSIZE(); |
$obj->FETCHSIZE; |
191 |
} |
} |
192 |
|
|
193 |
sub POP { |
sub POP { |
194 |
my $obj = shift; |
my $obj = shift; |
195 |
debug; |
debug(); |
196 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
197 |
my $value = $obj->FETCH($pos[-1]); |
my $value = $obj->FETCH($pos[-1]); |
198 |
$obj->{libconf}->deleteAtom($pos[-1]); |
$obj->{libconf}->deleteAtom($pos[-1]); |
201 |
|
|
202 |
sub SHIFT { |
sub SHIFT { |
203 |
my $obj = shift; |
my $obj = shift; |
204 |
debug; |
debug(); |
205 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
206 |
my $value = $obj->FETCH($pos[0]); |
my $value = $obj->FETCH($pos[0]); |
207 |
$obj->{libconf}->deleteAtom($pos[0]); |
$obj->{libconf}->deleteAtom($pos[0]); |
210 |
|
|
211 |
sub UNSHIFT { |
sub UNSHIFT { |
212 |
my ($obj, @list) = @_; |
my ($obj, @list) = @_; |
213 |
debug "list : [" . join('|', @list); |
debug("list : [" . join('|', @list)); |
214 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
215 |
$obj->{libconf}->insertAtom($pos[0], {type => 'VALUE', type2 => 'RESOLV_NAMESERVER', value => $_}) foreach (reverse @list); |
$obj->{libconf}->insertAtom($pos[0], {type => 'VALUE', type2 => 'RESOLV_NAMESERVER', value => $_ }) foreach reverse @list; |
216 |
} |
} |
217 |
|
|
218 |
sub SPLICE { |
sub SPLICE { |
219 |
my $obj = shift; |
my $obj = shift; |
220 |
my $offset = shift || 0; |
my $offset = shift || 0; |
221 |
my $length = shift || $obj->FETCHSIZE() - $offset; |
my $length = shift || $obj->FETCHSIZE - $offset; |
222 |
my @list = @_; |
my @list = @_; |
223 |
debug "offset : $offset - length : $length - list : [" . join('|', @list) . "]"; |
debug("offset : $offset - length : $length - list : [" . join('|', @list) . "]"); |
224 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_NAMESERVER' }); |
225 |
my @ret = (); |
my @ret; |
226 |
foreach (0..$length-1){ |
foreach (0..$length-1) { |
227 |
print " -- $_ \n"; |
print " -- $_ \n"; |
228 |
print exists($list[$_]) . "\n"; |
print exists($list[$_]) . "\n"; |
229 |
push @ret, $obj->FETCH($offset+$_); |
push @ret, $obj->FETCH($offset+$_); |
230 |
exists $list[$_] ? $obj->STORE($offset+$_, $list[$_]) : $obj->{libconf}->deleteAtom($pos[$offset+$_]); |
exists $list[$_] ? $obj->STORE($offset+$_, $list[$_]) : $obj->{libconf}->deleteAtom($pos[$offset+$_]); |
231 |
} |
} |
232 |
wantarray ? @ret : $ret[-1]; |
wantarray() ? @ret : $ret[-1]; |
233 |
} |
} |
234 |
|
|
235 |
package Libconf::Glueconf::Resolv::Domain::Wrapper; |
package Libconf::Glueconf::Resolv::Domain::Wrapper; |
238 |
|
|
239 |
sub TIESCALAR { |
sub TIESCALAR { |
240 |
my ($pkg, $libconf) = @_; |
my ($pkg, $libconf) = @_; |
241 |
debug; |
debug(); |
242 |
bless { libconf => $libconf }, $pkg; |
bless { libconf => $libconf }, $pkg; |
243 |
} |
} |
244 |
|
|
245 |
sub FETCH { |
sub FETCH { |
246 |
my ($obj) = @_; |
my ($obj) = @_; |
247 |
debug; |
debug(); |
248 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_DOMAIN' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_DOMAIN' }); |
249 |
@pos > 0 or return undef; |
@pos > 0 or return undef; |
250 |
$obj->{libconf}->getAtom($pos[-1])->{value}; |
$obj->{libconf}->getAtom($pos[-1])->{value}; |
252 |
|
|
253 |
sub STORE { |
sub STORE { |
254 |
my ($obj, $value) = @_; |
my ($obj, $value) = @_; |
255 |
debug "value : $value"; |
debug("value : $value"); |
256 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_DOMAIN' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'VALUE', type2 => 'RESOLV_DOMAIN' }); |
257 |
if (@pos > 0) { |
if (@pos > 0) { |
258 |
$obj->{libconf}->editAtom($pos[-1], {type => 'VALUE', type2 => 'RESOLV_DOMAIN', value => $value}); |
$obj->{libconf}->editAtom($pos[-1], {type => 'VALUE', type2 => 'RESOLV_DOMAIN', value => $value }); |
259 |
} else { |
} else { |
260 |
$obj->{libconf}->appendAtom({type => 'VALUE', type2 => 'RESOLV_DOMAIN', value => $value}); |
$obj->{libconf}->appendAtom({type => 'VALUE', type2 => 'RESOLV_DOMAIN', value => $value }); |
261 |
} |
} |
262 |
} |
} |
263 |
|
|
267 |
|
|
268 |
sub TIEARRAY { |
sub TIEARRAY { |
269 |
my ($pkg, $libconf) = @_; |
my ($pkg, $libconf) = @_; |
270 |
debug; |
debug(); |
271 |
bless { libconf => $libconf }, $pkg; |
bless { libconf => $libconf }, $pkg; |
272 |
} |
} |
273 |
|
|
274 |
sub FETCH { |
sub FETCH { |
275 |
my ($obj, $idx) = @_; |
my ($obj, $idx) = @_; |
276 |
debug "idx : $idx"; |
debug("idx : $idx"); |
277 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
278 |
$obj->{libconf}->getAtom($pos[-1])->{list}->[$idx]; |
$obj->{libconf}->getAtom($pos[-1])->{list}->[$idx]; |
279 |
} |
} |
280 |
|
|
281 |
sub STORE { |
sub STORE { |
282 |
my ($obj, $idx, $value) = @_; |
my ($obj, $idx, $value) = @_; |
283 |
debug "idx : $idx - value : $value"; |
debug("idx : $idx - value : $value"); |
284 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
285 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
286 |
$tab[$idx] = $value; |
$tab[$idx] = $value; |
289 |
|
|
290 |
sub FETCHSIZE { |
sub FETCHSIZE { |
291 |
my ($obj) = @_; |
my ($obj) = @_; |
292 |
debug; |
debug(); |
293 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
294 |
@pos > 0 or return 0; |
@pos > 0 or return 0; |
295 |
# require Data::Dumper; |
# require Data::Dumper; |
296 |
# print Data::Dumper->Dump([@pos], ['@pos']) . "\n"; |
# print Data::Dumper->Dump([@pos], ['@pos']) . "\n"; |
297 |
my $pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
# my $pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
298 |
# print Data::Dumper->Dump([$pos], ['$pos']) . "\n"; |
# print Data::Dumper->Dump([$pos], ['$pos']) . "\n"; |
299 |
# debug "SEARCH Wrapper - FETCHSIZE : " . scalar(@{$obj->{libconf}->getAtom($pos[-1])->{list}}) . "\n"; |
# debug("SEARCH Wrapper - FETCHSIZE : " . scalar(@{$obj->{libconf}->getAtom($pos[-1])->{list}}) . "\n"); |
300 |
scalar @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
scalar @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
301 |
} |
} |
302 |
|
|
303 |
sub STORESIZE { |
sub STORESIZE { |
304 |
my ($obj, $count) = @_; |
my ($obj, $count) = @_; |
305 |
debug "count : $count"; |
debug("count : $count"); |
306 |
my $size = $obj->FETCHSIZE(); |
my $size = $obj->FETCHSIZE; |
307 |
if ($count > $size) { |
if ($count > $size) { |
308 |
foreach ($count-$size..$count ) { |
foreach ($count-$size..$count) { |
309 |
$obj->STORE($_, ''); |
$obj->STORE($_, ''); |
310 |
} |
} |
311 |
} elsif ($count < $size) { |
} elsif ($count < $size) { |
312 |
foreach (0..$size-$count-2 ) { |
foreach (0..$size-$count-2) { |
313 |
$obj->POP(); |
$obj->POP; |
314 |
} |
} |
315 |
} |
} |
316 |
} |
} |
317 |
|
|
318 |
sub EXTEND { } |
sub EXTEND {} |
319 |
|
|
320 |
sub EXISTS { |
sub EXISTS { |
321 |
my ($obj, $index) = @_; |
my ($obj, $index) = @_; |
322 |
debug "index : $index"; |
debug("index : $index"); |
323 |
defined $obj->FETCH($index); |
defined $obj->FETCH($index); |
324 |
} |
} |
325 |
|
|
326 |
sub CLEAR { |
sub CLEAR { |
327 |
my $obj = shift; |
my $obj = shift; |
328 |
debug; |
debug(); |
329 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
330 |
$obj->{libconf}->editAtom($pos[-1], { list => [] }); |
$obj->{libconf}->editAtom($pos[-1], { list => [] }); |
331 |
} |
} |
333 |
sub PUSH { |
sub PUSH { |
334 |
my $obj = shift; |
my $obj = shift; |
335 |
my @list = @_; |
my @list = @_; |
336 |
debug "list : [" . join('|', @list) . "]"; |
debug("list : [" . join('|', @list) . "]"); |
337 |
my $last = $obj->FETCHSIZE(); |
my $last = $obj->FETCHSIZE; |
338 |
$obj->STORE($last + $_, $list[$_]) foreach (0..$#list); |
$obj->STORE($last + $_, $list[$_]) foreach (0..$#list); |
339 |
$obj->FETCHSIZE(); |
$obj->FETCHSIZE; |
340 |
} |
} |
341 |
|
|
342 |
sub POP { |
sub POP { |
343 |
my $obj = shift; |
my $obj = shift; |
344 |
debug; |
debug(); |
345 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
346 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
347 |
my $value = pop @tab; |
my $value = pop @tab; |
351 |
|
|
352 |
sub SHIFT { |
sub SHIFT { |
353 |
my $obj = shift; |
my $obj = shift; |
354 |
debug; |
debug(); |
355 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
356 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
357 |
my $value = shift @tab; |
my $value = shift @tab; |
361 |
|
|
362 |
sub UNSHIFT { |
sub UNSHIFT { |
363 |
my ($obj, @list) = @_; |
my ($obj, @list) = @_; |
364 |
debug "list : [" . join('|', @list); |
debug("list : [" . join('|', @list)); |
365 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
366 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
367 |
unshift @tab, @list; |
unshift @tab, @list; |
371 |
sub SPLICE { |
sub SPLICE { |
372 |
my $obj = shift; |
my $obj = shift; |
373 |
my $offset = shift || 0; |
my $offset = shift || 0; |
374 |
my $length = shift || $obj->FETCHSIZE() - $offset; |
my $length = shift || $obj->FETCHSIZE - $offset; |
375 |
my @list = @_; |
my @list = @_; |
376 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SEARCH' }); |
377 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
378 |
my @ret = splice @tab, $offset, $length, @list; |
my @ret = splice @tab, $offset, $length, @list; |
379 |
$obj->{libconf}->editAtom($pos[-1], { list => \@tab }); |
$obj->{libconf}->editAtom($pos[-1], { list => \@tab }); |
380 |
wantarray ? @ret : $ret[-1]; |
wantarray() ? @ret : $ret[-1]; |
381 |
} |
} |
382 |
|
|
383 |
package Libconf::Glueconf::Resolv::Sortlist::Wrapper; |
package Libconf::Glueconf::Resolv::Sortlist::Wrapper; |
386 |
|
|
387 |
sub TIEARRAY { |
sub TIEARRAY { |
388 |
my ($pkg, $libconf) = @_; |
my ($pkg, $libconf) = @_; |
389 |
debug; |
debug(); |
390 |
bless { libconf => $libconf }, $pkg; |
bless { libconf => $libconf }, $pkg; |
391 |
} |
} |
392 |
|
|
393 |
sub FETCH { |
sub FETCH { |
394 |
my ($obj, $idx) = @_; |
my ($obj, $idx) = @_; |
395 |
debug "idx : $idx"; |
debug("idx : $idx"); |
396 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
397 |
$obj->{libconf}->getAtom($pos[-1])->{list}->[$idx]; |
$obj->{libconf}->getAtom($pos[-1])->{list}->[$idx]; |
398 |
} |
} |
399 |
|
|
400 |
sub STORE { |
sub STORE { |
401 |
my ($obj, $idx, $value) = @_; |
my ($obj, $idx, $value) = @_; |
402 |
debug "idx : $idx - value : $value"; |
debug("idx : $idx - value : $value"); |
403 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
404 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
405 |
$tab[$idx] = $value; |
$tab[$idx] = $value; |
408 |
|
|
409 |
sub FETCHSIZE { |
sub FETCHSIZE { |
410 |
my ($obj) = @_; |
my ($obj) = @_; |
411 |
debug; |
debug(); |
412 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
413 |
@pos > 0 or return 0; |
@pos > 0 or return 0; |
414 |
scalar @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
scalar @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
416 |
|
|
417 |
sub STORESIZE { |
sub STORESIZE { |
418 |
my ($obj, $count) = @_; |
my ($obj, $count) = @_; |
419 |
debug "count : $count"; |
debug("count : $count"); |
420 |
my $size = $obj->FETCHSIZE(); |
my $size = $obj->FETCHSIZE; |
421 |
if ($count > $size) { |
if ($count > $size) { |
422 |
foreach ($count-$size..$count ) { |
foreach ($count-$size..$count) { |
423 |
$obj->STORE($_, ''); |
$obj->STORE($_, ''); |
424 |
} |
} |
425 |
} elsif ($count < $size) { |
} elsif ($count < $size) { |
426 |
foreach (0..$size-$count-2 ) { |
foreach (0..$size-$count-2) { |
427 |
$obj->POP(); |
$obj->POP; |
428 |
} |
} |
429 |
} |
} |
430 |
} |
} |
431 |
|
|
432 |
sub EXTEND { } |
sub EXTEND {} |
433 |
|
|
434 |
sub EXISTS { |
sub EXISTS { |
435 |
my ($obj, $index) = @_; |
my ($obj, $index) = @_; |
436 |
debug "index : $index"; |
debug("index : $index"); |
437 |
defined $obj->FETCH($index); |
defined $obj->FETCH($index); |
438 |
} |
} |
439 |
|
|
440 |
sub CLEAR { |
sub CLEAR { |
441 |
my $obj = shift; |
my $obj = shift; |
442 |
debug; |
debug(); |
443 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
444 |
$obj->{libconf}->editAtom($pos[-1], { list => [] }); |
$obj->{libconf}->editAtom($pos[-1], { list => [] }); |
445 |
} |
} |
447 |
sub PUSH { |
sub PUSH { |
448 |
my $obj = shift; |
my $obj = shift; |
449 |
my @list = @_; |
my @list = @_; |
450 |
debug "list : [" . join('|', @list) . "]"; |
debug("list : [" . join('|', @list) . "]"); |
451 |
my $last = $obj->FETCHSIZE(); |
my $last = $obj->FETCHSIZE; |
452 |
$obj->STORE($last + $_, $list[$_]) foreach (0..$#list); |
$obj->STORE($last + $_, $list[$_]) foreach (0..$#list); |
453 |
$obj->FETCHSIZE(); |
$obj->FETCHSIZE; |
454 |
} |
} |
455 |
|
|
456 |
sub POP { |
sub POP { |
457 |
my $obj = shift; |
my $obj = shift; |
458 |
debug; |
debug(); |
459 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
460 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
461 |
my $value = pop @tab; |
my $value = pop @tab; |
465 |
|
|
466 |
sub SHIFT { |
sub SHIFT { |
467 |
my $obj = shift; |
my $obj = shift; |
468 |
debug; |
debug(); |
469 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
470 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
471 |
my $value = shift @tab; |
my $value = shift @tab; |
475 |
|
|
476 |
sub UNSHIFT { |
sub UNSHIFT { |
477 |
my ($obj, @list) = @_; |
my ($obj, @list) = @_; |
478 |
debug "list : [" . join('|', @list); |
debug("list : [" . join('|', @list)); |
479 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
480 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
481 |
unshift @tab, @list; |
unshift @tab, @list; |
485 |
sub SPLICE { |
sub SPLICE { |
486 |
my $obj = shift; |
my $obj = shift; |
487 |
my $offset = shift || 0; |
my $offset = shift || 0; |
488 |
my $length = shift || $obj->FETCHSIZE() - $offset; |
my $length = shift || $obj->FETCHSIZE - $offset; |
489 |
my @list = @_; |
my @list = @_; |
490 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_SORTLIST' }); |
491 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
492 |
my @ret = splice @tab, $offset, $length, @list; |
my @ret = splice @tab, $offset, $length, @list; |
493 |
$obj->{libconf}->editAtom($pos[-1], { list => \@tab }); |
$obj->{libconf}->editAtom($pos[-1], { list => \@tab }); |
494 |
wantarray ? @ret : $ret[-1]; |
wantarray() ? @ret : $ret[-1]; |
495 |
} |
} |
496 |
|
|
497 |
|
|
501 |
|
|
502 |
sub TIEARRAY { |
sub TIEARRAY { |
503 |
my ($pkg, $libconf) = @_; |
my ($pkg, $libconf) = @_; |
504 |
debug; |
debug(); |
505 |
bless { libconf => $libconf }, $pkg; |
bless { libconf => $libconf }, $pkg; |
506 |
} |
} |
507 |
|
|
508 |
sub FETCH { |
sub FETCH { |
509 |
my ($obj, $idx) = @_; |
my ($obj, $idx) = @_; |
510 |
debug "idx : $idx"; |
debug("idx : $idx"); |
511 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
512 |
$obj->{libconf}->getAtom($pos[-1])->{list}->[$idx]; |
$obj->{libconf}->getAtom($pos[-1])->{list}->[$idx]; |
513 |
} |
} |
514 |
|
|
515 |
sub STORE { |
sub STORE { |
516 |
my ($obj, $idx, $value) = @_; |
my ($obj, $idx, $value) = @_; |
517 |
debug "idx : $idx - value : $value"; |
debug("idx : $idx - value : $value"); |
518 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
519 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
520 |
$tab[$idx] = $value; |
$tab[$idx] = $value; |
523 |
|
|
524 |
sub FETCHSIZE { |
sub FETCHSIZE { |
525 |
my ($obj) = @_; |
my ($obj) = @_; |
526 |
debug; |
debug(); |
527 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
528 |
@pos > 0 or return 0; |
@pos > 0 or return 0; |
529 |
scalar @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
scalar @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
531 |
|
|
532 |
sub STORESIZE { |
sub STORESIZE { |
533 |
my ($obj, $count) = @_; |
my ($obj, $count) = @_; |
534 |
debug "count : $count"; |
debug("count : $count"); |
535 |
my $size = $obj->FETCHSIZE(); |
my $size = $obj->FETCHSIZE; |
536 |
if ($count > $size) { |
if ($count > $size) { |
537 |
foreach ($count-$size..$count ) { |
foreach ($count-$size..$count) { |
538 |
$obj->STORE($_, ''); |
$obj->STORE($_, ''); |
539 |
} |
} |
540 |
} elsif ($count < $size) { |
} elsif ($count < $size) { |
541 |
foreach (0..$size-$count-2 ) { |
foreach (0..$size-$count-2) { |
542 |
$obj->POP(); |
$obj->POP; |
543 |
} |
} |
544 |
} |
} |
545 |
} |
} |
546 |
|
|
547 |
sub EXTEND { } |
sub EXTEND {} |
548 |
|
|
549 |
sub EXISTS { |
sub EXISTS { |
550 |
my ($obj, $index) = @_; |
my ($obj, $index) = @_; |
551 |
debug "index : $index"; |
debug("index : $index"); |
552 |
defined $obj->FETCH($index); |
defined $obj->FETCH($index); |
553 |
} |
} |
554 |
|
|
555 |
sub CLEAR { |
sub CLEAR { |
556 |
my $obj = shift; |
my $obj = shift; |
557 |
debug; |
debug(); |
558 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
559 |
$obj->{libconf}->editAtom($pos[-1], { list => [] }); |
$obj->{libconf}->editAtom($pos[-1], { list => [] }); |
560 |
} |
} |
562 |
sub PUSH { |
sub PUSH { |
563 |
my $obj = shift; |
my $obj = shift; |
564 |
my @list = @_; |
my @list = @_; |
565 |
debug "list : [" . join('|', @list) . "]"; |
debug("list : [" . join('|', @list) . "]"); |
566 |
my $last = $obj->FETCHSIZE(); |
my $last = $obj->FETCHSIZE; |
567 |
$obj->STORE($last + $_, $list[$_]) foreach (0..$#list); |
$obj->STORE($last + $_, $list[$_]) foreach (0..$#list); |
568 |
$obj->FETCHSIZE(); |
$obj->FETCHSIZE; |
569 |
} |
} |
570 |
|
|
571 |
sub POP { |
sub POP { |
572 |
my $obj = shift; |
my $obj = shift; |
573 |
debug; |
debug(); |
574 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
575 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
576 |
my $value = pop @tab; |
my $value = pop @tab; |
580 |
|
|
581 |
sub SHIFT { |
sub SHIFT { |
582 |
my $obj = shift; |
my $obj = shift; |
583 |
debug; |
debug(); |
584 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
585 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
586 |
my $value = shift @tab; |
my $value = shift @tab; |
590 |
|
|
591 |
sub UNSHIFT { |
sub UNSHIFT { |
592 |
my ($obj, @list) = @_; |
my ($obj, @list) = @_; |
593 |
debug "list : [" . join('|', @list); |
debug("list : [" . join('|', @list)); |
594 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
595 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
596 |
unshift @tab, @list; |
unshift @tab, @list; |
600 |
sub SPLICE { |
sub SPLICE { |
601 |
my $obj = shift; |
my $obj = shift; |
602 |
my $offset = shift || 0; |
my $offset = shift || 0; |
603 |
my $length = shift || $obj->FETCHSIZE() - $offset; |
my $length = shift || $obj->FETCHSIZE - $offset; |
604 |
my @list = @_; |
my @list = @_; |
605 |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
my @pos = $obj->{libconf}->findAtomPos({ type => 'LIST', type2 => 'RESOLV_OPTIONS' }); |
606 |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
my @tab = @{$obj->{libconf}->getAtom($pos[-1])->{list}}; |
607 |
my @ret = splice @tab, $offset, $length, @list; |
my @ret = splice @tab, $offset, $length, @list; |
608 |
$obj->{libconf}->editAtom($pos[-1], { list => \@tab }); |
$obj->{libconf}->editAtom($pos[-1], { list => \@tab }); |
609 |
wantarray ? @ret : $ret[-1]; |
wantarray() ? @ret : $ret[-1]; |
610 |
} |
} |
611 |
|
|
612 |
1; |
1; |