source: trunk/gsdl/perllib/cpan/MARC/File/MicroLIF.pm@ 3430

Last change on this file since 3430 was 3430, checked in by jrm21, 22 years ago

Added MARCPlug, mostly done by David Bainbridge. It needs a configuration file,
which maps MARC fields into metadata, which is in gsdlhome/etc/marctodc.txt

  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1package MARC::File::MicroLIF;
2
3=head1 NAME
4
5MARC::File::MicroLIF - MicroLIF-specific file handling
6
7=cut
8
9use strict;
10use integer;
11eval 'use warnings' if $] >= 5.006;
12
13use vars qw( $ERROR );
14
15=head1 VERSION
16
17Version 1.10
18
19 $Id: MicroLIF.pm 3430 2002-09-24 05:17:39Z jrm21 $
20
21=cut
22
23use vars '$VERSION'; $VERSION = '1.10';
24
25use MARC::File;
26use vars qw( @ISA ); @ISA = qw( MARC::File );
27
28use MARC::Record qw( LEADER_LEN );
29
30=head1 SYNOPSIS
31
32 use MARC::File::MicroLIF;
33
34 my $file = MARC::File::MicroLIF::in( $filename );
35
36 while ( my $marc = $file->next() ) {
37 # Do something
38 }
39 $file->close();
40 undef $file;
41
42=head1 EXPORT
43
44None.
45
46=head1 METHODS
47
48=cut
49
50sub _next {
51 my $self = shift;
52
53 my $fh = $self->{fh};
54
55 local $/ = "`\n";
56
57 my $lifrec = <$fh>;
58
59 return $lifrec;
60}
61
62sub decode {
63 my $text = shift;
64 $text = shift if (ref($text)||$text) =~ /^MARC::File/; # Handle being called as a method
65
66 my $marc = MARC::Record->new();
67
68 my @lines = split( /\n/, $text );
69 for my $line ( @lines ) {
70 # Ignore the file header if the calling program hasn't already dealt with it
71 next if $line =~ /^HDR/;
72
73 ($line =~ s/^(\d\d\d|LDR)//) or
74 return $marc->_gripe( "Invalid tag number: ", substr( $line, 0, 3 ) );
75 my $tagno = $1;
76
77 ($line =~ s/\^$//) or $marc->_warn( "Tag $tagno is missing a trailing caret." );
78
79 if ( $tagno eq "LDR" ) {
80 $marc->leader( substr( $line, 0, LEADER_LEN ) );
81 } elsif ( $tagno < 10 ) {
82 $marc->add_fields( $tagno, $line );
83 } else {
84 $line =~ s/^(.)(.)//;
85 my ($ind1,$ind2) = ($1,$2);
86 my @subfields;
87 my @subfield_data_pairs = split( /_(?=[a-z0-9])/, $line );
88 shift @subfield_data_pairs; # Leading _ makes an empty pair
89 for my $pair ( @subfield_data_pairs ) {
90 my ($subfield,$data) = (substr( $pair, 0, 1 ), substr( $pair, 1 ));
91 push( @subfields, $subfield, $data );
92 }
93 $marc->add_fields( $tagno, $ind1, $ind2, @subfields );
94 }
95 } # for
96
97 return $marc;
98}
99
1001;
101
102__END__
103
104=head1 TODO
105
106=over 4
107
108=item * Squawks about the final field missing a caret
109
110=back
111
112=head1 RELATED MODULES
113
114L<MARC::File>
115
116=head1 LICENSE
117
118This code may be distributed under the same terms as Perl itself.
119
120Please note that these modules are not products of or supported by the
121employers of the various contributors to the code.
122
123=head1 AUTHOR
124
125Andy Lester, E<lt>[email protected]<gt> or E<lt>[email protected]<gt>
126
127=cut
128
Note: See TracBrowser for help on using the repository browser.