line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Catmandu::Importer::MARC::RAW - Package that imports ISO 2709 encoded MARC records |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# From the command line |
8
|
|
|
|
|
|
|
$ catmandu convert MARC --type RAW --fix "marc_map('245a','title')" < /foo/bar.mrc |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# From perl |
11
|
|
|
|
|
|
|
use Catmandu; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# import records from file |
14
|
|
|
|
|
|
|
my $importer = Catmandu->importer('MARC',file => '/foo/bar.mrc' , type => 'RAW'); |
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 CONFIGURATION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=over |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item id |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
The MARC field which contains the system id (default: 001) |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item file |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Read input from a local file given by its path. Alternatively a scalar |
40
|
|
|
|
|
|
|
reference can be passed to read from a string. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item fh |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Read input from an L<IO::Handle>. If not specified, L<Catmandu::Util::io> is used to |
45
|
|
|
|
|
|
|
create the input stream from the C<file> argument or by using STDIN. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item encoding |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Binmode of the input stream C<fh>. Set to C<:utf8> by default. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item fix |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
An ARRAY of one or more fixes or file scripts to be applied to imported items. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=back |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 METHODS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SEE ALSO |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
L<Catmandu::Importer>, |
64
|
|
|
|
|
|
|
L<Catmandu::Iterable> |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
package Catmandu::Importer::MARC::RAW; |
68
|
2
|
|
|
2
|
|
897
|
use Catmandu::Sane; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
26
|
|
69
|
2
|
|
|
2
|
|
403
|
use Moo; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
70
|
2
|
|
|
2
|
|
1244
|
use MARC::Parser::RAW; |
|
2
|
|
|
|
|
94267
|
|
|
2
|
|
|
|
|
414
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
our $VERSION = '1.20'; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
has id => (is => 'ro' , default => sub { '001' }); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub generator { |
79
|
|
|
|
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
my $parser = MARC::Parser::RAW->new($self->fh); |
81
|
|
|
|
|
|
|
sub { |
82
|
|
|
|
|
|
|
my $record = $parser->next(); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
return undef unless defined $record; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $id; |
87
|
|
|
|
|
|
|
for my $field (@$record) { |
88
|
|
|
|
|
|
|
my ($tag,$ind1,$ind2,$p,$data,@q) = @$field; |
89
|
|
|
|
|
|
|
if ($tag eq $self->id) { |
90
|
|
|
|
|
|
|
$id = $data; |
91
|
|
|
|
|
|
|
last; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
+{ _id => $id , record => $record }; |
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |