| 1 | package MARC::Moose::Parser::MarcxmlSaxSimple; | ||
| 2 | # ABSTRACT: Parser for MARXML records using SAX::Simple parser | ||
| 3 | $MARC::Moose::Parser::MarcxmlSaxSimple::VERSION = '1.0.46'; | ||
| 4 | use Moose; | ||
| 5 | |||
| 6 | extends 'MARC::Moose::Parser'; | ||
| 7 | |||
| 8 | use MARC::Moose::Field::Control; | ||
| 9 | use MARC::Moose::Field::Std; | ||
| 10 | use XML::Simple; | ||
| 11 | |||
| 12 | has 'xs' => ( is => 'rw', default => sub { XML::Simple->new() } ); | ||
| 13 | |||
| 14 | |||
| 15 | override 'parse' => sub { | ||
| 16 | my ($self, $raw) = @_; | ||
| 17 | |||
| 18 | return unless $raw; | ||
| 19 | |||
| 20 | my $ref = eval { $self->xs->XMLin($raw, forcearray => [ 'subfield' ] ) }; | ||
| 21 | return if $@; | ||
| 22 | |||
| 23 | my $record = MARC::Moose::Record->new(); | ||
| 24 | $record->_leader( $ref->{leader} ); | ||
| 25 | my @fields_control = map { | ||
| 26 | MARC::Moose::Field::Control->new( tag => $_->{tag}, value => $_->{content} ); | ||
| 27 | } @{$ref->{controlfield}}; | ||
| 28 | my @fields_std = map { | ||
| 29 | my @sf = map { [ $_->{code}, $_->{content} ] } @{$_->{subfield}}; | ||
| 30 | MARC::Moose::Field::Std->new( | ||
| 31 | tag => $_->{tag}, | ||
| 32 | ind1 => defined($_->{ind1}) ? $_->{ind1} : ' ', | ||
| 33 | ind2 => defined($_->{ind2}) ? $_->{ind2} : ' ', | ||
| 34 | subf => \@sf, | ||
| 35 | ); | ||
| 36 | } @{$ref->{datafield}}; | ||
| 37 | $record->fields( [ @fields_control, @fields_std ] ); | ||
| 38 | |||
| 39 | return $record; | ||
| 40 | }; | ||
| 41 | |||
| 42 | __PACKAGE__->meta->make_immutable; | ||
| 43 | |||
| 44 | 1; | ||
| 45 | |||
| 46 | __END__ | ||
| 47 | |||
| 48 | =pod | ||
| 49 | |||
| 50 | =encoding UTF-8 | ||
| 51 | |||
| 52 | =head1 NAME | ||
| 53 | |||
| 54 | MARC::Moose::Parser::MarcxmlSaxSimple - Parser for MARXML records using SAX::Simple parser | ||
| 55 | |||
| 56 | =head1 VERSION | ||
| 57 | |||
| 58 | version 1.0.46 | ||
| 59 | |||
| 60 | =head1 SEE ALSO | ||
| 61 | |||
| 62 | =over 4 | ||
| 63 | |||
| 64 | =item * | ||
| 65 | |||
| 66 | L<MARC::Moose> | ||
| 67 | |||
| 68 | =item * | ||
| 69 | |||
| 70 | L<MARC::Moose::Parser> | ||
| 71 | |||
| 72 | =item * | ||
| 73 | |||
| 74 | L<MARC::Moose::Parser::Marcxml> | ||
| 75 | |||
| 76 | =back | ||
| 77 | |||
| 78 | =head1 AUTHOR | ||
| 79 | |||
| 80 | Frédéric Demians <f.demians@tamil.fr> | ||
| 81 | |||
| 82 | =head1 COPYRIGHT AND LICENSE | ||
| 83 | |||
| 84 | This software is copyright (c) 2022 by Frédéric Demians. | ||
| 85 | |||
| 86 | This is free software; you can redistribute it and/or modify it under | ||
| 87 | the same terms as the Perl 5 programming language system itself. | ||
| 88 | |||
| 89 | =cut |