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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 772 - (hide annotations)
Fri Nov 3 20:40:38 2006 UTC (17 years, 6 months ago) by dpavlin
File size: 2064 byte(s)
 r1124@llin:  dpavlin | 2006-11-03 21:39:00 +0100
 use MARC::Fast 0.05 to_ascii to implement dump_rec

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

  ViewVC Help
Powered by ViewVC 1.1.26