Importer/MARC/MiJ.pm

filter: Statementstmt 100% 26 / 26 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 94.5% 35 / 37 CC 2 SCAR 2.0
CC
2
Cov
96%
generator
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Importer/MARC/MARCMaker.pm ↑ Summary Importer/MARC/Lint.pm »
1 =head1 NAME
2  
3 Catmandu::Importer::MARC::MiJ - Package that imports MARC-in-JSON records
4  
5 =head1 SYNOPSIS
6  
7 # From the command line
8 $ catmandu convert MARC --type MiJ --fix "marc_map('245a','title')" < /foo/bar.json
9  
10 # From perl
11 use Catmandu;
12  
13 # import records from file
14 my $importer = Catmandu->importer('MARC',file => '/foo/bar.json', type => 'MiJ');
15 my $fixer = Catmandu->fixer("marc_map('245a','title')");
16  
17 $importer->each(sub {
18 my $item = shift;
19 ...
20 });
21  
22 # or using the fixer
23  
24 $fixer->fix($importer)->each(sub {
25 my $item = shift;
26 printf "title: %s\n" , $item->{title};
27 });
28  
29 =head1 METHODS
30  
31 =head2 new(file => $file , fh => $fh , id => $field)
32  
33 Parse a file or a filehandle into a L<Catmandu::Iterable>. Optionally provide an
34 id attribute specifying the source of the system identifer '_id' field (e.g. '001').
35  
36 =head1 INHERTED METHODS
37  
38 =head2 count
39  
40 =head2 each(&callback)
41  
42 =head2 ...
43  
44 Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited.
45  
46 =head1 SEE ALSO
47  
48 L<MARC::File::MARCMaker>
49  
50 =cut
51 package Catmandu::Importer::MARC::MiJ;
52 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 ▶use MARC::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 1 ▶use Catmandu::Importer::MARC::Decoder;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 ▶use MARC::File::MiJ;
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 1 our $VERSION = '1.33';
59  
60 1 with 'Catmandu::Importer';
61  
62 1 ▶has id => (is => 'ro' , default => sub { '001' });
Subroutine __ANON__: called CC=1 SCAR=0.0
63 has decoder => (
64 is => 'ro',
65 lazy => 1 ,
66 1 ▶ builder => sub {
Subroutine _build_decoder: called CC=1 SCAR=0.0
67 1 Catmandu::Importer::MARC::Decoder->new;
68 1 } );
69  
70 1 ▶sub generator {
Subroutine generator: called CC=2 SCAR=7.0
Pod undocumented
71 1 my ($self) = @_;
72 1 my $file = MARC::File::MiJ->in($self->file);
73  
74 # MARC::File doesn't provide support for inline files
75 1 ▶ $file = $self->decoder->fake_marc_file($self->fh,'MARC::File::MiJ') unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 1 1
76 sub {
77 $self->decoder->decode($file->next(),$self->id);
78 }
79 1 }
80  
81 1 1;
« Importer/MARC/MARCMaker.pm ↑ Summary Importer/MARC/Lint.pm »