/[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 337 - (hide annotations)
Sat Dec 31 16:41:35 2005 UTC (18 years, 4 months ago) by dpavlin
File size: 1610 byte(s)
 r343@llin:  dpavlin | 2005-12-31 17:44:58 +0100
 fix clash of $self->{size} from WebPAC::Input and WebPAC::Input::MARC,
 dokument _marc_size property

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

  ViewVC Help
Powered by ViewVC 1.1.26