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