/[webpac2]/trunk/lib/WebPAC/Input.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WebPAC/Input.pm

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

revision 1221 by dpavlin, Tue Jun 9 21:37:32 2009 UTC revision 1304 by dpavlin, Sun Sep 20 21:38:15 2009 UTC
# Line 137  This function will read whole database i Line 137  This function will read whole database i
137    
138  By default, C<input_encoding> is assumed to be C<cp852>.  By default, C<input_encoding> is assumed to be C<cp852>.
139    
140  C<offset> is optional parametar to position at some offset before reading from database.  C<offset> is optional parametar to skip records at beginning.
141    
142  C<limit> is optional parametar to read just C<limit> records from database  C<limit> is optional parametar to read just C<limit> records from database
143    
# Line 183  sub open { Line 183  sub open {
183    
184          # store data in object          # store data in object
185          foreach my $v (qw/path offset limit/) {          foreach my $v (qw/path offset limit/) {
186                  $self->{$v} = $arg->{$v} if ($arg->{$v});                  $self->{$v} = $arg->{$v} if defined $arg->{$v};
187          }          }
188    
189          if ($arg->{load_row} || $arg->{save_row}) {          if ($arg->{load_row} || $arg->{save_row}) {
# Line 230  sub open { Line 230  sub open {
230    
231          my $class = $self->{module} || $log->logconfess("can't get low-level module name!");          my $class = $self->{module} || $log->logconfess("can't get low-level module name!");
232    
233            $arg->{$_} = $self->{$_} foreach qw(offset limit);
234    
235          my $ll_db = $class->new(          my $ll_db = $class->new(
236                  path => $arg->{path},                  path => $arg->{path},
237                  input_config => $arg->{input_config} || $self->{input_config},                  input_config => $arg->{input_config} || $self->{input_config},
# Line 243  sub open { Line 245  sub open {
245                  %{ $arg },                  %{ $arg },
246          );          );
247    
248            # save for dump and input_module
249            $self->{ll_db} = $ll_db;
250    
251          unless (defined($ll_db)) {          unless (defined($ll_db)) {
252                  $log->logwarn("can't open database $arg->{path}, skipping...");                  $log->logwarn("can't open database $arg->{path}, skipping...");
253                  return;                  return;
# Line 259  sub open { Line 264  sub open {
264          my $to_rec = $size;          my $to_rec = $size;
265    
266          if (my $s = $self->{offset}) {          if (my $s = $self->{offset}) {
267                  $log->debug("skipping to MFN $s");                  $log->debug("offset $s records");
268                  $from_rec = $s;                  $from_rec = $s + 1;
269          } else {          } else {
270                  $self->{offset} = $from_rec;                  $self->{offset} = $from_rec - 1;
271          }          }
272    
273          if ($self->{limit}) {          if ($self->{limit}) {
# Line 272  sub open { Line 277  sub open {
277          }          }
278    
279          # store size for later          # store size for later
280          $self->{size} = ($to_rec - $from_rec) ? ($to_rec - $from_rec + 1) : 0;          $self->{size} = $to_rec - $from_rec + 1;
281    
282          my $strict_encoding = $arg->{strict_encoding} || $self->{strict_encoding}; ## FIXME should be 1 really          my $strict_encoding = $arg->{strict_encoding} || $self->{strict_encoding}; ## FIXME should be 1 really
283    
# Line 386  sub open { Line 391  sub open {
391          $self->{max_pos} = $to_rec;          $self->{max_pos} = $to_rec;
392          $log->debug("max_pos: $to_rec");          $log->debug("max_pos: $to_rec");
393    
         # save for dump  
         $self->{ll_db} = $ll_db;  
   
394          return $size;          return $size;
395  }  }
396    
# Line 413  sub fetch { Line 415  sub fetch {
415          $log->logconfess("it seems that you didn't load database!") unless ($self->{pos});          $log->logconfess("it seems that you didn't load database!") unless ($self->{pos});
416    
417          if ($self->{pos} == -1) {          if ($self->{pos} == -1) {
418                  $self->{pos} = $self->{offset};                  $self->{pos} = $self->{offset} + 1;
419          } else {          } else {
420                  $self->{pos}++;                  $self->{pos}++;
421          }          }

Legend:
Removed from v.1221  
changed lines
  Added in v.1304

  ViewVC Help
Powered by ViewVC 1.1.26