| 1 | package MARC::File::SAX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ## no POD here since you don't really want to use this module | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ## directly. Look at MARC::File::XML instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ## MARC::File::SAX is a SAX handler for parsing XML encoded using the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ## MARC21slim XML schema from the Library of Congress. It builds a MARC::Record | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | ## object up from SAX events. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | ## For more details see: http://www.loc.gov/standards/marcxml/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use XML::SAX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use base qw( XML::SAX::Base ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use MARC::Charset qw(utf8_to_marc8); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | sub start_element { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 483 | ▶ | my ( $self, $element ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_element: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 483 | my $name = $element->{ Name }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 483 | ▶ | if ( $name eq 'leader' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 14 | $self->{ tag } = 'LDR'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } elsif ( $name eq 'controlfield' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 44 | $self->{ tag } = $element->{ Attributes }{ '{}tag' }{ Value }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } elsif ( $name eq 'datafield' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 159 | $self->{ tag } = $element->{ Attributes }{ '{}tag' }{ Value }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 159 | $self->{ i1 } = $element->{ Attributes }{ '{}ind1' }{ Value }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 159 | $self->{ i2 } = $element->{ Attributes }{ '{}ind2' }{ Value }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } elsif ( $name eq 'subfield' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 250 | $self->{ subcode } = $element->{ Attributes }{ '{}code' }{ Value }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | sub end_element { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 483 | ▶ | my ( $self, $element ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end_element: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 483 | my $name = $element->{ Name }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 483 | ▶ | if ( $name eq 'subfield' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 250 | push @{ $self->{ subfields } }, $self->{ subcode }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 250 | ▶ | if ($self->{ transcode }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 10 | push @{ $self->{ subfields } }, utf8_to_marc8($self->{ chars }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 240 | push @{ $self->{ subfields } }, $self->{ chars } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 250 | $self->{ chars } = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 250 | $self->{ subcode } = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } elsif ( $name eq 'controlfield' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | $self->{ record }->append_fields( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | MARC::Field->new( $self->{ tag }, $self->{ chars } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 44 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 44 | $self->{ chars } = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 44 | $self->{ tag } = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } elsif ( $name eq 'datafield' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | $self->{ record }->append_fields( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | MARC::Field->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | $self->{ tag }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | $self->{ i1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | $self->{ i2 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 159 | @{ $self->{ subfields } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 159 | $self->{ tag } = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 159 | $self->{ i1 } = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 159 | $self->{ i2 } = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 159 | $self->{ subfields } = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 159 | $self->{ chars } = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } elsif ( $name eq 'leader' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 14 | my $ldr = $self->{ chars }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | $self->{ transcode }++ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 14 | ▶ | if (substr($ldr,9,1) eq 'a' and $self->{toMARC8}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
substr($ldr, 9, 1) eq "a" and $self->{"toMARC8"}
MC/DC50%1/2
substr($ldr, 9, 1) eq "a" and $self->{"toMARC8"}
substr($ldr, 9, 1) eq "a"
$self->{"toMARC8"}
Truth table66%2/3
A and B
A= substr($ldr, 9, 1) eq "a"B= $self->{"toMARC8"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 14 | ▶ | substr($ldr,9,1,' ') if ($self->{ transcode }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 14 | $self->{ record }->leader( $ldr ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 14 | $self->{ chars } = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 14 | $self->{ tag } = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | sub characters { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 960 | ▶ | my ( $self, $chars ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
characters: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 960 | ▶ | if ( $self->{ subcode } or ( $self->{ tag } and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$self->{"subcode"} or $self->{"tag"} and $self->{"tag"} eq "LDR" || $self->{"tag"} < 10
$self->{"tag"} and $self->{"tag"} eq "LDR" || $self->{"tag"} < 10
$self->{"tag"} eq "LDR" or $self->{"tag"} < 10
MC/DC100%4/4
$self->{"subcode"} or $self->{"tag"} and $self->{"tag"} eq "LDR" || $self->{"tag"} < 10
$self->{"subcode"}
$self->{"tag"}
$self->{"tag"} eq "LDR"
$self->{"tag"} < 10
Truth table100%5/5
A or B and C or D
A= $self->{"subcode"}B= $self->{"tag"}C= $self->{"tag"} eq "LDR"D= $self->{"tag"} < 10
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ( $self->{ tag } eq 'LDR' or $self->{ tag } < 10 ) ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 316 | $self->{ chars } .= $chars->{ Data }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||