| File | /usr/share/perl5/MARC/File/SAX.pm |
| Statements Executed | 16 |
| Total Time | 0.0009454 seconds |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0s | 0s | MARC::File::SAX::BEGIN |
| 0 | 0 | 0 | 0s | 0s | MARC::File::SAX::characters |
| 0 | 0 | 0 | 0s | 0s | MARC::File::SAX::end_element |
| 0 | 0 | 0 | 0s | 0s | MARC::File::SAX::start_element |
| Line | Stmts. | Exclusive Time | Avg. | Code |
|---|---|---|---|---|
| 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 | 3 | 24µs | 8µs | use strict; # spent 8µs making 1 call to strict::import |
| 13 | 3 | 122µs | 41µs | use XML::SAX; # spent 44µs making 1 call to Exporter::import |
| 14 | 3 | 43µs | 14µs | use base qw( XML::SAX::Base ); # spent 20.9ms making 1 call to base::import |
| 15 | 3 | 48µs | 16µs | use Data::Dumper; # spent 69µs making 1 call to Exporter::import |
| 16 | 3 | 705µs | 235µs | use MARC::Charset qw(utf8_to_marc8); # spent 56µs making 1 call to Exporter::import |
| 17 | ||||
| 18 | sub start_element { | |||
| 19 | my ( $self, $element ) = @_; | |||
| 20 | my $name = $element->{ Name }; | |||
| 21 | if ( $name eq 'leader' ) { | |||
| 22 | $self->{ tag } = 'LDR'; | |||
| 23 | } elsif ( $name eq 'controlfield' ) { | |||
| 24 | $self->{ tag } = $element->{ Attributes }{ '{}tag' }{ Value }; | |||
| 25 | } elsif ( $name eq 'datafield' ) { | |||
| 26 | $self->{ tag } = $element->{ Attributes }{ '{}tag' }{ Value }; | |||
| 27 | $self->{ i1 } = $element->{ Attributes }{ '{}ind1' }{ Value }; | |||
| 28 | $self->{ i2 } = $element->{ Attributes }{ '{}ind2' }{ Value }; | |||
| 29 | } elsif ( $name eq 'subfield' ) { | |||
| 30 | $self->{ subcode } = $element->{ Attributes }{ '{}code' }{ Value }; | |||
| 31 | } | |||
| 32 | } | |||
| 33 | ||||
| 34 | sub end_element { | |||
| 35 | my ( $self, $element ) = @_; | |||
| 36 | my $name = $element->{ Name }; | |||
| 37 | if ( $name eq 'subfield' ) { | |||
| 38 | push @{ $self->{ subfields } }, $self->{ subcode }; | |||
| 39 | ||||
| 40 | if ($self->{ transcode }) { | |||
| 41 | push @{ $self->{ subfields } }, utf8_to_marc8($self->{ chars }); | |||
| 42 | } else { | |||
| 43 | push @{ $self->{ subfields } }, $self->{ chars } ; | |||
| 44 | } | |||
| 45 | ||||
| 46 | $self->{ chars } = ''; | |||
| 47 | $self->{ subcode } = ''; | |||
| 48 | } elsif ( $name eq 'controlfield' ) { | |||
| 49 | $self->{ record }->append_fields( | |||
| 50 | MARC::Field->new( $self->{ tag }, $self->{ chars } ) | |||
| 51 | ); | |||
| 52 | $self->{ chars } = ''; | |||
| 53 | $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 | @{ $self->{ subfields } } | |||
| 61 | ) | |||
| 62 | ); | |||
| 63 | $self->{ tag } = ''; | |||
| 64 | $self->{ i1 } = ''; | |||
| 65 | $self->{ i2 } = ''; | |||
| 66 | $self->{ subfields } = []; | |||
| 67 | $self->{ chars } = ''; | |||
| 68 | } elsif ( $name eq 'leader' ) { | |||
| 69 | my $ldr = $self->{ chars }; | |||
| 70 | $self->{ transcode }++ | |||
| 71 | if (substr($ldr,9,1) eq 'a' and $self->{toMARC8}); | |||
| 72 | ||||
| 73 | substr($ldr,9,1,' ') if ($self->{ transcode }); | |||
| 74 | $self->{ record }->leader( $ldr ); | |||
| 75 | $self->{ chars } = ''; | |||
| 76 | $self->{ tag } = ''; | |||
| 77 | } | |||
| 78 | ||||
| 79 | } | |||
| 80 | ||||
| 81 | sub characters { | |||
| 82 | my ( $self, $chars ) = @_; | |||
| 83 | if ( ( exists $self->{ subcode } and $self->{ subcode } ne '') or ( $self->{ tag } and | |||
| 84 | ( $self->{ tag } eq 'LDR' or $self->{ tag } < 10 ) ) ) { | |||
| 85 | $self->{ chars } .= $chars->{ Data }; | |||
| 86 | } | |||
| 87 | } | |||
| 88 | ||||
| 89 | 1 | 4µs | 4µs | 1; |