line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Exporter::PICA; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
20720
|
use Catmandu::Sane; |
|
2
|
|
|
|
|
99304
|
|
|
2
|
|
|
|
|
10
|
|
4
|
2
|
|
|
2
|
|
2239
|
use PICA::Writer::Plus; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use PICA::Writer::Plain; |
6
|
|
|
|
|
|
|
use PICA::Writer::XML; |
7
|
|
|
|
|
|
|
use Moo; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.15'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Exporter'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has type => ( is => 'rw', default => sub { 'xml' } ); |
14
|
|
|
|
|
|
|
has writer => ( is => 'lazy' ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _build_writer { |
17
|
|
|
|
|
|
|
my ($self) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $type = lc $self->type; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
if ( $type =~ /^(pica)?plus$/ ) { |
22
|
|
|
|
|
|
|
PICA::Writer::Plus->new( fh => $self->fh ); |
23
|
|
|
|
|
|
|
} elsif ( $type eq 'plain') { |
24
|
|
|
|
|
|
|
PICA::Writer::Plain->new( fh => $self->fh ); |
25
|
|
|
|
|
|
|
} elsif ( $type eq 'xml') { |
26
|
|
|
|
|
|
|
PICA::Writer::XML->new( fh => $self->fh ); |
27
|
|
|
|
|
|
|
} else { |
28
|
|
|
|
|
|
|
die "unknown type: $type"; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub add { |
33
|
|
|
|
|
|
|
my ($self, $data) = @_; |
34
|
|
|
|
|
|
|
# utf8::decode ??? |
35
|
|
|
|
|
|
|
$self->writer->write($data); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub commit { # TODO: why is this not called automatically? |
39
|
|
|
|
|
|
|
my ($self) = @_; |
40
|
|
|
|
|
|
|
$self->writer->end if $self->can('end'); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
__END__ |