--- trunk/lib/WebPAC/Input/ISIS.pm 2005/07/17 21:04:23 20 +++ trunk/lib/WebPAC/Input/ISIS.pm 2005/07/17 22:28:11 21 @@ -62,7 +62,8 @@ If optional parametar C is set, it will read just 500 records from database in example above. -Returns number of last record read into memory (size of database, really). +Returns size of database, regardless of C and C +parametars, see also C<$isis->size>. =cut @@ -78,10 +79,10 @@ $log->logdie("can't find database ",$arg->{'filename'}) unless (glob($arg->{'filename'}.'.*')); # store data in object - $self->{'isis_filename'} = $arg->{'filename'}; $self->{'isis_code_page'} = $code_page; - - #$self->{'isis_code_page'} = $code_page; + foreach my $v (qw/isis_filename start_mfn limit_mfn/) { + $self->{$v} = $arg->{$v} if ($arg->{$v}); + } # create Text::Iconv object my $cp = Text::Iconv->new($code_page,$self->{'code_page'}); @@ -89,12 +90,12 @@ $log->info("reading ISIS database '",$arg->{'filename'},"'"); $log->debug("isis code page: $code_page"); - my ($isis_db,$maxmfn); + my ($isis_db,$db_size); if ($have_openisis) { $log->debug("using OpenIsis perl bindings"); $isis_db = OpenIsis::open($arg->{'filename'}); - $maxmfn = OpenIsis::maxRowid( $isis_db ) || 1; + $db_size = OpenIsis::maxRowid( $isis_db ) || 1; } elsif ($have_biblio_isis) { $log->debug("using Biblio::Isis"); use Biblio::Isis; @@ -107,9 +108,9 @@ return $l; }, ); - $maxmfn = $isis_db->count; + $db_size = $isis_db->count; - unless ($maxmfn) { + unless ($db_size) { $log->logwarn("no records in database ", $arg->{'filename'}, ", skipping..."); return; } @@ -120,6 +121,7 @@ my $startmfn = 1; + my $maxmfn = $db_size; if (my $s = $self->{'start_mfn'}) { $log->info("skipping to MFN $s"); @@ -128,7 +130,14 @@ $self->{'start_mfn'} = $startmfn; } - $maxmfn = $startmfn + $self->{limit_mfn} if ($self->{limit_mfn}); + if ($self->{limit_mfn}) { + $log->info("limiting to ",$self->{limit_mfn}," records"); + $maxmfn = $startmfn + $self->{limit_mfn} - 1; + $maxmfn = $db_size if ($maxmfn > $db_size); + } + + # store size for later + $self->{'size'} = ($maxmfn - $startmfn) ? ($maxmfn - $startmfn + 1) : 0; $log->info("processing ",($maxmfn-$startmfn)." records using ",( $have_openisis ? 'OpenIsis' : 'Biblio::Isis')); @@ -194,7 +203,9 @@ $log->debug("max mfn: $maxmfn"); # store max mfn and return it. - return $self->{'max_mfn'} = $maxmfn; + $self->{'max_mfn'} = $maxmfn; + + return $db_size; } =head2 fetch @@ -260,11 +271,17 @@ print $isis->size; +Result from this function can be used to loop through all records + + foreach my $mfn ( 1 ... $isis->size ) { ... } + +because it takes into account C and C. + =cut sub size { my $self = shift; - return $self->{'max_mfn'}; + return $self->{'size'}; } =head2 seek