NAME
MARC::File::MARCMaker -- Work with MARCMaker/MARCBreaker records.
SYNOPSIS
use MARC::File::MARCMaker;
my $file = MARC::File::MARCMaker->in( $filename );
while ( my $marc = $file->next() ) {
# Do something
}
$file->close();
undef $file;
####################################################
use MARC::File::MARCMaker;
## reading with MARC::Batch
my $batch = MARC::Batch->new( 'MARCMaker', $filename );
my $record = $batch->next();
## or reading with MARC::File::MARCMaker explicitly
my $file = MARC::File::MARCMaker->in( $filename );
my $record = $file->next();
## output a single MARC::Record object in MARCMaker format (formatted plain text)
#print $record->as_marcmaker(); #goal syntax
print MARC::File::MARCMaker->encode($record); #current syntax
DESCRIPTION
The MARC-File-MARCMaker distribution is an extension to the MARC-Record distribution for working with MARC21 data using the format used by the Library of Congress MARCMaker and MARCBreaker programs.
More information may be obtained here: http://www.loc.gov/marc/makrbrkr.html
You must have MARC::Record installed to use MARC::File::MARCMaker. In fact once you install the MARC-File-MARCMaker distribution you will most likely not use it directly, but will have an additional file format available to you when you use MARC::Batch.
This module is based on code from the original MARC.pm module, as well as the MARC::Record distribution's MARC::File::USMARC and MARC::File::MicroLIF modules.
DEVIATIONS FROM LC'S DOCUMENTATION
LC's MARCMaker/MARCBreaker programs require files to have DOS line endings. This module should be capable of reading any type of line ending. It converts existing endings to "\n", the endings of the platform.
Initial version may or may not work well with line breaks in the middle of a field.
MARCMaker version of the LDR (record size bytes) will not necessarily be dependable, and should not be relied upon.
EXPORT
None.
TODO
Do limit tests in filling the buffer and getting chunks. Seems to work for first fill, but may fail on larger reads/multiple reads to fill the buffer.
Test special characters (those requiring escapes). Initial version may not fully support non-English characters. All MARC-8 may work, Unicode support is untested and unassured.
Implement better character encoding and decoding, including Unicode support.
Work on character set internal subs for both input and output. Currently, the original subs from MARC.pm are being used essentially as-is.
Error checking for line breaks vs. new fields? Probably not possible, since line breaks are allowed within fields, so checking for missing equals sign is not really possible.
Account for multiple occurences of =LDR in a single record, usually caused by lack of blank line between records, so records get mushed together. Also check for multiple =001s.
Determine why the constant SUBFIELD_INDICATOR can't be used in the split into subfields.
Work on encode().
Allow as_marcmaker() to be called with either MARC::Field or MARC::Record objects, returning the appropriate result. Desired behavior is as_usmarc() methods in MARC::Record and MARC::Field
Decode should mostly be working. Test for correctness.
Remove unnecessary code and documentation, remnants of the initial development of the module. Move internal subs to end of module?
VERSION HISTORY
Version 0.05: First CPAN release, Oct. 30, 2005.
Version 0.04: Updated Oct. 22, 2005. Released Oct. 23, 2005.
-Initial commit to CVS on SourceForge
-Misc. cleanup.
Version 0.03: Updated Aug. 2, 2005. Released Aug. 14, 2005.
-Revised decode() to fix problem with dollar sign conversion from mnemonics to characters.
Version 0.02: Updated July 12-13, 2005. Released July 16, 2005.
-Preliminary version of encode() for fields and records
Version 0.01: Initial version, Nov. 21, 2004-Mar. 7, 2005. Released Mar. 7, 2005.
-Basic version, translates .mrk format file into MARC::Record objects.
############################################################
This section is copied from MARC::File::MicroLIF.
############################################################
The buffer must be large enough to handle any valid record because we don't check for cases like a CR/LF pair or an end-of-record/CR/LF trio being only partially in the buffer.
The max valid record is the max MARC record size (99999) plus one or two characters per tag (CR, LF, or CR/LF). It's hard to say what the max number of tags is, so here we use 6000. (6000 tags can be squeezed into a MARC record only if every tag has only one subfield containing a maximum of one character, or if data from multiple tags overlaps in the MARC record body. We're pretty safe.)
METHODS
_next (merged from MicroLIF and USMARC)
Called by MARC::File::next().
decode( $string [, \&filter_func ] )
(description based on MARC::File::USMARC::decode POD information)
Constructor for handling data from a MARCMaker file. This function takes care of all the tag directory parsing & mangling.
Any warnings or coercions can be checked in the warnings()
function.
The $filter_func
is an optional reference to a user-supplied function that determines on a tag-by-tag basis if you want the tag passed to it to be put into the MARC record. The function is passed the tag number and the raw tag data, and must return a boolean. The return of a true value tells MARC::File::MARCMaker::decode that the tag should get put into the resulting MARC record.
For example, if you only want title and subject tags in your MARC record, try this:
sub filter {
my ($tagno,$tagdata) = @_;
return ($tagno == 245) || ($tagno >= 600 && $tagno <= 699);
}
my $marc = MARC::File::MARCMaker->decode( $string, \&filter );
Why would you want to do such a thing? The big reason is that creating fields is processor-intensive, and if your program is doing read-only data analysis and needs to be as fast as possible, you can save time by not creating fields that you'll be ignoring anyway.
Another possible use is if you're only interested in printing certain tags from the record, then you can filter them when you read from disc and not have to delete unwanted tags yourself.
update_leader() #from USMARC
This may be unnecessary code. Delete this section if that is the case.
If any changes get made to the MARC record, the first 5 bytes of the leader (the length) will be invalid. This function updates the leader with the correct length of the record as it would be if written out to a file.
sub update_leader() { #from USMARC my $self = shift;
my (undef,undef,$reclen,$baseaddress) = $self->_build_tag_directory();
$self->_set_leader_lengths( $reclen, $baseaddress );
} #updated_leader() from USMARC
encode() #based on MARC::File::USMARC
Returns a string of characters suitable for writing out to a MARCMaker file, including the leader, directory and all the fields.
Uses as_marcmaker() below to build each field.
as_marcmaker()
Based on MARC::Field::as_usmarc(). Turns a MARC::Field into a MARCMaker formatted field string.
TODO (as_marcmaker())
-Change field encoding portion of as_marcmaker() to internal _as_marcmaker()
-Implement as_marcmaker() as wrapper for MARC::Record object and MARC::Field object encoding into MARCMaker format.
_get_chunk( ) #for MARCMaker
Gets the next chunk of data (which should be a single complete record).
All extra \r and \n are stripped and line endings are converted to those of the platform (\n).
_unget_chunk ( ) #done for MARCMaker?
$chunk is put at the beginning of the buffer followed
by two line endings ("\n\n") as a record separator.
I don't know that this sub is necessary.
_char2maker
Pass in string of characters from a MARC record and a character map ($charset, or usmarc_default() by default). Returns string of characters encoded in MARCMaker format. (e.g. replaces '$' with {dollar})
Default charset
usmarc_default() -- Originally from MARC.pm. Offers default mnemonics for character encoding and decoding.
Used by _maker2char.
This perhaps should be an internal _usmarc_default().
ustext_default
ustext_default -- Originally from MARC.pm. Offers default mnemonics for character encoding and decoding.
Used by _char2maker.
This perhaps should be an internal _ustext_default().
_maker2char default
_maker2char() -- Translates MARCMaker encoded character into MARC-8 character.
RELATED MODULES
SEE ALSO
http://www.loc.gov/marc/makrbrkr.html for more information about the DOS-based MARCMaker and MARCBreaker programs.
The methods in this MARCMaker module are based upon MARC::File::USMARC.pm and MARC::File::MicroLIF.pm. Those are distributed with MARC::Record. The underlying code is based on the MARCMaker-related methods in MARC.pm.
LICENSE
This code may be distributed under the same terms as Perl itself.
Please note that this module is not a product of or supported by the employers of the various contributors to the code.
AUTHOR
Bryan Baldus eijabb@cpan.org
Copyright (c) 2004-2005.