/[webpac2]/trunk/lib/WebPAC/Input/MARC.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/MARC.pm

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

revision 307 by dpavlin, Tue Dec 20 00:03:04 2005 UTC revision 908 by dpavlin, Mon Oct 29 23:20:13 2007 UTC
# Line 3  package WebPAC::Input::MARC; Line 3  package WebPAC::Input::MARC;
3  use warnings;  use warnings;
4  use strict;  use strict;
5    
6  use MARC::Fast;  use MARC::Fast 0.03;
7    use base qw/WebPAC::Common/;
8    use Carp qw/confess/;
9    
10  =head1 NAME  =head1 NAME
11    
# Line 11  WebPAC::Input::MARC - support for MARC d Line 13  WebPAC::Input::MARC - support for MARC d
13    
14  =head1 VERSION  =head1 VERSION
15    
16  Version 0.02  Version 0.09
17    
18  =cut  =cut
19    
20  our $VERSION = '0.02';  our $VERSION = '0.09';
21    
22    
23  =head1 SYNOPSIS  =head1 SYNOPSIS
# Line 23  our $VERSION = '0.02'; Line 25  our $VERSION = '0.02';
25  Open USMARC, Unimarc or any other file format that has same internal  Open USMARC, Unimarc or any other file format that has same internal
26  structure using C<MARC::Fast>.  structure using C<MARC::Fast>.
27    
28   my $marc = new WebPAC::Input::MARC();   my $marc = new WebPAC::Input::MARC(
29   $marc->open( path => '/path/to/marc.iso' );          path => '/path/to/marc.iso'
30     );
31    
32  =head1 FUNCTIONS  =head1 FUNCTIONS
33    
34  =head2 open_db  =head2 new
35    
36  Returns handle to database  Returns new low-level input API object
37    
38    my $db = $open_db(    my $marc = new WebPAC::Input::MARC(
39          path => '/path/to/marc.iso'          path => '/path/to/marc.iso',
40            filter => \&code_ref,
41    }    }
42    
43  =cut  =cut
44    
45  sub open_db {  sub new {
46          my $self = shift;          my $class = shift;
47            my $self = {@_};
48            bless($self, $class);
49    
50          my $arg = {@_};          my $arg = {@_};
51    
# Line 47  sub open_db { Line 53  sub open_db {
53    
54          $log->info("opening MARC database '$arg->{path}'");          $log->info("opening MARC database '$arg->{path}'");
55    
56          my $db = new MARC::Fast( marcdb => $arg->{path});          my $db = new MARC::Fast(
57                    marcdb => $arg->{path},
58                    hash_filter => $arg->{filter},
59            );
60          my $db_size = $db->count - 1;   # FIXME          my $db_size = $db->count - 1;   # FIXME
61    
62          $self->{size} = $db_size;          $self->{_marc_size} = $db_size;
63            $self->{_marc_db} = $db;
64    
65          return ($db, $db_size);          $self ? return $self : return undef;
66  }  }
67    
68  =head2 fetch_rec  =head2 fetch_rec
69    
70  Return record with ID C<$mfn> from database  Return record with ID C<$mfn> from database
71    
72    my $rec = $self->fetch_rec( $db, $mfn );    my $rec = $self->fetch_rec( $mfn );
73    
74  }  }
75    
# Line 68  Return record with ID C<$mfn> from datab Line 78  Return record with ID C<$mfn> from datab
78  sub fetch_rec {  sub fetch_rec {
79          my $self = shift;          my $self = shift;
80    
81          my ($db, $mfn) = @_;          my $mfn = shift;
82    
83          if ($mfn > $self->{size}) {          if ($mfn > $self->{_marc_size}) {
84                  $self->_get_logger()->warn("seek beyond database size $self->{size} to $mfn");                  $self->_get_logger()->warn("seek beyond database size $self->{_marc_size} to $mfn");
85          } else {          } else {
86                  my $row = $db->fetch($mfn);                  my $marc = $self->{_marc_db} || confess "no _marc_db?";
87                    my $row = $marc->to_hash($mfn);
88                  push @{$row->{'000'}}, $mfn;                  push @{$row->{'000'}}, $mfn;
89                    push @{$row->{'leader'}}, $marc->last_leader;
90                  return $row;                  return $row;
91          }          }
92  }  }
93    
94    =head2 dump_ascii
95    
96    Return ASCII dump of record with ID C<$mfn> from database
97    
98      print $self->dump_ascii( $mfn );
99    
100    }
101    
102    =cut
103    
104    sub dump_ascii {
105            my $self = shift;
106    
107            my $mfn = shift;
108            return $self->{_marc_db}->to_ascii($mfn);
109    }
110    
111    =head2 size
112    
113    Return number of records in database
114    
115      my $size = $isis->size;
116    
117    =cut
118    
119    sub size {
120            my $self = shift;
121            return $self->{_marc_size};
122    }
123    
124    
125  =head1 AUTHOR  =head1 AUTHOR
126    
127  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>

Legend:
Removed from v.307  
changed lines
  Added in v.908

  ViewVC Help
Powered by ViewVC 1.1.26