| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catmandu::Importer::MODS; |
|
2
|
|
|
|
|
|
|
our $VERSION = "0.1"; |
|
3
|
3
|
|
|
3
|
|
83776
|
use Catmandu::Sane; |
|
|
3
|
|
|
|
|
398722
|
|
|
|
3
|
|
|
|
|
22
|
|
|
4
|
3
|
|
|
3
|
|
3823
|
use Catmandu::Util qw(:is :array :check); |
|
|
3
|
|
|
|
|
194146
|
|
|
|
3
|
|
|
|
|
2343
|
|
|
5
|
3
|
|
|
3
|
|
4431
|
use MODS::Record; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moo; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has type => ( |
|
11
|
|
|
|
|
|
|
is => 'ro', |
|
12
|
|
|
|
|
|
|
isa => sub { |
|
13
|
|
|
|
|
|
|
my $t = $_[0]; |
|
14
|
|
|
|
|
|
|
is_string($t) && array_includes([qw(xml json)],$t) || die("type must be 'xml' or 'json'"); |
|
15
|
|
|
|
|
|
|
}, |
|
16
|
|
|
|
|
|
|
default => sub { 'xml'; }, |
|
17
|
|
|
|
|
|
|
lazy => 1 |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub generator { |
|
21
|
|
|
|
|
|
|
my($self) = @_; |
|
22
|
|
|
|
|
|
|
sub { |
|
23
|
|
|
|
|
|
|
state $i = 0; |
|
24
|
|
|
|
|
|
|
#result: MODS::Record::Mods or MODS::Record::ModsCollection |
|
25
|
|
|
|
|
|
|
state $mods = do { |
|
26
|
|
|
|
|
|
|
#MODS::Record->from_json expects binary input (decode_json is applied) |
|
27
|
|
|
|
|
|
|
if($self->type eq "json"){ |
|
28
|
|
|
|
|
|
|
$self->fh->binmode(":raw"); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
my $m = $self->type eq "xml" ? MODS::Record->from_xml($self->fh) : MODS::Record->from_json($self->fh); |
|
31
|
|
|
|
|
|
|
my $res = ref($m) eq "MODS::Element::Mods" ? [$m] : $m->mods; |
|
32
|
|
|
|
|
|
|
$res; |
|
33
|
|
|
|
|
|
|
}; |
|
34
|
|
|
|
|
|
|
return $i < scalar(@$mods) ? $mods->[$i++] : undef; |
|
35
|
|
|
|
|
|
|
}; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 NAME |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Catmandu::Importer::MODS - Catmandu Importer for importing mods records |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
use Catmandu::Importer::MODS; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $importer = Catmandu::Importer::MODS->new(file => "modsCollection.xml",type => "xml"); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $numModsElements = $importer->each(sub{ |
|
49
|
|
|
|
|
|
|
#$modsElement is a MODS::Element::Mods object |
|
50
|
|
|
|
|
|
|
my $modsElement = shift; |
|
51
|
|
|
|
|
|
|
}); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
MODS can be expressed in either XML or JSON. XML is the more common way to express. |
|
56
|
|
|
|
|
|
|
This module reads from a file, and iterates over the elements 'mods'. In case |
|
57
|
|
|
|
|
|
|
of a simple mods document, only one element is found. In case of a 'modsCollection', |
|
58
|
|
|
|
|
|
|
several mods elements can be found. |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
These files SHOULD be expressed in UTF-8. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 METHODS |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 Catmandu::Importer::MODS->new(file => "mods.xml",type => "xml") |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Creates a new importer. 'file' can anything that can be transformed into |
|
67
|
|
|
|
|
|
|
an IO::Handle by Catmandu::Util::io. See http://search.cpan.org/~nics/Catmandu-0.5004/lib/Catmandu/Util.pm for more information. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
'type' can only be 'json' or 'xml'. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 each(sub{ .. }) |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
The importer transforms the input 'file' into an array of L. |
|
74
|
|
|
|
|
|
|
This method iterates over that list, and supplies the callback with one |
|
75
|
|
|
|
|
|
|
MODS::Element::Mods at a time. |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=over 4 |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item * L |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item * Library Of Congress MODS pages (http://www.loc.gov/standards/mods/) |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=back |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 DESIGN NOTES |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=over 4 |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item * This module is part of the LibreCat/Catmandu project http://librecat.org |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item * Make sure your files are expressed in UTF-8. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=back |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 AUTHORS |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over 4 |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item * Nicolas Franck |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=back |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 LICENSE |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This library is free software and may be distributed under the same terms |
|
108
|
|
|
|
|
|
|
as perl itself. See L. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |