| 1 | package MARC::Moose::Parser::Marcedit; | ||
| 2 | # ABSTRACT: Parser for Marcedit records | ||
| 3 | $MARC::Moose::Parser::Marcedit::VERSION = '1.0.49'; | ||
| 4 | use Moose; | ||
| 5 | extends 'MARC::Moose::Parser'; | ||
| 6 | use JSON; | ||
| 7 | |||
| 8 | |||
| 9 | override 'parse' => sub { | ||
| 10 | my ($self, $raw) = @_; | ||
| 11 | return unless $raw; | ||
| 12 | |||
| 13 | my @fields; | ||
| 14 | my $leader; | ||
| 15 | for my $line (split /\n/, $raw) { | ||
| 16 | my $tag = substr($line, 1, 3); | ||
| 17 | if ($tag eq 'LDR') { | ||
| 18 | $leader = substr($line, 6); | ||
| 19 | next; | ||
| 20 | } | ||
| 21 | if ($tag lt '010') { | ||
| 22 | push @fields, MARC::Moose::Field::Control->new( | ||
| 23 | tag => $tag, value => substr($line, 6)); | ||
| 24 | next; | ||
| 25 | } | ||
| 26 | my $ind1 = substr($line, 6, 1); | ||
| 27 | my $ind2 = substr($line, 7, 1); | ||
| 28 | $ind1 = ' ' if $ind1 eq "\\"; | ||
| 29 | $ind2 = ' ' if $ind2 eq "\\"; | ||
| 30 | $line = substr($line, 9); | ||
| 31 | my @parts = split /\$/, $line; | ||
| 32 | my @subf; | ||
| 33 | for my $part (@parts) { | ||
| 34 | my ($letter, $value) = (substr($part, 0, 1), substr($part, 1)); | ||
| 35 | push @subf, [ $letter => $value ]; | ||
| 36 | } | ||
| 37 | push @fields, MARC::Moose::Field::Std->new( | ||
| 38 | tag => $tag, | ||
| 39 | ind1 => $ind1, | ||
| 40 | ind2 => $ind2, | ||
| 41 | subf => \@subf ); | ||
| 42 | } | ||
| 43 | my $record = MARC::Moose::Record->new( | ||
| 44 | fields => \@fields ); | ||
| 45 | $record->_leader($leader); | ||
| 46 | |||
| 47 | $record->lint($self->lint) if $record->lint; | ||
| 48 | |||
| 49 | return $record; | ||
| 50 | }; | ||
| 51 | |||
| 52 | __PACKAGE__->meta->make_immutable; | ||
| 53 | 1; | ||
| 54 | |||
| 55 | __END__ |