| 1 | package MARC::Moose::Reader::File::Marcedit; | ||
| 2 | # ABSTRACT: File reader for MARC::Moose record from Marcedit file (.mrk) | ||
| 3 | $MARC::Moose::Reader::File::Marcedit::VERSION = '1.0.49'; | ||
| 4 | use Moose; | ||
| 5 | use Modern::Perl; | ||
| 6 | use MARC::Moose::Record; | ||
| 7 | use MARC::Moose::Parser::Marcedit; | ||
| 8 | |||
| 9 | with 'MARC::Moose::Reader::File'; | ||
| 10 | |||
| 11 | |||
| 12 | has '+parser' => ( | ||
| 13 | default => sub { | ||
| 14 | my $parser = MARC::Moose::Parser::Marcedit->new(); | ||
| 15 | return $parser; | ||
| 16 | } | ||
| 17 | ); | ||
| 18 | |||
| 19 | |||
| 20 | sub read { | ||
| 21 | my $self = shift; | ||
| 22 | |||
| 23 | $self->count( $self->count + 1); | ||
| 24 | |||
| 25 | my $fh = $self->{fh}; | ||
| 26 | |||
| 27 | return if eof($fh); | ||
| 28 | |||
| 29 | my @lines; | ||
| 30 | |||
| 31 | # Next record | ||
| 32 | my $found = 0; | ||
| 33 | while (<$fh>) { | ||
| 34 | $found = $_ =~ /^=LDR/; | ||
| 35 | if ($found) { | ||
| 36 | s/\n$//; | ||
| 37 | s/\r$//; | ||
| 38 | push @lines, $_; | ||
| 39 | last; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | return unless $found; | ||
| 43 | |||
| 44 | while (<$fh>) { | ||
| 45 | s/\n$//; | ||
| 46 | s/\r$//; | ||
| 47 | last unless $_; # Ligne vide | ||
| 48 | push @lines, $_; | ||
| 49 | } | ||
| 50 | |||
| 51 | $self->parser->parse(join("\n", @lines)); | ||
| 52 | } | ||
| 53 | |||
| 54 | |||
| 55 | __PACKAGE__->meta->make_immutable; | ||
| 56 | |||
| 57 | 1; | ||
| 58 | |||
| 59 | __END__ |