line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::MAB2; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.21'; |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
644546
|
use Catmandu::Sane; |
|
5
|
|
|
|
|
385882
|
|
|
5
|
|
|
|
|
34
|
|
6
|
5
|
|
|
5
|
|
971
|
use Moo; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
24
|
|
7
|
5
|
|
|
5
|
|
2741
|
use MAB2::Parser::Disk; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
216
|
|
8
|
5
|
|
|
5
|
|
1516
|
use MAB2::Parser::RAW; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
194
|
|
9
|
5
|
|
|
5
|
|
1327
|
use MAB2::Parser::XML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has type => ( is => 'ro', default => sub {'RAW'} ); |
14
|
|
|
|
|
|
|
has id => ( is => 'ro', default => sub {'001'} ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub mab_generator { |
17
|
|
|
|
|
|
|
my $self = shift; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $file; |
20
|
|
|
|
|
|
|
my $type = lc($self->type); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
if ( $type eq 'raw' ) { |
23
|
|
|
|
|
|
|
$file = MAB2::Parser::RAW->new( $self->fh ); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
elsif ( $type eq 'xml' ) { |
26
|
|
|
|
|
|
|
$self->{encoding} = ':raw'; # set encoding to :raw to drop PerlIO layers, as required by libxml2 |
27
|
|
|
|
|
|
|
$file = MAB2::Parser::XML->new( $self->fh ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
elsif ( $type eq 'disk' ) { |
30
|
|
|
|
|
|
|
$file = MAB2::Parser::Disk->new( $self->fh ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
|
|
|
|
|
|
Catmandu::Error->throw('unknown type'); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $id = $self->id; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub { |
39
|
|
|
|
|
|
|
my $record = $file->next(); |
40
|
|
|
|
|
|
|
return unless $record; |
41
|
|
|
|
|
|
|
return $record; |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub generator { |
46
|
|
|
|
|
|
|
my ($self) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $type = lc($self->type); |
49
|
|
|
|
|
|
|
if ( $type =~ /raw|xml|disk$/ ) { |
50
|
|
|
|
|
|
|
return $self->mab_generator; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
|
|
|
|
|
|
Catmandu::Error->throw('unknown type (suppported types: Disk, RAW, XML)'); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=pod |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=encoding UTF-8 |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 NAME |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Catmandu::Importer::MAB2 - Package that imports MAB2 data |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 SYNOPSIS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
use Catmandu::Importer::MAB2; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $importer = Catmandu::Importer::MAB2->new(file => "./t/mab2.dat", type=> "raw"); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $n = $importer->each(sub { |
77
|
|
|
|
|
|
|
my $hashref = $_[0]; |
78
|
|
|
|
|
|
|
# ... |
79
|
|
|
|
|
|
|
}); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
To convert between MAB2 syntax variants with the L<catmandu> command line client: |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
catmandu convert MAB2 --type raw to MAB2 --type xml < mab2.dat |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 MAB2 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
The parsed MAB2 record is a HASH containing two keys '_id' containing the 001 field (or the system |
88
|
|
|
|
|
|
|
identifier of the record) and 'record' containing an ARRAY of ARRAYs for every field: |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
{ |
91
|
|
|
|
|
|
|
'record' => [ |
92
|
|
|
|
|
|
|
[ |
93
|
|
|
|
|
|
|
'001', |
94
|
|
|
|
|
|
|
' ', |
95
|
|
|
|
|
|
|
'_', |
96
|
|
|
|
|
|
|
'fol05882032 ' |
97
|
|
|
|
|
|
|
], |
98
|
|
|
|
|
|
|
[ |
99
|
|
|
|
|
|
|
245, |
100
|
|
|
|
|
|
|
'a', |
101
|
|
|
|
|
|
|
'a', |
102
|
|
|
|
|
|
|
'Cross-platform Perl /', |
103
|
|
|
|
|
|
|
'c', |
104
|
|
|
|
|
|
|
'Eric F. Johnson.' |
105
|
|
|
|
|
|
|
], |
106
|
|
|
|
|
|
|
], |
107
|
|
|
|
|
|
|
'_id' => 'fol05882032' |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 METHODS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This module inherits all methods of L<Catmandu::Importer> and by this |
113
|
|
|
|
|
|
|
L<Catmandu::Iterable>. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 CONFIGURATION |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
In addition to the configuration provided by L<Catmandu::Importer> (C<file>, |
118
|
|
|
|
|
|
|
C<fh>, etc.) the importer can be configured with the following parameters: |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=over |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item type |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Describes the MAB2 syntax variant. Supported values (case ignored) include the |
125
|
|
|
|
|
|
|
default value C<xml> for MABxml, C<disk> for human-readable MAB2 serialization |
126
|
|
|
|
|
|
|
("Diskettenformat") or C<raw> for data-exchange MAB2 serialization ("Bandformat"). |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 AUTHOR |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Johann Rolschewski <jorol@cpan.org> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Johann Rolschewski. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
139
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |