/[libconf]/libconf/perl-Libconf/Glueconf/Resolv.pm
ViewVC logotype

Diff of /libconf/perl-Libconf/Glueconf/Resolv.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by tv, Thu Nov 27 09:57:11 2003 UTC revision 1.8 by tv, Thu Nov 27 10:23:46 2003 UTC
# Line 38  sub new { Line 38  sub new {
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;
# Line 52  sub debug { Libconf::debug(@_) } Line 52  sub debug { Libconf::debug(@_) }
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;
# Line 72  sub TIEHASH { Line 72  sub TIEHASH {
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    
# Line 120  sub debug { Libconf::debug(@_) } Line 119  sub debug { Libconf::debug(@_) }
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};
# Line 134  sub FETCH { Line 133  sub FETCH {
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]);
# Line 202  sub POP { Line 201  sub POP {
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]);
# Line 211  sub SHIFT { Line 210  sub SHIFT {
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;
# Line 239  sub debug { Libconf::debug(@_) } Line 238  sub debug { Libconf::debug(@_) }
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};
# Line 253  sub FETCH { Line 252  sub FETCH {
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    
# Line 268  sub debug { Libconf::debug(@_) } Line 267  sub debug { Libconf::debug(@_) }
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;
# Line 290  sub STORE { Line 289  sub STORE {
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  }  }
# Line 334  sub CLEAR { Line 333  sub CLEAR {
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;
# Line 352  sub POP { Line 351  sub POP {
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;
# Line 362  sub SHIFT { Line 361  sub SHIFT {
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;
# Line 372  sub UNSHIFT { Line 371  sub UNSHIFT {
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;
# Line 387  sub debug { Libconf::debug(@_) } Line 386  sub debug { Libconf::debug(@_) }
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;
# Line 409  sub STORE { Line 408  sub STORE {
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}};
# Line 417  sub FETCHSIZE { Line 416  sub FETCHSIZE {
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  }  }
# Line 448  sub CLEAR { Line 447  sub CLEAR {
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;
# Line 466  sub POP { Line 465  sub POP {
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;
# Line 476  sub SHIFT { Line 475  sub SHIFT {
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;
# Line 486  sub UNSHIFT { Line 485  sub UNSHIFT {
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    
# Line 502  sub debug { Libconf::debug(@_) } Line 501  sub debug { Libconf::debug(@_) }
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;
# Line 524  sub STORE { Line 523  sub STORE {
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}};
# Line 532  sub FETCHSIZE { Line 531  sub FETCHSIZE {
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  }  }
# Line 563  sub CLEAR { Line 562  sub CLEAR {
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;
# Line 581  sub POP { Line 580  sub POP {
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;
# Line 591  sub SHIFT { Line 590  sub SHIFT {
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;
# Line 601  sub UNSHIFT { Line 600  sub UNSHIFT {
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;

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26