| 1 | package Catmandu::Importer::PICA; | ||||||||||||||
| 2 | 8 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 1 | our $VERSION = '1.18'; | |||||||||||||
| 6 | |||||||||||||||
| 7 | 8 | ▶ | use Catmandu::Sane; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 8 | ▶ | use PICA::Data qw(pica_parser); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 8 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 1 | with 'Catmandu::Importer'; | |||||||||||||
| 12 | |||||||||||||||
| 13 | 0 | ▶ | has type => ( is => 'ro', default => sub { 'xml' } ); | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.4
| |||||||||||||||
| 14 | 1 | has parser => ( is => 'lazy' ); | |||||||||||||
| 15 | 21 | ▶ | has level => ( is => 'ro', default => sub { -1 } ); | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 24 | ▶ | has queue => ( is => 'ro', default => sub { [] } ); | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | |||||||||||||||
| 18 | 23 | ▶ | sub _build_parser { | ||||||||||||
|
Subroutine
_build_parser: called CC=3 SCAR=11.0
| |||||||||||||||
| 19 | 23 | my ($self) = @_; | |||||||||||||
| 20 | |||||||||||||||
| 21 | 23 | my $type = lc $self->type; | |||||||||||||
| 22 | |||||||||||||||
| 23 | 23 | ▶ | if ( $type eq 'xml' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 24 | 3 | $self->{encoding} = ':raw' | |||||||||||||
| 25 | ; # set encoding to :raw to drop PerlIO layers, as required by libxml2 | ||||||||||||||
| 26 | 3 | PICA::Parser::XML->new( $self->fh ); | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | elsif ( $type =~ m/^p(ica)?p(plus)?xml$/ ) { | ||||||||||||||
| 29 | 1 | $self->{encoding} = ':raw' | |||||||||||||
| 30 | ; # set encoding to :raw to drop PerlIO layers, as required by libxml2 | ||||||||||||||
| 31 | 1 | PICA::Parser::PPXML->new( $self->fh ); | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | else { | ||||||||||||||
| 34 | 19 | pica_parser( $type, fh => $self->fh ); | |||||||||||||
| 35 | } | ||||||||||||||
| 36 | } | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 23 | ▶ | sub generator { | ||||||||||||
|
Subroutine
generator: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 39 | 23 | my ($self) = @_; | |||||||||||||
| 40 | |||||||||||||||
| 41 | sub { | ||||||||||||||
| 42 | my $queue = $self->queue; | ||||||||||||||
| 43 | my $next = @$queue ? shift @$queue : $self->parser->next; | ||||||||||||||
| 44 | return unless $next; | ||||||||||||||
| 45 | |||||||||||||||
| 46 | if ( $self->level > -1 ) { | ||||||||||||||
| 47 | push @$queue, $next->split( $self->level ); | ||||||||||||||
| 48 | $next = shift @$queue; | ||||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | # Catmandu does not like blessed objects/arrays | ||||||||||||||
| 52 | $next->{record} = [ map { [@$_] } @{ $next->{record} } ]; | ||||||||||||||
| 53 | return {%$next}; | ||||||||||||||
| 54 | 23 | }; | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | |||||||||||||||
| 57 | 1 | 1; | |||||||||||||
| 58 | __END__ | ||||||||||||||