| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catmandu::Exporter::MAB2; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.23'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
82471
|
use Catmandu::Sane; |
|
|
2
|
|
|
|
|
151143
|
|
|
|
2
|
|
|
|
|
14
|
|
|
6
|
2
|
|
|
2
|
|
1312
|
use MAB2::Writer::Disk; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
62
|
|
|
7
|
2
|
|
|
2
|
|
806
|
use MAB2::Writer::RAW; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
54
|
|
|
8
|
2
|
|
|
2
|
|
761
|
use MAB2::Writer::XML; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
53
|
|
|
9
|
2
|
|
|
2
|
|
22
|
use Moo; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
7
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Exporter'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has type => ( is => 'ro', default => sub {'raw'} ); |
|
14
|
|
|
|
|
|
|
has xml_declaration => ( is => 'ro', default => sub {0} ); |
|
15
|
|
|
|
|
|
|
has collection => ( is => 'ro', default => sub {0} ); |
|
16
|
|
|
|
|
|
|
has writer => ( is => 'lazy' ); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _build_writer { |
|
19
|
3
|
|
|
3
|
|
25
|
my ($self) = @_; |
|
20
|
|
|
|
|
|
|
|
|
21
|
3
|
|
|
|
|
6
|
my $type = lc( $self->{type} ); |
|
22
|
3
|
100
|
|
|
|
11
|
if ( $type eq 'raw' ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
15
|
MAB2::Writer::RAW->new( fh => $self->fh ); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
elsif ( $type eq 'disk' ) { |
|
26
|
1
|
|
|
|
|
15
|
MAB2::Writer::Disk->new( fh => $self->fh ); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
elsif ( $type eq 'xml' ) { |
|
29
|
1
|
|
|
|
|
18
|
MAB2::Writer::XML->new( |
|
30
|
|
|
|
|
|
|
fh => $self->fh, |
|
31
|
|
|
|
|
|
|
xml_declaration => $self->xml_declaration, |
|
32
|
|
|
|
|
|
|
collection => $self->collection |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
else { |
|
36
|
0
|
|
|
|
|
|
die "unknown type: $type"; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub add { |
|
41
|
|
|
|
|
|
|
my ( $self, $data ) = @_; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
if ( !$self->count ) { |
|
44
|
|
|
|
|
|
|
if ( lc( $self->type ) eq 'xml' ) { |
|
45
|
|
|
|
|
|
|
$self->writer->start(); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$self->writer->write($data); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub commit { |
|
54
|
|
|
|
|
|
|
my ($self) = @_; |
|
55
|
|
|
|
|
|
|
if ( $self->collection ) { |
|
56
|
|
|
|
|
|
|
$self->writer->end(); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
$self->writer->close_fh(); |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=pod |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=encoding UTF-8 |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 NAME |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Catmandu::Exporter::MAB2 - Package that exports MAB2 data |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
use Catmandu::Exporter::MAB2; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $exporter = Catmandu::Exporter::MAB2->new(file => "mab2.dat", type => "RAW"); |
|
80
|
|
|
|
|
|
|
my $data = { |
|
81
|
|
|
|
|
|
|
record => [ |
|
82
|
|
|
|
|
|
|
... |
|
83
|
|
|
|
|
|
|
[245, '1', 'a', 'Cross-platform Perl /', 'c', 'Eric F. Johnson.'], |
|
84
|
|
|
|
|
|
|
... |
|
85
|
|
|
|
|
|
|
], |
|
86
|
|
|
|
|
|
|
}; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$exporter->add($data); |
|
89
|
|
|
|
|
|
|
$exporter->commit; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 Arguments |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=over |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item C<file> |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Path to file with MAB2 records. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item C<fh> |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Open filehandle for file with MAB2 records. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item C<type> |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Specify type of MAB2 records: Disk (Diskette), RAW (Band), XML. Default: 001. Optional. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item C<xml_declaration> |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Write XML declaration. Set to 0 or 1. Default: 0. Optional. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item C<collection> |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Wrap records in collection element (<datei>). Set to 0 or 1. Default: 0. Optional. |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=back |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 METHODS |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 new(file => $file | fh => $filehandle [, type => XML, xml-declaration => 1, collection => 1]) |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Create a new Catmandu MAB2 exports which serializes into a $file. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 add($data) |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Add record to exporter. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 commit() |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Close collection (optional) and filehandle. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
In addition to the configuration provided by L<Catmandu::Exporter> (C<file>, |
|
134
|
|
|
|
|
|
|
C<fh>, etc.) the importer can be configured with the following parameters: |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=over |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item type |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
MAB2 syntax variant. See L<Catmandu::Importer::MAB2>. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item xml_declaration |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Write XML declaration. Set to 0 or 1. Default: 0. Optional. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item collection |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Wrap records in collection element (<datei>). Set to 0 or 1. Default: 0. Optional. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=back |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 AUTHOR |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Johann Rolschewski <jorol@cpan.org> |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Johann Rolschewski. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
161
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |