r494@llin: dpavlin | 2006-02-27 00:22:59 +0100
[webpac2] / lib / WebPAC / Input / MARC.pm
index fdcce36..a4f3cbf 100644 (file)
@@ -3,10 +3,7 @@ package WebPAC::Input::MARC;
 use warnings;
 use strict;
 
-use blib;
-
-use WebPAC::Common;
-use MARC::Fast;
+use MARC::Fast 0.03;
 
 =head1 NAME
 
@@ -14,11 +11,11 @@ WebPAC::Input::MARC - support for MARC database files
 
 =head1 VERSION
 
-Version 0.01
+Version 0.05
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.05';
 
 
 =head1 SYNOPSIS
@@ -36,7 +33,8 @@ structure using C<MARC::Fast>.
 Returns handle to database
 
   my $db = $open_db(
-       path => '/path/to/marc.iso'
+       path => '/path/to/marc.iso',
+       filter => \&code_ref,
   }
 
 =cut
@@ -50,8 +48,13 @@ sub open_db {
 
        $log->info("opening MARC database '$arg->{path}'");
 
-       my $db = new MARC::Fast( marcdb => $arg->{path});
-       my $db_size = $db->count;
+       my $db = new MARC::Fast(
+               marcdb => $arg->{path},
+               hash_filter => $arg->{filter},
+       );
+       my $db_size = $db->count - 1;   # FIXME
+
+       $self->{_marc_size} = $db_size;
 
        return ($db, $db_size);
 }
@@ -71,9 +74,25 @@ sub fetch_rec {
 
        my ($db, $mfn) = @_;
 
-       return $db->fetch($mfn);
+       if ($mfn > $self->{_marc_size}) {
+               $self->_get_logger()->warn("seek beyond database size $self->{_marc_size} to $mfn");
+       } else {
+               my $row = $db->to_hash($mfn);
+               push @{$row->{'000'}}, $mfn;
+               return $row;
+       }
 }
 
+=head1 PROPERTIES
+
+=head2 _marc_size
+
+Store size of MARC database
+
+  print $self->{_marc_size};
+
+
+
 =head1 AUTHOR
 
 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>