line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::MODS; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = "0.31"; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
64406
|
use Catmandu::Sane; |
|
3
|
|
|
|
|
667837
|
|
|
3
|
|
|
|
|
20
|
|
6
|
3
|
|
|
3
|
|
4199
|
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
|
|
|
|
|
|
|
#starting from version 0.11 of MODS::Record utf8 is enabled by issuing JSON->new->utf8(1) |
29
|
|
|
|
|
|
|
if($MODS::Record::VERSION >= 0.11){ |
30
|
|
|
|
|
|
|
if($self->type eq "json"){ |
31
|
|
|
|
|
|
|
$self->fh->binmode(":raw"); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
#before version 0.11 of MODS::Record, decoding needed to be done yourself |
35
|
|
|
|
|
|
|
else{ |
36
|
|
|
|
|
|
|
if($self->type eq "json"){ |
37
|
|
|
|
|
|
|
$self->fh->binmode(':utf8'); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
my $m = $self->type eq "xml" ? MODS::Record->from_xml($self->fh) : MODS::Record->from_json($self->fh); |
41
|
|
|
|
|
|
|
my $res = ref($m) eq "MODS::Element::Mods" ? [$m] : $m->mods; |
42
|
|
|
|
|
|
|
$res; |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
return $i < scalar(@$mods) ? $mods->[$i++] : undef; |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
__END__ |