Permalink
Browse files

Adding support for MODS

  • Loading branch information...
phochste committed Sep 22, 2015
1 parent 347bcc1 commit 7c94797504821a6a1fab8e4ab3e16dd0118c4480
View
@@ -1,7 +1,9 @@
Revision history for Catmandu-OAI
{{$NEXT}}
-
+ - Adding support for MODS
+ - Adding support for MARC collections
+
0.09 2015-08-17 14:50:39 CEST
- Fixing repeated last page bug #10
View
@@ -6,14 +6,16 @@ on 'test', sub {
requires 'Test::Exception','0.32';
};
-requires 'Catmandu', '0.9204';
-requires 'HTTP::OAI', '4.03';
-requires 'Moo', '1.0';
-requires 'XML::Struct', '0.18';
+requires 'Catmandu', '>=0.9';
+requires 'HTTP::OAI', '>=4.03';
+requires 'Moo', '>=1.0';
+requires 'XML::Struct', '>=0.18';
+requires 'MODS::Record', '>=0.11';
+requires 'IO::String', '0';
# Need recent SSL to talk to https endpoint correctly
-requires 'IO::Socket::SSL', '1.993';
+requires 'IO::Socket::SSL', '>=1.993';
feature 'xslt' => sub {
- requires 'Catmandu::XML', '0.15';
+ requires 'Catmandu::XML', '>=0.15';
};
@@ -30,6 +30,9 @@ sub _build_handler {
elsif ($self->metadataPrefix eq 'marcxml') {
return 'marcxml';
}
+ elsif ($self->metadataPrefix eq 'mods') {
+ return 'mods';
+ }
else {
return 'struct';
}
@@ -261,7 +264,8 @@ C<foobar> will create a C<Catmandu::Importer::OAI::Parser::foobar> instance.
By default the handler L<Catmandu::Importer::OAI::Parser::oai_dc> is used for
metadataPrefix C<oai_dc>, L<Catmandu::Importer::OAI::Parser::marcxml> for
-C<marcxml>, and L<Catmandu::Importer::OAI::Parser::struct> for other formats.
+C<marcxml>, L<Catmandu::Importer::OAI::Parser::mods> for
+C<mods>, and L<Catmandu::Importer::OAI::Parser::struct> for other formats.
In addition there is L<Catmandu::Importer::OAI::Parser::raw> to return the XML
as it is.
@@ -11,8 +11,13 @@ sub parse {
my @out;
my $id = undef;
+ # Read in the collection tag if available
+ if ($dom->localname eq 'collection') {
+ $dom = $dom->firstChild;
+ }
+
for my $field ($dom->getChildrenByLocalName('*')) {
- my $name = $field->localname;
+ my $name = $field->localname;
my $value = $field->textContent // '';
if ($name eq 'leader') {
push @out, [ 'LDR', ' ', ' ', '_', $value ];
@@ -0,0 +1,33 @@
+package Catmandu::Importer::OAI::Parser::mods;
+
+use Catmandu::Sane;
+use Moo;
+use MODS::Record;
+use Catmandu::Util;
+use JSON;
+
+with 'Catmandu::Logger';
+
+sub parse {
+ my ($self,$dom) = @_;
+
+ return undef unless defined $dom;
+
+ my $xml = $dom->toString;
+ my $perl = { error => 1 };
+
+ eval {
+ my $io = Catmandu::Util::io \$xml , mode => 'r', encoding => ':encoding(utf8)';
+ my $mods = MODS::Record->from_xml($io);
+ my $txt = $mods->as_json;
+ $perl = JSON::decode_json($mods->as_json);
+ };
+ if ($@) {
+ $self->log->error($@);
+ $self->log->error("Failed to parse: $xml");
+ }
+
+ { _metadata => $perl };
+}
+
+1;
@@ -2,7 +2,6 @@ package Catmandu::Importer::OAI::Parser::raw;
use Catmandu::Sane;
use Moo;
-use XML::Struct qw(readXML);
sub parse {
my ($self,$dom) = @_;

0 comments on commit 7c94797

Please sign in to comment.