← Index
Performance Profile   « block view • line view • sub view »
For t/test-parsing
  Run on Sun Nov 14 09:49:57 2010
Reported on Sun Nov 14 09:50:12 2010

File /usr/share/perl5/MARC/File/SAX.pm
Statements Executed 16
Total Time 0.0009454 seconds
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
0000s0sMARC::File::SAX::::BEGINMARC::File::SAX::BEGIN
0000s0sMARC::File::SAX::::charactersMARC::File::SAX::characters
0000s0sMARC::File::SAX::::end_elementMARC::File::SAX::end_element
0000s0sMARC::File::SAX::::start_elementMARC::File::SAX::start_element
LineStmts.Exclusive
Time
Avg.Code
1package 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
12324µs8µsuse strict;
# spent 8µs making 1 call to strict::import
133122µs41µsuse XML::SAX;
# spent 44µs making 1 call to Exporter::import
14343µs14µsuse base qw( XML::SAX::Base );
# spent 20.9ms making 1 call to base::import
15348µs16µsuse Data::Dumper;
# spent 69µs making 1 call to Exporter::import
163705µs235µsuse MARC::Charset qw(utf8_to_marc8);
# spent 56µs making 1 call to Exporter::import
17
18sub 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
34sub 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
81sub 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
8914µs4µs1;