/[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

Contents of /trunk/lib/WebPAC/Input/MARC.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1110 - (show annotations)
Sat Sep 6 10:53:47 2008 UTC (15 years, 7 months ago) by dpavlin
File size: 2200 byte(s)
- version dependency on MARC::Fast is handled by Makefile.PL
- include_subfields in returned hash

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

  ViewVC Help
Powered by ViewVC 1.1.26