.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "MODS::Record 3pm"
.TH MODS::Record 3pm "2022-11-29" "perl v5.36.0" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
MODS::Record \- Perl extension for handling MODS records
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 2
\& use MODS::Record qw(xml_string);
\& use open qw(:utf8);
\&
\& my $mods = MODS::Record\->new;
\&
\& my $collection = MODS::Collection\->new;
\&
\& my $mods = $collection\->add_mods(ID => \*(Aq1234\*(Aq);
\&
\& $mods\->add_abstract("Hello", lang => \*(Aqeng\*(Aq);
\& $mods\->add_abstract("Bonjour", lang => \*(Aqfra\*(Aq);
\&
\& # Set a deeply nested field...
\& $mods\->add_language()\->add_languageTerm(\*(Aqeng\*(Aq);
\&
\& # Set a list of deeply nested fields...
\& $mods\->add_location(sub {
\& $_[0]\->add_physicalLocation(\*(Aqhere\*(Aq);
\& $_[0]\->add_shelfLocator(\*(Aqhere too\*(Aq);
\& $_[0]\->add_url(\*(Aqhttp://here.org/there\*(Aq);
\& });
\&
\& # Set an inline XML extension...
\& $mods\->add_accessCondition(xml_string("21212"));
\&
\& # Retrieve a field by a filter...
\& $mods\->get_abstract(lang => \*(Aqfra\*(Aq)\->body("Bonjour :)");
\& $mods\->get_abstract(lang => \*(Aqfra\*(Aq)\->contentType(\*(Aqtext/plain\*(Aq);
\&
\& for ($mods\->get_abstract(lang => \*(Aqfra\*(Aq)) {
\& printf "%s\en" , $_\->body;
\& }
\&
\& # Set a field to a new value
\& my @newabstract;
\& for ($mods\->get_abstract) {
\& push @newabstract, $_ unless $_\->lang eq \*(Aqfra\*(Aq;
\& }
\& $mods\->set_abstract(@newabstract);
\&
\& # Clear all abstracts;
\& $mods\->set_abstract(undef);
\&
\& # Serialize
\& print $mods\->as_json(pretty => 1);
\& print $mods\->as_xml;
\&
\& # Deserialize
\& my $mods = MODS::Record\->from_xml(IO::File\->new(\*(Aqmods.xml\*(Aq));
\& my $mods = MODS::Record\->from_json(IO::File\->new(\*(Aqmods.js\*(Aq));
\&
\& my $count = MODS::Record\->from_xml(IO::File\->new(\*(Aqmods.xml\*(Aq), sub {
\& my $mods = shift;
\& ...
\& });
\&
\& my $count = MODS::Record\->from_json(IO::File\->new(\*(Aqmods.js\*(Aq), sub {
\& my $mods = shift;
\& ...
\& });
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This module provides \s-1MODS\s0 (http://www.loc.gov/standards/mods/) parsing and creation for \s-1MODS\s0 Schema 3.5.
.SH "METHODS"
.IX Header "METHODS"
.SS "MODS::Record\->new(%attribs)"
.IX Subsection "MODS::Record->new(%attribs)"
.SS "MODS::Collection\->new(%attribs)"
.IX Subsection "MODS::Collection->new(%attribs)"
Create a new \s-1MODS\s0 record or collection. Optionally attributes can be provided as
defined by the \s-1MODS\s0 specification. E.g.
.PP
.Vb 1
\& $mods = MODS::Record\->new(ID=\*(Aq123\*(Aq);
.Ve
.SS "\fBadd_xxx()\fP"
.IX Subsection "add_xxx()"
Add a new element to the record where 'xxx' is the name of a \s-1MODS\s0 element (e.g. titleInfo, name, genre, etc).
This method returns an instance of the added \s-1MODS\s0 element. E.g.
.PP
.Vb 1
\& $titleInfo = $mods\->add_titleInfo; # $titleInfo is a \*(AqMODS::Element::TitleInfo\*(Aq
.Ve
.SS "add_xxx($text,%attribs)"
.IX Subsection "add_xxx($text,%attribs)"
Add a new element to the record where 'xxx' is the name of a \s-1MODS\s0 element. Set the text content of the element to \f(CW$text\fR
and optionally provide further attributes. This method returns an instance of the added \s-1MODS\s0 element. E.g.
.PP
.Vb 1
\& $mods\->add_abstract("My abstract", lang=>\*(Aqeng\*(Aq);
.Ve
.SS "add_xxx(sub { })"
.IX Subsection "add_xxx(sub { })"
Add a new element to the record where 'xxx' is the name of a \s-1MODS\s0 element. The provided coderef gets as input an instance
of the added \s-1MODS\s0 element. This method returns an instance of the added \s-1MODS\s0 element. E.g.
.PP
.Vb 5
\& $mods\->add_abstract(sub {
\& my $o = shift;
\& $o\->body("My abstract");
\& $o\->lang("eng");
\& })
.Ve
.SS "add_xxx($obj)"
.IX Subsection "add_xxx($obj)"
Add a new element to the record where 'xxx' is the name of a \s-1MODS\s0 element. The \f(CW$obj\fR is an instance of a MODS::Element::Xxx
class (where Xxx is the corresponding \s-1MODS\s0 element). This method returns an instance of the added \s-1MODS\s0 element. E.g.
.PP
.Vb 3
\& $mods\->add_abstract(
\& MODS::Element::Abstract\->new(_body=>\*(AqMy abstract\*(Aq, lang=>\*(Aqeng\*(Aq)
\& );
.Ve
.SS "\fBget_xxx()\fP"
.IX Subsection "get_xxx()"
.SS "get_xxx(%filter)"
.IX Subsection "get_xxx(%filter)"
.SS "get_xxx(sub { })"
.IX Subsection "get_xxx(sub { })"
Retrieve an element from the record where 'xxx' is the name of a \s-1MODS\s0 element. This methods return in array context all the
matching elements or the first match in scalar context. Optionally provide a \f(CW%filter\fR or a coderef filter function.
E.g.
.PP
.Vb 3
\& @titles = $mods\->get_titleInfo();
\& $alt = $mods\->get_titleInfo(type=>\*(Aqalternate\*(Aq);
\& $alt = $mods\->get_titleInfo(sub { shift\->type eq \*(Aqalternate\*(Aq});
.Ve
.SS "\fBset_xxxx()\fP"
.IX Subsection "set_xxxx()"
.SS "set_xxx(undef)"
.IX Subsection "set_xxx(undef)"
.SS "set_xxx($array_ref)"
.IX Subsection "set_xxx($array_ref)"
.SS "set_xxx($xxx1,$xxx2,...)"
.IX Subsection "set_xxx($xxx1,$xxx2,...)"
Set an element of the record to a new value where 'xxx' is the name of a \s-1MODS\s0 element. When no arguments are provided, then this
is a null operation. When undef als argument is provided, then the element is deleted. To overwrite the existing content of the
element an \s-1ARRAY\s0 (ref) of MODS::Element::Xxx can be provided (where 'Xxx' is the corresponding \s-1MODS\s0 element). E.g.
.PP
.Vb 2
\& # Delete all abstracts
\& $mods\->set_abstract(undef);
\&
\& # Set all abstracts
\& $mods\->set_abstract(MODS::Element::Abstract\->new(), MODS::Element::Abstract\->new(), ...);
\& $mods\->set_abstract([ MODS::Element::Abstract\->new(), MODS::Element::Abstract\->new(), ... ]);
.Ve
.SS "\fBas_xml()\fP"
.IX Subsection "as_xml()"
.SS "as_xml(xml_prolog=>1)"
.IX Subsection "as_xml(xml_prolog=>1)"
Return the record as \s-1XML.\s0
.ie n .SS "from_xml($string [, $callback])"
.el .SS "from_xml($string [, \f(CW$callback\fP])"
.IX Subsection "from_xml($string [, $callback])"
.ie n .SS "from_xml(IO::Handle [, $callback])"
.el .SS "from_xml(IO::Handle [, \f(CW$callback\fP])"
.IX Subsection "from_xml(IO::Handle [, $callback])"
Parse an \s-1XML\s0 string or IO::Handle into a MODS::Record. This method return the parsed \s-1JSON.\s0
.PP
If a callback function is provided then for each \s-1MODS\s0 element in the \s-1XML\s0 stream the callback will be called.
The method returns the number of parsed \s-1MODS\s0 elements.
.PP
.Vb 2
\& E.g.
\& my $mods = MODS::Record\->from_xml( IO::File\->new(...) );
\&
\& my $count = MODS::Record\->from_xml( IO::File\->new(...) , sub {
\& my $mods = shift;
\& } );
.Ve
.SS "\fBas_json()\fP"
.IX Subsection "as_json()"
.SS "as_json(pretty=>1)"
.IX Subsection "as_json(pretty=>1)"
Return the record as \s-1JSON\s0 string.
.ie n .SS "from_json($string [, $callback])"
.el .SS "from_json($string [, \f(CW$callback\fP])"
.IX Subsection "from_json($string [, $callback])"
.ie n .SS "from_json(IO::Handle [, $callback])"
.el .SS "from_json(IO::Handle [, \f(CW$callback\fP])"
.IX Subsection "from_json(IO::Handle [, $callback])"
Parse and \s-1JSON\s0 string or JSON::Handle into a MODS::Record. This method return the parsed \s-1JSON.\s0
.PP
If a callback function is provided then we expect as input a stream of \s-1JSON\s0 strings
(each line one \s-1JSON\s0 string). For each \s-1MODS\s0 object in the \s-1JSON\s0 stream the callback will be called.
The method returns the number of parsed strings.
.PP
.Vb 2
\& E.g.
\& my $mods = MODS::Record\->from_json( IO::File\->new(...) );
\&
\& my $count = MODS::Record\->from_json( IO::File\->new(...) , sub {
\& my $mods = shift;
\& } );
.Ve
.SH "SEE ALSO"
.IX Header "SEE ALSO"
.IP "\(bu" 4
Library Of Congress \s-1MODS\s0 pages (http://www.loc.gov/standards/mods/)
.SH "DESIGN NOTES"
.IX Header "DESIGN NOTES"
.IP "\(bu" 4
I'm not a \s-1MODS\s0 expert
.IP "\(bu" 4
I needed a \s-1MODS\s0 module to parse and create \s-1MODS\s0 records for our institutional repository
.IP "\(bu" 4
This module is part of the LibreCat/Catmandu project http://librecat.org
.IP "\(bu" 4
This module is not created for speed
.IP "\(bu" 4
This module doesn't have any notion of ordering of \s-1MODS\s0 elements themselves (e.g. first 'titleInfo', then 'name').
But each sub-element keeps its original order (e.g. each 'title' in 'titleInfo').
.IP "\(bu" 4
Heiko Jansen provides at GitHub a Moose-based \s-1MODS\s0 parser https://github.com/heikojansen/MODS\*(--Record
.SH "AUTHOR"
.IX Header "AUTHOR"
Patrick Hochstenbach
.SH "LICENSE AND COPYRIGHT"
.IX Header "LICENSE AND COPYRIGHT"
This program is free software; you can redistribute it and/or modify it
under the terms of either: the \s-1GNU\s0 General Public License as published
by the Free Software Foundation; or the Artistic License.
.PP
See for more information.