| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Catmandu::Importer::MARC::Decoder; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 30 |  |  | 30 |  | 60788 | use Catmandu::Sane; | 
|  | 30 |  |  |  |  | 143418 |  | 
|  | 30 |  |  |  |  | 230 |  | 
| 4 | 30 |  |  | 30 |  | 5529 | use Moo; | 
|  | 30 |  |  |  |  | 66 |  | 
|  | 30 |  |  |  |  | 163 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | our $VERSION = '1.21'; | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | sub fake_marc_file { | 
| 9 | 3 |  |  | 3 | 0 | 122 | my ($self,$fh,$class) = @_; | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 3 |  |  |  |  | 14 | my $obj = { | 
| 12 |  |  |  |  |  |  | filename    => scalar($fh), | 
| 13 |  |  |  |  |  |  | fh          => $fh, | 
| 14 |  |  |  |  |  |  | recnum      => 0, | 
| 15 |  |  |  |  |  |  | warnings    => [], | 
| 16 |  |  |  |  |  |  | }; | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 3 |  |  |  |  | 12 | return( bless $obj , $class ); | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub decode { | 
| 22 | 136 |  |  | 136 | 0 | 208378 | my ($self, $record, $id) = @_; | 
| 23 | 136 | 100 |  |  |  | 257 | return unless eval { $record->isa('MARC::Record') }; | 
|  | 136 |  |  |  |  | 744 |  | 
| 24 | 123 |  |  |  |  | 244 | my @result = (); | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 123 |  |  |  |  | 347 | push @result , [ 'LDR' , ' ', ' ' , '_' , $record->leader ]; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 123 |  |  |  |  | 1010 | for my $field ($record->fields()) { | 
| 29 | 2264 |  |  |  |  | 4510 | my $tag  = $field->tag; | 
| 30 | 2264 |  | 100 |  |  | 8688 | my $ind1 = $field->indicator(1) // ' '; | 
| 31 | 2264 |  | 100 |  |  | 22933 | my $ind2 = $field->indicator(2) // ' '; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 2264 |  |  |  |  | 21479 | my @sf = (); | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 2264 | 100 |  |  |  | 3639 | if ($field->is_control_field) { | 
| 36 | 492 |  |  |  |  | 2160 | push @sf , '_', $field->data; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 2264 |  |  |  |  | 11133 | for my $subfield ($field->subfields) { | 
| 40 | 2927 |  |  |  |  | 26843 | push @sf , @$subfield; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 2264 |  |  |  |  | 11490 | push @result, [$tag,$ind1,$ind2,@sf]; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 123 |  |  |  |  | 264 | my $sysid = undef; | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 123 | 100 | 100 |  |  | 686 | if ($id =~ /^00/ && $record->field($id)) { | 
|  |  | 100 | 33 |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 49 | 111 |  |  |  |  | 3296 | $sysid = $record->field($id)->data(); | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  | elsif ($id =~ /^([0-9]{3})([[0-9a-zA-Z])$/) { | 
| 52 | 10 |  |  |  |  | 27 | my $field = $record->field($1); | 
| 53 | 10 | 50 |  |  |  | 878 | $sysid = $field->subfield($2) if ($field); | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  | elsif (defined $id  && $record->field($id)) { | 
| 56 | 0 |  |  |  |  | 0 | $sysid = $record->field($id)->subfield("a"); | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 123 |  |  |  |  | 4004 | return { _id => $sysid , record => \@result }; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | 1; |