File: README

package info (click to toggle)
libmods-record-perl 0.13-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 220 kB
  • sloc: perl: 1,649; xml: 83; sh: 4; makefile: 2
file content (246 lines) | stat: -rw-r--r-- 7,228 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
NAME

    MODS::Record - Perl extension for handling MODS records

SYNOPSIS

     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 => '1234');
    
     $mods->add_abstract("Hello", lang => 'eng');
     $mods->add_abstract("Bonjour", lang => 'fra');
    
     # Set a deeply nested field...
     $mods->add_language()->add_languageTerm('eng');
    
     # Set a list of deeply nested fields...
     $mods->add_location(sub {
        $_[0]->add_physicalLocation('here');
        $_[0]->add_shelfLocator('here too');
        $_[0]->add_url('http://here.org/there');
     });
    
     # Set an inline XML extension...
     $mods->add_accessCondition(xml_string("<x:foo><x:bar>21212</x:bar></x:foo>"));
    
     # Retrieve a field by a filter...
     $mods->get_abstract(lang => 'fra')->body("Bonjour :)");
     $mods->get_abstract(lang => 'fra')->contentType('text/plain');
    
     for ($mods->get_abstract(lang => 'fra')) {
        printf "%s\n" , $_->body;
     }
    
     # Set a field to a new value
     my @newabstract;
     for ($mods->get_abstract) {
        push @newabstract, $_ unless $_->lang eq 'fra';
     }
     $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('mods.xml'));
     my $mods = MODS::Record->from_json(IO::File->new('mods.js'));
    
     my $count = MODS::Record->from_xml(IO::File->new('mods.xml'), sub {
        my $mods = shift;
        ...
     });
    
     my $count = MODS::Record->from_json(IO::File->new('mods.js'), sub {
        my $mods = shift;
        ...
     });

DESCRIPTION

    This module provides MODS (http://www.loc.gov/standards/mods/) parsing
    and creation for MODS Schema 3.5.

METHODS

 MODS::Record->new(%attribs)

 MODS::Collection->new(%attribs)

    Create a new MODS record or collection. Optionally attributes can be
    provided as defined by the MODS specification. E.g.

     $mods = MODS::Record->new(ID='123');

 add_xxx()

    Add a new element to the record where 'xxx' is the name of a MODS
    element (e.g. titleInfo, name, genre, etc). This method returns an
    instance of the added MODS element. E.g.

     $titleInfo = $mods->add_titleInfo; # $titleInfo is a 'MODS::Element::TitleInfo'

 add_xxx($text,%attribs)

    Add a new element to the record where 'xxx' is the name of a MODS
    element. Set the text content of the element to $text and optionally
    provide further attributes. This method returns an instance of the
    added MODS element. E.g.

     $mods->add_abstract("My abstract", lang=>'eng');

 add_xxx(sub { })

    Add a new element to the record where 'xxx' is the name of a MODS
    element. The provided coderef gets as input an instance of the added
    MODS element. This method returns an instance of the added MODS
    element. E.g.

     $mods->add_abstract(sub {
        my $o = shift;
        $o->body("My abstract");
        $o->lang("eng");
     })

 add_xxx($obj)

    Add a new element to the record where 'xxx' is the name of a MODS
    element. The $obj is an instance of a MODS::Element::Xxx class (where
    Xxx is the corresponding MODS element). This method returns an instance
    of the added MODS element. E.g.

     $mods->add_abstract(
         MODS::Element::Abstract->new(_body=>'My abstract', lang=>'eng')
     );

 get_xxx()

 get_xxx(%filter)

 get_xxx(sub { })

    Retrieve an element from the record where 'xxx' is the name of a MODS
    element. This methods return in array context all the matching elements
    or the first match in scalar context. Optionally provide a %filter or a
    coderef filter function. E.g.

     @titles = $mods->get_titleInfo();
     $alt    = $mods->get_titleInfo(type=>'alternate');
     $alt    = $mods->get_titleInfo(sub { shift->type eq 'alternate'});

 set_xxxx()

 set_xxx(undef)

 set_xxx($array_ref)

 set_xxx($xxx1,$xxx2,...)

    Set an element of the record to a new value where 'xxx' is the name of
    a MODS 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 ARRAY
    (ref) of MODS::Element::Xxx can be provided (where 'Xxx' is the
    corresponding MODS element). E.g.

     # 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(), ... ]);

 as_xml()

 as_xml(xml_prolog=>1)

    Return the record as XML.

 from_xml($string [, $callback])

 from_xml(IO::Handle [, $callback])

    Parse an XML string or IO::Handle into a MODS::Record. This method
    return the parsed JSON.

    If a callback function is provided then for each MODS element in the
    XML stream the callback will be called. The method returns the number
    of parsed MODS elements.

     E.g.
        my $mods = MODS::Record->from_xml( IO::File->new(...) );
    
        my $count = MODS::Record->from_xml( IO::File->new(...) , sub {
            my $mods = shift;
        } );

 as_json()

 as_json(pretty=>1)

    Return the record as JSON string.

 from_json($string [, $callback])

 from_json(IO::Handle [, $callback])

    Parse and JSON string or JSON::Handle into a MODS::Record. This method
    return the parsed JSON.

    If a callback function is provided then we expect as input a stream of
    JSON strings (each line one JSON string). For each MODS object in the
    JSON stream the callback will be called. The method returns the number
    of parsed strings.

     E.g.
        my $mods = MODS::Record->from_json( IO::File->new(...) );
    
        my $count = MODS::Record->from_json( IO::File->new(...) , sub {
            my $mods = shift;
        } );

SEE ALSO

      * Library Of Congress MODS pages (http://www.loc.gov/standards/mods/)

DESIGN NOTES

      * I'm not a MODS expert

      * I needed a MODS module to parse and create MODS records for our
      institutional repository

      * This module is part of the LibreCat/Catmandu project
      http://librecat.org

      * This module is not created for speed

      * This module doesn't have any notion of ordering of MODS elements
      themselves (e.g. first 'titleInfo', then 'name'). But each
      sub-element keeps its original order (e.g. each 'title' in
      'titleInfo').

      * Heiko Jansen provides at GitHub a Moose-based MODS parser
      https://github.com/heikojansen/MODS--Record

AUTHOR

    Patrick Hochstenbach <Patrick.Hochstenbach at UGent.be>

LICENSE AND COPYRIGHT

    This program is free software; you can redistribute it and/or modify it
    under the terms of either: the GNU General Public License as published
    by the Free Software Foundation; or the Artistic License.

    See http://dev.perl.org/licenses/ for more information.