| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catmandu::Importer::MODS; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = "0.2"; |
|
4
|
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
47769
|
use Catmandu::Sane; |
|
|
3
|
|
|
|
|
233489
|
|
|
|
3
|
|
|
|
|
16
|
|
|
6
|
3
|
|
|
3
|
|
2731
|
use MODS::Record; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Moo; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has type => ( |
|
12
|
|
|
|
|
|
|
is => 'ro', |
|
13
|
|
|
|
|
|
|
isa => sub { |
|
14
|
|
|
|
|
|
|
die "type must be 'xml' or 'json'" unless grep { $_[0] eq $_ } qw(xml json); |
|
15
|
|
|
|
|
|
|
}, |
|
16
|
|
|
|
|
|
|
lazy => 1, |
|
17
|
|
|
|
|
|
|
builder => sub { |
|
18
|
|
|
|
|
|
|
($_[0]->file and $_[0]->file =~ /\.json$/) ? 'json' : 'xml'; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub generator { |
|
23
|
|
|
|
|
|
|
my ($self) = @_; |
|
24
|
|
|
|
|
|
|
sub { |
|
25
|
|
|
|
|
|
|
state $i = 0; |
|
26
|
|
|
|
|
|
|
#result: MODS::Record::Mods or MODS::Record::ModsCollection |
|
27
|
|
|
|
|
|
|
state $mods = do { |
|
28
|
|
|
|
|
|
|
#MODS::Record->from_json expects binary input (decode_json is applied) |
|
29
|
|
|
|
|
|
|
# if($self->type eq "json"){ |
|
30
|
|
|
|
|
|
|
# $self->fh->binmode(":raw"); |
|
31
|
|
|
|
|
|
|
# } |
|
32
|
|
|
|
|
|
|
my $m = $self->type eq "xml" ? MODS::Record->from_xml($self->fh) : MODS::Record->from_json($self->fh); |
|
33
|
|
|
|
|
|
|
my $res = ref($m) eq "MODS::Element::Mods" ? [$m] : $m->mods; |
|
34
|
|
|
|
|
|
|
$res; |
|
35
|
|
|
|
|
|
|
}; |
|
36
|
|
|
|
|
|
|
return $i < scalar(@$mods) ? $mods->[$i++] : undef; |
|
37
|
|
|
|
|
|
|
}; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
|
41
|
|
|
|
|
|
|
__END__ |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Catmandu::Importer::MODS - Catmandu Importer for importing mods records |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use Catmandu::Importer::MODS; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $importer = Catmandu::Importer::MODS->new(file => "modsCollection.xml"); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $numModsElements = $importer->each(sub{ |
|
54
|
|
|
|
|
|
|
my $modsElement = shift; # a MODS::Element::Mods object |
|
55
|
|
|
|
|
|
|
}); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
This L<Catmandu::Importer> reads MODS records to be processed with L<Catmandu>. |
|
60
|
|
|
|
|
|
|
In case of a simple "mods" document, one L<MODS::Element::Mods> item is |
|
61
|
|
|
|
|
|
|
imported. In case of a "modsCollection", several items are imported. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
See L<Catmandu::Importer>, L<Catmandu::Iterable>, L<Catmandu::Logger> and |
|
64
|
|
|
|
|
|
|
L<Catmandu::Fixable> for methods and options derived from these modules. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Make sure your files are expressed in UTF-8. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=over |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item type |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Set to C<xml> by default, as MODS is usually expressed in XML. Use C<json> (or |
|
75
|
|
|
|
|
|
|
provide a file with extension C<.json>) for a custom JSON format, introduced in |
|
76
|
|
|
|
|
|
|
module L<MODS::Record>. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=back |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
See L<Catmandu::MODS> for more information about MODS and Catmandu. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |