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