/[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 652 - (hide annotations)
Thu Sep 7 15:01:45 2006 UTC (17 years, 8 months ago) by dpavlin
File size: 1736 byte(s)
refactored internal WebPAC::Input::* API a bit, added dump_rec,
validate is now more clever and reports all errors from database at end

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 289
8     =head1 NAME
9    
10     WebPAC::Input::MARC - support for MARC database files
11    
12     =head1 VERSION
13    
14 dpavlin 416 Version 0.05
15 dpavlin 289
16     =cut
17    
18 dpavlin 416 our $VERSION = '0.05';
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 dpavlin 497 Returns handle to database and size in records
34 dpavlin 289
35 dpavlin 497 my ($db,$size) = $open_db(
36 dpavlin 416 path => '/path/to/marc.iso',
37     filter => \&code_ref,
38 dpavlin 289 }
39    
40     =cut
41    
42     sub open_db {
43     my $self = shift;
44    
45     my $arg = {@_};
46    
47     my $log = $self->_get_logger();
48    
49     $log->info("opening MARC database '$arg->{path}'");
50    
51 dpavlin 416 my $db = new MARC::Fast(
52     marcdb => $arg->{path},
53     hash_filter => $arg->{filter},
54     );
55 dpavlin 290 my $db_size = $db->count - 1; # FIXME
56 dpavlin 289
57 dpavlin 337 $self->{_marc_size} = $db_size;
58 dpavlin 652 $self->{_marc_db} = $db;
59 dpavlin 290
60 dpavlin 289 return ($db, $db_size);
61     }
62    
63     =head2 fetch_rec
64    
65     Return record with ID C<$mfn> from database
66    
67 dpavlin 652 my $rec = $self->fetch_rec( $mfn );
68 dpavlin 289
69     }
70    
71     =cut
72    
73     sub fetch_rec {
74     my $self = shift;
75    
76 dpavlin 652 my $mfn = shift;
77 dpavlin 289
78 dpavlin 337 if ($mfn > $self->{_marc_size}) {
79     $self->_get_logger()->warn("seek beyond database size $self->{_marc_size} to $mfn");
80 dpavlin 290 } else {
81 dpavlin 652 my $row = $self->{_marc_db}->to_hash($mfn);
82 dpavlin 291 push @{$row->{'000'}}, $mfn;
83 dpavlin 290 return $row;
84     }
85 dpavlin 289 }
86    
87 dpavlin 337 =head1 PROPERTIES
88    
89     =head2 _marc_size
90    
91     Store size of MARC database
92    
93     print $self->{_marc_size};
94    
95    
96    
97 dpavlin 289 =head1 AUTHOR
98    
99     Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
100    
101     =head1 COPYRIGHT & LICENSE
102    
103     Copyright 2005 Dobrica Pavlinusic, All Rights Reserved.
104    
105     This program is free software; you can redistribute it and/or modify it
106     under the same terms as Perl itself.
107    
108     =cut
109    
110     1; # End of WebPAC::Input::MARC

  ViewVC Help
Powered by ViewVC 1.1.26