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::MIRruns 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 inMARC::MIRthan she ever was inMARC::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 π«Ά
- Marc Chantreux (eiro) marcc(at)cpan.org
- You? https://github.com/eiro/p5-marc-mir
KNOWN BUGS π
feedbacks are very welcome bestie, please. The only known bugs are:
with_fieldsneeds$_map_datafieldscan'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
- debian bookworm: libmarc-mir-perl 0.4-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmarc-mir-perl 0.4-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmarc-mir-perl 0.4-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmarc-mir-perl 0.4-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmarc-mir-perl 0.4-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms