small fixes : opac lib is the same as librarian lib by default.
[koha.git] / marc / File.pm
1 package MARC::File;
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 =head1 NAME
22
23 MARC::File - Base class for files of MARC records
24
25 =cut
26
27 use 5.6.0;
28 use strict;
29 use integer;
30 use vars qw( $VERSION $ERROR );
31
32 # FIXME - Fix the POD to conform to Perl style. In particular,
33 # functions get an =item, not a =head2.
34
35 =head1 VERSION
36
37 Version 0.93
38
39     $Id$
40
41 =cut
42
43 our $VERSION = '0.93';
44
45 =head1 SYNOPSIS
46
47     use MARC::File::USMARC;
48
49     my $file = MARC::File::USMARC->in( $filename );
50     
51     while ( my $marc = $file->next() ) {
52         # Do something
53     }
54     $file->close();
55     undef $file;
56
57 =head1 EXPORT
58
59 None.  
60
61 =head1 METHODS
62
63 =head2 in()
64
65 Opens a file for input.
66
67 =cut
68
69 sub in {
70     my $class = shift;
71     my $filename = shift;
72
73     my $self = {
74         filename => $filename,
75     };
76
77     bless $self, $class;
78
79     if ( !open( $self->{fh}, "<", $filename ) ) {
80         undef $self;
81         $MARC::File::ERROR = "Couldn't open $filename: $!";
82     }
83
84     return $self;
85 } # new()
86
87 sub indata {
88     my $class = shift;
89     my $data = shift;
90
91     my $self = {
92         fh => '',
93         data => $data,
94         pointer => 0,
95     };
96
97     bless $self, $class;
98
99 #    if ( !open( $self->{fh}, "<", $filename ) ) {
100 #       undef $self;
101 #       $MARC::File::ERROR = "Couldn't open $filename: $!";
102 #    }
103
104     return $self;
105 } # new()
106
107 sub out {
108     die "Not yet written";
109 }
110
111 =head2 next()
112
113 Reads the next record from the file handle passed in.
114
115 =cut
116
117 sub next {
118     my $self = shift;
119
120     my $rec = $self->_next();
121
122     return $rec ? $self->decode($rec) : undef;
123 }
124
125 =head2 skip
126
127 Skips over the next record in the file.  Same as C<next()>,
128 without the overhead of parsing a record you're going to throw away
129 anyway.
130
131 Returns 1 or undef.
132
133 =cut
134
135 sub skip {
136     my $self = shift;
137
138     my $rec = $self->_next();
139
140     return $rec ? 1 : undef;
141 }
142
143 sub close {
144     my $self = shift;
145
146     close( $self->{fh} );
147     delete $self->{fh};
148
149     return;
150 }
151
152 sub _unimplemented() {
153     my $self = shift;
154     my $method = shift;
155
156     warn "Method $method must be overridden";
157 }
158
159 sub write   { $_[0]->_unimplemented("write"); }
160 sub decode  { $_[0]->_unimplemented("decode"); }
161
162 # NOTE: _gripe can be called as an object method, or not.  Your choice.
163 sub _gripe(@) {
164     if ( @_ ) {
165         shift if ref($_[0]) =~ /^MARC::File/;   # Skip first parm if it's a $self
166         $ERROR = join( "", @_ );
167     }
168
169     return undef;
170 }
171
172 1;
173
174 __END__
175
176 =head1 RELATED MODULES
177
178 L<MARC::Record>
179
180 =head1 TODO
181
182 =over 4
183
184 =item * C<out()> method
185
186 We only handle files for input right now.
187
188 =back
189
190 =cut
191
192 =head1 LICENSE
193
194 This code may be distributed under the same terms as Perl itself. 
195
196 Please note that these modules are not products of or supported by the
197 employers of the various contributors to the code.
198
199 =head1 AUTHOR
200
201 Andy Lester, E<lt>marc@petdance.comE<gt> or E<lt>alester@flr.follett.comE<gt>
202
203 =cut
204