--- trunk/lib/WebPAC/Input/MARC.pm 2005/12/20 19:01:27 309 +++ trunk/lib/WebPAC/Input/MARC.pm 2007/10/29 23:20:13 908 @@ -3,7 +3,9 @@ use warnings; use strict; -use MARC::Fast; +use MARC::Fast 0.03; +use base qw/WebPAC::Common/; +use Carp qw/confess/; =head1 NAME @@ -11,11 +13,11 @@ =head1 VERSION -Version 0.03 +Version 0.09 =cut -our $VERSION = '0.03'; +our $VERSION = '0.09'; =head1 SYNOPSIS @@ -23,23 +25,27 @@ Open USMARC, Unimarc or any other file format that has same internal structure using C. - my $marc = new WebPAC::Input::MARC(); - $marc->open( path => '/path/to/marc.iso' ); + my $marc = new WebPAC::Input::MARC( + path => '/path/to/marc.iso' + ); =head1 FUNCTIONS -=head2 open_db +=head2 new -Returns handle to database +Returns new low-level input API object - my $db = $open_db( - path => '/path/to/marc.iso' + my $marc = new WebPAC::Input::MARC( + path => '/path/to/marc.iso', + filter => \&code_ref, } =cut -sub open_db { - my $self = shift; +sub new { + my $class = shift; + my $self = {@_}; + bless($self, $class); my $arg = {@_}; @@ -47,19 +53,23 @@ $log->info("opening MARC database '$arg->{path}'"); - my $db = new MARC::Fast( marcdb => $arg->{path}); + my $db = new MARC::Fast( + marcdb => $arg->{path}, + hash_filter => $arg->{filter}, + ); my $db_size = $db->count - 1; # FIXME - $self->{size} = $db_size; + $self->{_marc_size} = $db_size; + $self->{_marc_db} = $db; - return ($db, $db_size); + $self ? return $self : return undef; } =head2 fetch_rec Return record with ID C<$mfn> from database - my $rec = $self->fetch_rec( $db, $mfn ); + my $rec = $self->fetch_rec( $mfn ); } @@ -68,17 +78,50 @@ sub fetch_rec { my $self = shift; - my ($db, $mfn) = @_; + my $mfn = shift; - if ($mfn > $self->{size}) { - $self->_get_logger()->warn("seek beyond database size $self->{size} to $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); + my $marc = $self->{_marc_db} || confess "no _marc_db?"; + my $row = $marc->to_hash($mfn); push @{$row->{'000'}}, $mfn; + push @{$row->{'leader'}}, $marc->last_leader; return $row; } } +=head2 dump_ascii + +Return ASCII dump of record with ID C<$mfn> from database + + print $self->dump_ascii( $mfn ); + +} + +=cut + +sub dump_ascii { + my $self = shift; + + my $mfn = shift; + return $self->{_marc_db}->to_ascii($mfn); +} + +=head2 size + +Return number of records in database + + my $size = $isis->size; + +=cut + +sub size { + my $self = shift; + return $self->{_marc_size}; +} + + =head1 AUTHOR Dobrica Pavlinusic, C<< >>