MARC::MIR(3pm)

✨ MARC::MIR πŸ’…

okay bestie, welcome to MARC::MIR, a Perl thing that lives in the User Contributed Perl Documentation corner of your system, and which is not a library. No cap. It's a specification. Let's get into it. πŸ¦‹


NAME 🌸

MIR::MARC β€” it's an Intermediate Representation, periodt.


DESCRIPTION πŸ’–

So here's the tea: MARC::MIR is not a library. It's a specification for an in-memory representation of a MARC record, and the whole vibe is simplicity. But this module still ships with a little set of helpers so you can actually do stuff with it β€” she calls that set of helpers the MARC::MIR DSL. πŸŽ€

And the DSL is designed to be used in the most natural way possible, like genuinely. Here are some basic examples (combined with Perlude):

use Modern::Perl;
use MARC::MIR;
use Perlude;

# marcdump

now {say for_humans from_iso2709} iso2709_records_of 'source.mrc'

# report the IDs of the 10 first records of the file

now {
    any_fields {
        tag eq '001' and say value
    } from_iso2709
} take 10, iso2709_records_of 'echantillon_ecparis.raw';

# or

now {
    $_ = from_iso2709;
    any_fields {
        tag eq '001' and say value
    }
} take 10, iso2709_records_of 'echantillon_ecparis.raw';

There are also some other modules and docs that are worth reading, so:

NAME 🧚

MARC::MIR::Template β€” it's a description format, used to import/export a MIR from/to data structures that fit modern formats like JSON or XML. (Those ship separately, iykyk.)

NAME πŸ‘‘

MARC::MIR::Tutorial β€” it gives you basic examples of how to use the MARC::MIR DSL that's described right down below. 🌈


WARNINGS πŸ’€

Okay so, full honesty hour: t/* is empty 😭 and the API may change. (Though she does say she thinks it's pretty quiet stable on the basics. And she thinks the doc is up to date, and so is the stability of MARC::MIR.)

Anyway: while we're all waiting for the tests, MARC::MIR runs daily on linux stations (perl 5.12 to 5.17) on large amounts of data. It's as faster and easier to use as the older libraries, and it's designed to get your data back from iso files no matter the quality of the serialization dictionary β€” so for one-shot scripts, she is now more confident in MARC::MIR than she ever was in MARC::Record, for example. 🫢

MOTIVATION 🌸

She dealt with a lot of MARC records in the past (mainly from/to iso2709 files) and was genuinely so annoyed by the state of the art:

ISO2709 was a clever format when it was invented (more than 40 years ago! older than FTP or even UNIX) but the world has changed in such a drastic way that most of the IT crowd β€” bred on modern serialization formats like YAML, JSON, XML β€” are clueless when it comes to magnetic-tape-friendly serializations. Librarians haven't got it since recently. πŸ™ˆ

As a result, IT people just flee libraries and reinvent information sciences from scratch with modern tools fitting the modern interconnected world, while librarians are left with the rest of us: dead bored programmers using old school tools and badly designed modules with a painful OO approach. She doesn't blame anyone β€” it's just the way things went.

But if you come back to the roots: a MARC record is a very simple structure, so it must be simple to manipulate. MARC::MIR is an attempt to get the simplicity back. ✨


SPECIFICATION πŸ’…

So MIR is just an array of array (peep man perllol) with very simple rules:

record       = [ header, [fields] ]
fields       = controlfield | datafield
controlfield = [tag,string]
datafield    = [tag,[subfields],indicators]
indicators   = [ ind1, ind2 ] # can be represented as a 2 chars fields
subfields    = [tag,string]

note that tags are always at the index 0, and data always at 1. 🎯

And all the indexes that the spec doesn't use? Free real estate, bestie β€” you can use them to store instructions for middleware and serializer purposes. There's no convention there.

Examples πŸ¦‹

A MIR control field is a tag and a value:

[ '001', '1231313145' ]

A MIR data field:

[ $tag, [@subfield] ]
[ $tag, [@subfield], "  " ]
[ $tag, [@subfield], [' ',' '] ]

A MIR record:

[ '01972cam0a2200541   450' =>
    [ [ '001' => '2344564564' ] # this is the ID
    ,   [ '856'
        , [ [ q => "jpeg" ]
          , [ z => "cover from original version" ]
          , [ u => "http://localhost/img/" ]
          ]
        ]
    ]
]

DSL 🌈

Using $_ and the "(_)" prototype is idiomatic here β€” almost every sub is written to be used in a very natural way (her hope is that librarians write some code πŸ₯Ί). So we prefer to write:

say for_humans from_iso2709

instead of the more pythonic way:

say( for_humans( from_iso2709( $_ )))

map_*, with_*, any_*, grep_* πŸŽ€

# TODO: maybe an array there ?

tag, value, indicators πŸ‘‘

ISO2709 handling ⭐

# TODO: from|to_iso2709

CIB handling 🌸

# TODO: from|to_iso2709

Authors 🫢


KNOWN BUGS 😭

feedbacks are very welcome bestie, please. The only known bugs are:

  • with_fields needs $_
  • map_datafields can't work
  • *_values? must crash on references

πŸ’– and that's the whole page, you ate πŸ’–

This was MARC::MIR(3pm) from perl v5.36.0, dated 2023-02-09 β€” go forth and slay your iso2709 files, periodt. πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from