/[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 908 - (hide annotations)
Mon Oct 29 23:20:13 2007 UTC (16 years, 6 months ago) by dpavlin
File size: 2187 byte(s)
leader from WebPAC::Input::MARC is now available as rec('leader')

for mondifications within leader, use substr(rec('leader'),from,to)
instead of proposed leader(field,nr) syntax

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

  ViewVC Help
Powered by ViewVC 1.1.26