| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Catmandu::Importer::MARC::Lint - Package that imports USMARC records validated with MARC::Lint |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# From the command line |
|
8
|
|
|
|
|
|
|
$ catmandu convert MARC --type Lint --fix "marc_map('245a','title')" < /foo/data.mrc |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# From perl |
|
11
|
|
|
|
|
|
|
use Catmandu; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# import records from file |
|
14
|
|
|
|
|
|
|
my $importer = Catmandu->importer('MARC',file => '/foo/data.mrc', type => 'Lint'); |
|
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 DESCRIPTION |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
All items produced with the Catmandu::Importer::MARC::Lint importer contain three keys: |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
'_id' : the system identifier of the record (usually the 001 field) |
|
34
|
|
|
|
|
|
|
'record' : an ARRAY of ARRAYs containing the record data |
|
35
|
|
|
|
|
|
|
'lint' : the output of MARC::Lint's check_record on the MARC record |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item id |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
The MARC field which contains the system id (default: 001) |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item file |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Read input from a local file given by its path. Alternatively a scalar |
|
48
|
|
|
|
|
|
|
reference can be passed to read from a string. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item fh |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Read input from an L<IO::Handle>. If not specified, L<Catmandu::Util::io> is used to |
|
53
|
|
|
|
|
|
|
create the input stream from the C<file> argument or by using STDIN. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item encoding |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Binmode of the input stream C<fh>. Set to C<:utf8> by default. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item fix |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
An ARRAY of one or more fixes or file scripts to be applied to imported items. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=back |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 METHODS |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
L<Catmandu::Importer>, |
|
72
|
|
|
|
|
|
|
L<Catmandu::Iterable> |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
|
75
|
|
|
|
|
|
|
package Catmandu::Importer::MARC::Lint; |
|
76
|
1
|
|
|
1
|
|
692
|
use Catmandu::Sane; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
77
|
1
|
|
|
1
|
|
244
|
use Moo; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
6
|
|
|
78
|
1
|
|
|
1
|
|
643
|
use MARC::File::USMARC; |
|
|
1
|
|
|
|
|
16368
|
|
|
|
1
|
|
|
|
|
29
|
|
|
79
|
1
|
|
|
1
|
|
650
|
use MARC::Lint; |
|
|
1
|
|
|
|
|
35401
|
|
|
|
1
|
|
|
|
|
42
|
|
|
80
|
1
|
|
|
1
|
|
349
|
use Catmandu::Importer::MARC::Decoder; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
218
|
|
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
our $VERSION = '1.21'; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
has id => (is => 'ro' , default => sub { '001' }); |
|
87
|
|
|
|
|
|
|
has decoder => ( |
|
88
|
|
|
|
|
|
|
is => 'ro', |
|
89
|
|
|
|
|
|
|
lazy => 1 , |
|
90
|
|
|
|
|
|
|
builder => sub { |
|
91
|
1
|
|
|
1
|
|
31
|
Catmandu::Importer::MARC::Decoder->new; |
|
92
|
|
|
|
|
|
|
} ); |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub generator { |
|
95
|
|
|
|
|
|
|
my ($self) = @_; |
|
96
|
|
|
|
|
|
|
my $lint = MARC::Lint->new; |
|
97
|
|
|
|
|
|
|
my $file = MARC::File::USMARC->in($self->fh); |
|
98
|
|
|
|
|
|
|
# MARC::File doesn't provide support for inline files |
|
99
|
|
|
|
|
|
|
$file = $self->decoder->fake_marc_file($self->fh,'MARC::File::USMARC') unless $file; |
|
100
|
|
|
|
|
|
|
sub { |
|
101
|
|
|
|
|
|
|
my $marc = $file->next(); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return undef unless $marc; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $doc = $self->decoder->decode($marc,$self->id); |
|
106
|
|
|
|
|
|
|
$lint->check_record( $marc ); |
|
107
|
|
|
|
|
|
|
$doc->{lint} = [$lint->warnings]; |
|
108
|
|
|
|
|
|
|
$doc; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |