--- trunk/lib/WebPAC/Input.pm 2009/04/21 21:03:52 1128 +++ trunk/lib/WebPAC/Input.pm 2009/09/20 21:38:15 1304 @@ -3,7 +3,7 @@ use warnings; use strict; -use blib; +use lib 'lib'; use WebPAC::Common; use base qw/WebPAC::Common/; @@ -137,7 +137,7 @@ By default, C is assumed to be C. -C is optional parametar to position at some offset before reading from database. +C is optional parametar to skip records at beginning. C is optional parametar to read just C records from database @@ -183,7 +183,7 @@ # store data in object foreach my $v (qw/path offset limit/) { - $self->{$v} = $arg->{$v} if ($arg->{$v}); + $self->{$v} = $arg->{$v} if defined $arg->{$v}; } if ($arg->{load_row} || $arg->{save_row}) { @@ -230,6 +230,8 @@ my $class = $self->{module} || $log->logconfess("can't get low-level module name!"); + $arg->{$_} = $self->{$_} foreach qw(offset limit); + my $ll_db = $class->new( path => $arg->{path}, input_config => $arg->{input_config} || $self->{input_config}, @@ -243,6 +245,9 @@ %{ $arg }, ); + # save for dump and input_module + $self->{ll_db} = $ll_db; + unless (defined($ll_db)) { $log->logwarn("can't open database $arg->{path}, skipping..."); return; @@ -259,10 +264,10 @@ my $to_rec = $size; if (my $s = $self->{offset}) { - $log->debug("skipping to MFN $s"); - $from_rec = $s; + $log->debug("offset $s records"); + $from_rec = $s + 1; } else { - $self->{offset} = $from_rec; + $self->{offset} = $from_rec - 1; } if ($self->{limit}) { @@ -272,7 +277,7 @@ } # store size for later - $self->{size} = ($to_rec - $from_rec) ? ($to_rec - $from_rec + 1) : 0; + $self->{size} = $to_rec - $from_rec + 1; my $strict_encoding = $arg->{strict_encoding} || $self->{strict_encoding}; ## FIXME should be 1 really @@ -386,12 +391,11 @@ $self->{max_pos} = $to_rec; $log->debug("max_pos: $to_rec"); - # save for dump - $self->{ll_db} = $ll_db; - return $size; } +sub input_module { $_[0]->{ll_db} } + =head2 fetch Fetch next record from database. It will also displays progress bar. @@ -411,7 +415,7 @@ $log->logconfess("it seems that you didn't load database!") unless ($self->{pos}); if ($self->{pos} == -1) { - $self->{pos} = $self->{offset}; + $self->{pos} = $self->{offset} + 1; } else { $self->{pos}++; }