Importer/MARC.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 95.8% 46 / 48 CC 4 SCAR 6.4
CC
4
Cov
100%
BUILD
3.0
generator
2.0
BEGIN
1.0
CRAP 1.9
« Exporter/MARC/ISO.pm ↑ Summary Fix/marc_in_json.pm »
1 package Catmandu::Importer::MARC;
2 42 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 42 ▶use Catmandu::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 42 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 38 our $VERSION = '1.33';
7  
8 1 ▶has type => (is => 'ro' , default => sub { 'ISO' });
Subroutine __ANON__: called CC=1 SCAR=0.0
9 38 has skip_errors => (is => 'ro');
10 38 has _importer => (is => 'ro');
11  
12 38 with 'Catmandu::Importer';
13  
14 202 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.0
Pod undocumented
15 202 my ($self,$args) = @_;
16  
17 202 my $type = $self->type;
18  
19 # keep USMARC temporary as alias for ISO, remove in future version
20 # print deprecation warning
21 202 ▶ if ($type eq 'USMARC') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "USMARC") 1 201 202
22 1 $type = 'ISO';
23 1 warn( "deprecated", "Oops! Importer \"USMARC\" is deprecated. Use \"ISO\" instead." );
24 }
25  
26 202 ▶ if (exists $args->{records}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"records"}) 1 201 202
27 1 $type = 'Record';
28 }
29  
30 202 my $pkg = Catmandu::Util::require_package($type,'Catmandu::Importer::MARC');
31  
32 202 delete $args->{file};
33 202 delete $args->{type};
34 202 delete $args->{fix};
35  
36 202 $self->{_importer} = $pkg->new(file => $self->file, %$args);
37 }
38  
39 202 ▶sub generator {
Subroutine generator: called CC=2 SCAR=6.9
Pod undocumented
40 206 my ($self) = @_;
41  
42 206 ▶ if ($self->skip_errors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->skip_errors) { } 1 201 202
43 5 my $gen = $self->_importer->generator;
44 5 my $nr = 0;
45 sub {
46 my $item = 0;
47 do {
48 $nr++;
49 try {
50 $item = $gen->();
51 } catch {
52 $self->log->error("error at record $nr : $_");
53 };
54 } while (defined($item) && $item == 0);
55 $item;
56 5 };
57 }
58 else {
59 205 $self->_importer->generator;
60 }
61 }
62  
63 38 1;
64 __END__
« Exporter/MARC/ISO.pm ↑ Summary Fix/marc_in_json.pm »