File Coverage

blib/lib/Catmandu/AlephX/Op/PublishAvail.pm
Criterion Covered Total %
statement 15 32 46.8
branch 0 2 0.0
condition n/a
subroutine 5 7 71.4
pod 0 2 0.0
total 20 43 46.5


line stmt bran cond sub pod time code
1             package Catmandu::AlephX::Op::PublishAvail;
2 1     1   102616 use Catmandu::Sane;
  1         191435  
  1         8  
3 1     1   329 use Catmandu::Util qw(:check);
  1         2  
  1         305  
4 1     1   488 use Catmandu::AlephX::Metadata::MARC;
  1         3  
  1         34  
5 1     1   415 use Catmandu::AlephX::Record;
  1         2  
  1         30  
6 1     1   7 use Moo;
  1         2  
  1         3  
7              
8             our $VERSION = "1.072";
9              
10             with('Catmandu::AlephX::Response');
11              
12             #format: [ { _id => <id>, record => <doc>}, .. ]
13             #<doc> has extra tag in marc array called 'AVA'
14             has records => (
15             is => 'ro',
16             isa => sub { check_array_ref($_[0]); }
17             );
18 0     0 0   sub op { 'publish-avail' }
19              
20             sub parse {
21 0     0 0   my($class,$str_ref) = @_;
22 0           my $xpath = xpath($str_ref);
23              
24 0           $xpath->registerNs(oai => "http://www.openarchives.org/OAI/2.0/");
25 0           $xpath->registerNs(marc => "http://www.loc.gov/MARC21/slim");
26              
27 0           my $op = op();
28 0           my @records;
29              
30 0           for my $record($xpath->find("/$op/oai:OAI-PMH/oai:ListRecords/oai:record")->get_nodelist()){
31              
32 0           my $identifier = $record->findvalue("./*[local-name() = 'header']/*[local-name()='identifier']");
33 0           $identifier =~ s/aleph-publish://o;
34              
35 0           my($record) = $record->find("./*[local-name()='metadata']/*[local-name() = 'record']")->get_nodelist();
36 0 0         if($record){
37             #remove controlfield with tag 'FMT' and 'LDR' because Catmandu::Importer::MARC cannot handle these
38 0           my $m = Catmandu::AlephX::Metadata::MARC->parse($record);
39 0           $m->{_id} = $identifier;
40 0           push @records,Catmandu::AlephX::Record->new(metadata => $m);
41             }else{
42 0           push @records,Catmandu::AlephX::Record->new(
43             metadata => Catmandu::AlephX::Metadata::MARC->new(
44             data => { _id => $identifier }, type => "oai_marc"
45             )
46             );
47             }
48             }
49              
50             __PACKAGE__->new(
51 0           errors => $class->parse_errors($xpath),
52             session_id => $xpath->findvalue("/$op/session-id"),
53             records => \@records,
54             content_ref => $str_ref
55             );
56             }
57              
58             1;