MARC::File(3pm)

πŸ“¦
version 2.0.7 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

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

okay so. this is MARC::File, and it lives in the User Contributed Perl Documentation corner of the perl world. it's the base class for files of MARC records β€” like, the mom of all the file classes. she doesn't do much herself but everything else inherits her vibe. 🫢


✨ NAME ✨

MARC::File β€” literally just the base class for files of MARC records. that's the whole personality. πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

use MARC::File::USMARC;

# If you have weird control fields...
use MARC::Field;
MARC::Field->allow_controlfield_tags('FMT', 'LDX');

my $file = MARC::File::USMARC->in( $filename );

while ( my $marc = $file->next() ) {
    # Do something
}
$file->close();
undef $file;

see how clean that is?? we love a loop that just reads records until there are none left and then closes up shop. main character energy fr fr. πŸ’…


🌸 EXPORT 🌸

None. not a single thing. she's not exporting anything, she's minding her own business. ✨


πŸŽ€ METHODS πŸŽ€

πŸ’œ in()

Opens a file up for import. real talk: you're usually not calling this on MARC::File directly β€” you'd reach for MARC::File::USMARC or MARC::File::MicroLIF to do the actual work.

my $file = MARC::File::USMARC->in( 'file.marc' );

She hands you back a MARC::File object, or undef if it went sideways. and if something DID go wrong, the error message is chilling in $MARC::File::ERROR. 😭

Optional lil bonus: you can also pass in a filehandle, and MARC::File will "do the right thing". she just gets it, iykyk.

my $handle = IO::File->new( 'gunzip -c file.marc.gz |' );
my $file = MARC::File::USMARC->in( $handle );

🧚 next( [\&filter_func] )

Reads the next record off the filehandle you passed in. ✨

The $filter_func is a reference to a filtering function. heads up though: currently only USMARC records support this. for the deets, go look at MARC::File::USMARC's decode() function. πŸ‘€

Returns a MARC::Record reference, or undef if there's an error.

πŸ’… skip()

Skips right over the next record in the file. it's the same as next(), except you skip the whole ~parsing~ thing β€” because why do all that work on a record you're gonna throw away anyway? efficiency slay. πŸ”₯

Returns 1 or undef.

🌈 warnings()

similar to the methods in MARC::Record and MARC::Batch, warnings() returns any warnings that have piled up while processing this file. and as a lil side-effect β€” plot twist β€” it clears the warnings buffer. so read 'em while you got 'em bestie. πŸ’€

πŸ“ close()

Closes the file. both from the object's point of view and the actual file. she shuts it down all the way, no loose ends. periodt. πŸ’–

⭐ write()

Writes a record to the output file. this method must be overridden in your subclass β€” she's not writing it for you, you gotta bring your own. 🫢

🌸 decode()

Decodes a record into a USMARC format. same deal: this method must be overridden in your subclass. do it yourself, bestie. πŸ’œ


MARC::Record


🌈 TODO 🌈

  • out() method

okay so right now we only handle files for input. output is still on the vision board. πŸ¦‹


πŸ’– LICENSE πŸ’–

This code may be distributed under the same terms as Perl itself.

Please note that these modules are not products of or supported by the employers of the various contributors to the code.


✨ AUTHOR ✨

Andy Lester, <andy@petdance.com>


and that's the whole page!! πŸ’… this doc shipped with perl v5.36.0, dated 2022-10-13, and it came to you from the User Contributed Perl Documentation crew. tysm for reading, mwah, go read some MARC records. πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from