/[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 726 - (show annotations)
Fri Sep 29 19:52:17 2006 UTC (17 years, 6 months ago) by dpavlin
File size: 1847 byte(s)
 r1045@llin:  dpavlin | 2006-09-29 21:38:42 +0200
 change low-level API to be OO (and remove various ugly cludges).

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

  ViewVC Help
Powered by ViewVC 1.1.26