1 |
package WebPAC::Input::MARC; |
2 |
|
3 |
use warnings; |
4 |
use strict; |
5 |
|
6 |
use blib; |
7 |
|
8 |
use WebPAC::Common; |
9 |
use MARC::Fast; |
10 |
|
11 |
=head1 NAME |
12 |
|
13 |
WebPAC::Input::MARC - support for MARC database files |
14 |
|
15 |
=head1 VERSION |
16 |
|
17 |
Version 0.01 |
18 |
|
19 |
=cut |
20 |
|
21 |
our $VERSION = '0.01'; |
22 |
|
23 |
|
24 |
=head1 SYNOPSIS |
25 |
|
26 |
Open USMARC, Unimarc or any other file format that has same internal |
27 |
structure using C<MARC::Fast>. |
28 |
|
29 |
my $marc = new WebPAC::Input::MARC(); |
30 |
$marc->open( path => '/path/to/marc.iso' ); |
31 |
|
32 |
=head1 FUNCTIONS |
33 |
|
34 |
=head2 open_db |
35 |
|
36 |
Returns handle to database |
37 |
|
38 |
my $db = $open_db( |
39 |
path => '/path/to/marc.iso' |
40 |
} |
41 |
|
42 |
=cut |
43 |
|
44 |
sub open_db { |
45 |
my $self = shift; |
46 |
|
47 |
my $arg = {@_}; |
48 |
|
49 |
my $log = $self->_get_logger(); |
50 |
|
51 |
$log->info("opening MARC database '$arg->{path}'"); |
52 |
|
53 |
my $db = new MARC::Fast( marcdb => $arg->{path}); |
54 |
my $db_size = $db->count - 1; # FIXME |
55 |
|
56 |
$self->{size} = $db_size; |
57 |
|
58 |
return ($db, $db_size); |
59 |
} |
60 |
|
61 |
=head2 fetch_rec |
62 |
|
63 |
Return record with ID C<$mfn> from database |
64 |
|
65 |
my $rec = $self->fetch_rec( $db, $mfn ); |
66 |
|
67 |
} |
68 |
|
69 |
=cut |
70 |
|
71 |
sub fetch_rec { |
72 |
my $self = shift; |
73 |
|
74 |
my ($db, $mfn) = @_; |
75 |
|
76 |
if ($mfn > $self->{size}) { |
77 |
$self->_get_logger()->warn("seek beyond database size $self->{size} to $mfn"); |
78 |
} else { |
79 |
my $row = $db->fetch($mfn); |
80 |
push @{$row->{'000'}}, $mfn; |
81 |
return $row; |
82 |
} |
83 |
} |
84 |
|
85 |
=head1 AUTHOR |
86 |
|
87 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
88 |
|
89 |
=head1 COPYRIGHT & LICENSE |
90 |
|
91 |
Copyright 2005 Dobrica Pavlinusic, All Rights Reserved. |
92 |
|
93 |
This program is free software; you can redistribute it and/or modify it |
94 |
under the same terms as Perl itself. |
95 |
|
96 |
=cut |
97 |
|
98 |
1; # End of WebPAC::Input::MARC |