1 | package MARC::File::MicroLIF;
|
---|
2 |
|
---|
3 | =head1 NAME
|
---|
4 |
|
---|
5 | MARC::File::MicroLIF - MicroLIF-specific file handling
|
---|
6 |
|
---|
7 | =cut
|
---|
8 |
|
---|
9 | use strict;
|
---|
10 | use integer;
|
---|
11 | eval 'use warnings' if $] >= 5.006;
|
---|
12 |
|
---|
13 | use vars qw( $ERROR );
|
---|
14 |
|
---|
15 | =head1 VERSION
|
---|
16 |
|
---|
17 | Version 1.10
|
---|
18 |
|
---|
19 | $Id: MicroLIF.pm 3430 2002-09-24 05:17:39Z jrm21 $
|
---|
20 |
|
---|
21 | =cut
|
---|
22 |
|
---|
23 | use vars '$VERSION'; $VERSION = '1.10';
|
---|
24 |
|
---|
25 | use MARC::File;
|
---|
26 | use vars qw( @ISA ); @ISA = qw( MARC::File );
|
---|
27 |
|
---|
28 | use 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 |
|
---|
44 | None.
|
---|
45 |
|
---|
46 | =head1 METHODS
|
---|
47 |
|
---|
48 | =cut
|
---|
49 |
|
---|
50 | sub _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 |
|
---|
62 | sub 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 |
|
---|
100 | 1;
|
---|
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 |
|
---|
114 | L<MARC::File>
|
---|
115 |
|
---|
116 | =head1 LICENSE
|
---|
117 |
|
---|
118 | This code may be distributed under the same terms as Perl itself.
|
---|
119 |
|
---|
120 | Please note that these modules are not products of or supported by the
|
---|
121 | employers of the various contributors to the code.
|
---|
122 |
|
---|
123 | =head1 AUTHOR
|
---|
124 |
|
---|
125 | Andy Lester, E<lt>[email protected]<gt> or E<lt>[email protected]<gt>
|
---|
126 |
|
---|
127 | =cut
|
---|
128 |
|
---|