line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::MODS; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = "0.3"; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
42575
|
use Catmandu::Sane; |
|
3
|
|
|
|
|
205070
|
|
|
3
|
|
|
|
|
18
|
|
6
|
3
|
|
|
3
|
|
2932
|
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__ |