Importer/PNX.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 64 CC 4 SCAR 20.8
CC
4
Cov
0%
generator
20.0
_build_pnx
2.0
BEGIN
2.0
CRAP 8.0
1 package Catmandu::Importer::PNX;
2  
3 use Catmandu::Sane;
4 use Catmandu::Util qw(:is);
5 use XML::LibXML::Reader;
6 use Catmandu::PNX;
7 use feature 'state';
8  
9 our $VERSION = '0.04';
10  
11 use Moo;
12 use namespace::clean;
13  
14 with 'Catmandu::Importer';
15  
16 has 'xpath' => (is => 'ro' , default => sub { '/oai:OAI-PMH/oai:ListRecords//oai:record/oai:metadata/*' });
17 has 'pnx' => (is => 'lazy');
18  
19 sub _build_pnx {
20 return Catmandu::PNX->new;
21 }
22  
23 sub generator {
24 my ($self) = @_;
25 $self->{encoding} = ':raw';
26 sub {
27 state $reader = XML::LibXML::Reader->new(IO => $self->fh);
28  
29 my $match = $reader->nextPatternMatch(
30 XML::LibXML::Pattern->new(
31 $self->xpath ,
32 { oai => 'http://www.openarchives.org/OAI/2.0/' }
33 )
34 );
35  
36 return undef unless $match == 1;
37  
38 my $xml = $reader->readOuterXml();
39  
40 $xml =~ s{xmlns="[^"]+"}{};
41  
42 return undef unless length $xml;
43  
44 $reader->nextSibling();
45  
46 my $data = $self->pnx->parse($xml);
47  
48 if (exists $data->{control} && exists $data->{control}->{sourcerecordid}) {
49 $data->{_id} = $data->{control}->{sourcerecordid};
50 }
51  
52 return $data;
53 };
54 }
55  
56 1;
57  
58 __END__