| 1 | package MARC::Moose::Parser::Iso2709; | ||||||||||||
| 2 | # ABSTRACT: Parser for ISO2709 records | ||||||||||||
| 3 | 4 | $MARC::Moose::Parser::Iso2709::VERSION = '1.0.49'; | |||||||||||
| 4 | 4 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 4 | ▶ | use Modern::Perl; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 4 | require bytes; | |||||||||||
| 7 | |||||||||||||
| 8 | 4 | extends 'MARC::Moose::Parser'; | |||||||||||
| 9 | |||||||||||||
| 10 | 4 | ▶ | use MARC::Moose::Record; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 4 | ▶ | use MARC::Moose::Field::Control; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 4 | ▶ | use MARC::Moose::Field::Std; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | |||||||||||||
| 15 | # FIXME Experimental. Not used yet. | ||||||||||||
| 16 | #has converter => ( | ||||||||||||
| 17 | # is => 'rw', | ||||||||||||
| 18 | # isa => 'Text::IconvPtr', | ||||||||||||
| 19 | # default => sub { Text::Iconv->new( "cp857", "utf8" ) } | ||||||||||||
| 20 | #); | ||||||||||||
| 21 | |||||||||||||
| 22 | |||||||||||||
| 23 | |||||||||||||
| 24 | 4 | ▶ | override 'parse' => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=24.1
| |||||||||||||
| 25 | 4 | my ($self, $raw) = @_; | |||||||||||
| 26 | |||||||||||||
| 27 | 4 | ▶ | return unless $raw; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 4 | ▶ | my $utf8_flag = utf8::is_utf8($raw) || 1; | ||||||||||
|
Condition100%2/2
utf8::is_utf8($raw) || 1
MC/DC100%1/1
utf8::is_utf8($raw) || 1
utf8::is_utf8($raw)
Truth table100%2/2
A
A= utf8::is_utf8($raw)
| |||||||||||||
| 29 | |||||||||||||
| 30 | 4 | my $record = MARC::Moose::Record->new(); | |||||||||||
| 31 | |||||||||||||
| 32 | 4 | my $leader = substr($raw, 0, 24); | |||||||||||
| 33 | 4 | $record->_leader( $leader ); | |||||||||||
| 34 | |||||||||||||
| 35 | 4 | $raw = substr($raw, 24); | |||||||||||
| 36 | 4 | my $directory_len = substr($leader, 12, 5) - 25; | |||||||||||
| 37 | 4 | my $directory = substr $raw, 0, $directory_len; | |||||||||||
| 38 | 4 | my $content = substr($raw, $directory_len+1); | |||||||||||
| 39 | 4 | my $number_of_tag = $directory_len / 12; | |||||||||||
| 40 | 4 | my @fields; | |||||||||||
| 41 | 4 | ▶ | for (my $i = 0; $i < $number_of_tag; $i++) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 76 | my $off = $i * 12; | |||||||||||
| 43 | 76 | my $tag = substr($directory, $off, 3); | |||||||||||
| 44 | 76 | ▶ | next if $tag !~ /^[a-zA-Z0-9]*$/; # FIXME: it happens! | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | 76 | my $len = substr($directory, $off+3, 4) - 1; | |||||||||||
| 46 | 76 | my $pos = substr($directory, $off+7, 5) + 0; | |||||||||||
| 47 | 76 | my $value = bytes::substr($content, $pos, $len); | |||||||||||
| 48 | 76 | ▶ | utf8::decode($value) if $utf8_flag; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | 76 | ▶ | next unless $value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | #$value = $self->converter->convert($value); | ||||||||||||
| 51 | 76 | ▶ | if ( $value =~ /\x1F/ ) { # There are some letters | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 52 | 59 | my $i1 = substr($value, 0, 1); | |||||||||||
| 53 | 59 | my $i2 = substr($value, 1, 1); | |||||||||||
| 54 | 59 | $value = substr($value, 2); | |||||||||||
| 55 | 59 | my @sf; | |||||||||||
| 56 | 59 | for ( split /\x1F/, $value) { | |||||||||||
| 57 | 160 | ▶ | next if length($_) < 2; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | 101 | push @sf, [ substr($_, 0, 1), substr($_, 1) ]; | |||||||||||
| 59 | } | ||||||||||||
| 60 | 59 | push @fields, MARC::Moose::Field::Std->new( | |||||||||||
| 61 | tag => $tag, ind1 => $i1, ind2 => $i2, subf => \@sf ); | ||||||||||||
| 62 | } | ||||||||||||
| 63 | else { | ||||||||||||
| 64 | 17 | push @fields, MARC::Moose::Field::Control->new( tag => $tag, value => $value ); | |||||||||||
| 65 | } | ||||||||||||
| 66 | } | ||||||||||||
| 67 | 4 | $record->fields( \@fields ); | |||||||||||
| 68 | 4 | ▶ | $record->lint($self->lint) if $self->lint; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | 4 | return $record; | |||||||||||
| 70 | 4 | }; | |||||||||||
| 71 | |||||||||||||
| 72 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 73 | |||||||||||||
| 74 | 4 | 1; | |||||||||||
| 75 | |||||||||||||
| 76 | __END__ | ||||||||||||