| 1 | package MARC::Moose::Parser::Marcxml; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Parser for MARXML records | ||||||||||||||||||||||||||||
| 3 | 2 | $MARC::Moose::Parser::Marcxml::VERSION = '1.0.46'; | |||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | extends 'MARC::Moose::Parser'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use MARC::Moose::Field::Control; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use MARC::Moose::Field::Std; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | override 'parse' => sub { | ||||||||||||||||||||||||||||
| 13 | 1 | ▶ | my ($self, $raw) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | return unless $raw =~ /<record/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | my @parts = split />/, $raw; | |||||||||||||||||||||||||||
| 18 | 1 | my ($tag, $code, $ind1, $ind2); | |||||||||||||||||||||||||||
| 19 | 1 | my $record = MARC::Moose::Record->new(); | |||||||||||||||||||||||||||
| 20 | 1 | my @fields; | |||||||||||||||||||||||||||
| 21 | 1 | ▶ | while ( @parts ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 22 | $_ = shift @parts; | |||||||||||||||||||||||||||
| 23 | 22 | ▶ | $_ = shift @parts if /<record/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 22 | ▶ | if ( /<leader/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 1 | $_ = shift @parts; | |||||||||||||||||||||||||||
| 26 | 1 | /(.*)<\/leader/; | |||||||||||||||||||||||||||
| 27 | 1 | $record->_leader($1); | |||||||||||||||||||||||||||
| 28 | 1 | next; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 21 | ▶ | if ( /<controlfield\s*tag="(.*)"/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 4 | my $tag = $1; | |||||||||||||||||||||||||||
| 32 | 4 | $_ = shift @parts; | |||||||||||||||||||||||||||
| 33 | 4 | s/<\/controlfield//; | |||||||||||||||||||||||||||
| 34 | 4 | push @fields, MARC::Moose::Field::Control->new( tag => $tag, value => $_ ); | |||||||||||||||||||||||||||
| 35 | 4 | next; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 17 | ▶ | if ( /<datafield\s*tag="(.*?)"\s*ind1="(.*?)"\s*ind2="(.*)"/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 16 | my ($tag, $ind1, $ind2) = ($1, $2, $3); | |||||||||||||||||||||||||||
| 39 | 16 | my @subf; | |||||||||||||||||||||||||||
| 40 | 16 | ▶ | while ( @parts && $parts[0] =~ /<subfield.*code="(.*)"/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@parts and $parts[0] =~ /<subfield.*code="(.*)"/
MC/DC50%1/2
@parts and $parts[0] =~ /<subfield.*code="(.*)"/
@parts
$parts[0] =~ /<subfield.*code="(.*)"/
Truth table66%2/3
A and B
A= @partsB= $parts[0] =~ /<subfield.*code="(.*)"/
| |||||||||||||||||||||||||||||
| 41 | 50 | my $letter = $1; | |||||||||||||||||||||||||||
| 42 | 50 | shift @parts; | |||||||||||||||||||||||||||
| 43 | 50 | $_ = shift @parts; | |||||||||||||||||||||||||||
| 44 | 50 | s/<\/subfield//; | |||||||||||||||||||||||||||
| 45 | 50 | push @subf, [ $letter => $_ ]; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 16 | ▶ | $ind1 = ' ' unless defined($ind1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 16 | ▶ | $ind2 = ' ' unless defined($ind2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 16 | push @fields, MARC::Moose::Field::Std->new( | |||||||||||||||||||||||||||
| 50 | tag => $tag, | ||||||||||||||||||||||||||||
| 51 | ind1 => $ind1, | ||||||||||||||||||||||||||||
| 52 | ind2 => $ind2, | ||||||||||||||||||||||||||||
| 53 | subf => \@subf ); | ||||||||||||||||||||||||||||
| 54 | 16 | shift @parts; | |||||||||||||||||||||||||||
| 55 | 16 | next; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 1 | last; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 1 | $record->fields( \@fields ); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | return $record; | |||||||||||||||||||||||||||
| 62 | 2 | }; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2 | 1; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =pod | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head1 NAME | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | MARC::Moose::Parser::Marcxml - Parser for MARXML records | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head1 VERSION | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | version 1.0.46 | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | This MARCXML parser doesn't use a SAX parser. It's pure Perl. This results in | ||||||||||||||||||||||||||||
| 85 | better performances. | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =over 4 | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =item * | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | L<MARC::Moose> | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =item * | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | L<MARC::Moose::Parser> | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =back | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Frédéric Demians <f.demians@tamil.fr> | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | This software is copyright (c) 2022 by Frédéric Demians. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 110 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =cut | ||||||||||||||||||||||||||||