MARC::...RCMaker(3pm)

πŸ“¦
version 0.05 Β· 4 versions
, in debian bookworm, ubuntu noble

πŸ’– MARC::File::MARCMaker β€” bestie edition πŸ’–

okay so this is the page for MARC::File::MARCMaker(3pm), straight outta the User Contributed Perl Documentation section, and we're gonna go through the whole thing together because you deserve to understand it. no skipping. periodt.

✨ NAME ✨

MARC::File::MARCMaker β€” Work with MARCMaker/MARCBreaker records. that's the whole vibe. πŸ’…


🌸 SYNOPSIS 🌸

here's how you actually use it, bestie:

    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

like, look at that second half. the as_marcmaker() line is the dream (goal syntax, it's giving aspirational ✨) and the encode() line is what you can actually run today. iykyk.


πŸ¦‹ DESCRIPTION πŸ¦‹

so the MARC-File-MARCMaker distribution is an extension to the MARC-Record distribution, and its whole job is working with MARC21 data using the format from the Library of Congress MARCMaker and MARCBreaker programs. iconic honestly.

more info lives here: <http://www.loc.gov/marc/makrbrkr.html>

you must have MARC::Record installed to use MARC::File::MARCMaker. and lowkey? once you install the MARC-File-MARCMaker distribution you'll most likely not use it directly at all β€” instead you just get a bonus file format available to you whenever you use MARC::Batch. it's the gift that keeps giving 🎁

this module is based on code from the original MARC.pm module, plus the MARC::Record distribution's MARC::File::USMARC and MARC::File::MicroLIF modules. ancestry, but make it perl.

πŸ’€ 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. flexible queen πŸ‘‘
  • initial version may or may not work well with line breaks in the middle of a field. (not me being honest about it 😭)
  • the MARCMaker version of the LDR (record size bytes) will not necessarily be dependable, and should not be relied upon. do not trust it. fr fr.

πŸŽ€ EXPORT πŸŽ€

None. nothing. zero. empty. it exports nothing and that's on purpose. πŸ™ˆ


πŸ”₯ TODO πŸ”₯

the whole to-do list, and yes we're doing all of it because no details get left behind:

  • 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?

so much ambition. we love to see it. ⭐


🌈 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.

and then, direct from the source, a whole block that says:

############################################################
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.)

okay that math is unhinged but it checks out and we respect it 🫢


🧚 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. the heavy lifting. the main character energy πŸ’…

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.

basically: skip the work you don't need. efficiency slay. ⚑

update_leader() #from USMARC

This may be unnecessary code. Delete this section if that is the case. (brutal. honest. love that for us.)

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. (mood, honestly 😭)

_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.


MARC::Record

MARC.pm


⭐ SEE ALSO ⭐

MARC::File

<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.


and that's the whole page bestie, we read every single line, no skimming, no cap. shoutout to perl v5.36.0 and the date 2022-11-19 on the manual footer β€” that's the version and timestamp this lil page was rendered with, so if you're on something newer, well, slay, and stay curious πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from