| 1 | package MARC::Moose::Formater::Iso2709; | ||||||||||
| 2 | # ABSTRACT: MARC::Moose record formater into ISO 2709 format | ||||||||||
| 3 | 4 | $MARC::Moose::Formater::Iso2709::VERSION = '1.0.49'; | |||||||||
| 4 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use Modern::Perl; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 4 | extends 'MARC::Moose::Formater'; | |||||||||
| 9 | |||||||||||
| 10 | 4 | ▶ | use MARC::Moose::Field::Control; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 4 | ▶ | use MARC::Moose::Field::Std; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | override 'format' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=27.0
| |||||||||||
| 16 | 0 | my ($self, $record) = @_; | |||||||||
| 17 | |||||||||||
| 18 | 0 | my ( $directory, $fields, $from ) = ( '', '', 0 ); | |||||||||
| 19 | 4 | ▶ | use YAML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 0 | for my $field ( @{$record->fields} ) { | |||||||||
| 21 | 0 | my $str = do { | |||||||||
| 22 | 0 | ▶ | if ( ref($field) eq 'MARC::Moose::Field::Control' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 0 | $field->value . "\x1E"; | |||||||||
| 24 | } | ||||||||||
| 25 | else { | ||||||||||
| 26 | 0 | my $str = ''; | |||||||||
| 27 | 0 | $str .= "\x1F" . $_->[0] . $_->[1] for @{$field->subf}; | |||||||||
| 28 | 0 | $str = $field->ind1 . $field->ind2 . $str . "\x1E"; | |||||||||
| 29 | } | ||||||||||
| 30 | }; | ||||||||||
| 31 | #utf8::encode($str) unless utf8::is_utf8($str); | ||||||||||
| 32 | 0 | $fields .= $str; | |||||||||
| 33 | #FIXME: Which of this lines is the correct one? | ||||||||||
| 34 | 0 | my $len = bytes::length($str); | |||||||||
| 35 | #my $len = length($str); | ||||||||||
| 36 | 0 | $directory .= sprintf( "%03s%04d%05d", $field->tag, $len, $from ); | |||||||||
| 37 | 0 | $from += $len; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | # Update leader with calculated offset (data begining) and total length of | ||||||||||
| 41 | # record | ||||||||||
| 42 | 0 | my $offset = 24 + 12 * @{$record->fields} + 1; | |||||||||
| 43 | 0 | my $length = $offset + $from + 1; | |||||||||
| 44 | 0 | $record->set_leader_length( $length, $offset ); | |||||||||
| 45 | |||||||||||
| 46 | 0 | return $record->leader . $directory . "\x1E" . $fields . "\x1D"; | |||||||||
| 47 | 4 | }; | |||||||||
| 48 | |||||||||||
| 49 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||
| 50 | |||||||||||
| 51 | 4 | 1; | |||||||||
| 52 | |||||||||||
| 53 | __END__ | ||||||||||