Profile of XML/Parser/Expat.pm

← Index
NYTProf Performance Profile «line view»
For t/bug-md-11.t
Run on Fri Mar 8 13:27:24 2024
Reported on Fri Mar 8 13:30:23 2024

Filename | /home/micha/.plenv/versions/5.38.2/lib/perl5/site_perl/5.38.2/x86_64-linux/XML/Parser/Expat.pm
Statements | Executed 21950262 statements in 19.7s

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
67598 | 5 | 2 | 3.07s | 3.36s | XML::Parser::Expat::::setHandlers XML::Parser::Expat::setHandlers
7 | 1 | 1 | 2.57s | 70.4s | XML::Parser::Expat::::ParseString XML::Parser::Expat::ParseString (xsub)
1460048 | 2 | 1 | 1.73s | 1.73s | XML::Parser::Expat::::namespace XML::Parser::Expat::namespace
380001 | 1 | 1 | 1.51s | 1.51s | XML::Parser::Expat::::current_ns_prefixes XML::Parser::Expat::current_ns_prefixes
1520689 | 2 | 1 | 1.31s | 1.31s | XML::Parser::Expat::::expand_ns_prefix XML::Parser::Expat::expand_ns_prefix
364369 | 1 | 1 | 1.09s | 1.31s | XML::Parser::Expat::::recognized_string XML::Parser::Expat::recognized_string
398167 | 1 | 1 | 243ms | 243ms | XML::Parser::Expat::::new_ns_prefixes XML::Parser::Expat::new_ns_prefixes
364369 | 1 | 1 | 223ms | 223ms | XML::Parser::Expat::::RecognizedString XML::Parser::Expat::RecognizedString (xsub)
431581 | 5 | 1 | 221ms | 221ms | XML::Parser::Expat::::depth XML::Parser::Expat::depth
67591 | 1 | 1 | 26.8ms | 26.8ms | XML::Parser::Expat::::SetXMLDeclHandler XML::Parser::Expat::SetXMLDeclHandler (xsub)
67591 | 1 | 1 | 22.2ms | 22.2ms | XML::Parser::Expat::::SetEndElementHandler XML::Parser::Expat::SetEndElementHandler (xsub)
67591 | 1 | 1 | 21.1ms | 21.1ms | XML::Parser::Expat::::SetEntityDeclHandler XML::Parser::Expat::SetEntityDeclHandler (xsub)
67591 | 1 | 1 | 20.8ms | 20.8ms | XML::Parser::Expat::::SetAttListDeclHandler XML::Parser::Expat::SetAttListDeclHandler (xsub)
67591 | 1 | 1 | 20.5ms | 20.5ms | XML::Parser::Expat::::SetCommentHandler XML::Parser::Expat::SetCommentHandler (xsub)
67591 | 1 | 1 | 20.4ms | 20.4ms | XML::Parser::Expat::::SetCharacterDataHandler XML::Parser::Expat::SetCharacterDataHandler (xsub)
67591 | 1 | 1 | 20.2ms | 20.2ms | XML::Parser::Expat::::SetEndCdataHandler XML::Parser::Expat::SetEndCdataHandler (xsub)
67591 | 1 | 1 | 20.1ms | 20.1ms | XML::Parser::Expat::::SetExternalEntityRefHandler XML::Parser::Expat::SetExternalEntityRefHandler (xsub)
67591 | 1 | 1 | 19.4ms | 19.4ms | XML::Parser::Expat::::SetElementDeclHandler XML::Parser::Expat::SetElementDeclHandler (xsub)
67591 | 1 | 1 | 18.9ms | 18.9ms | XML::Parser::Expat::::SetStartCdataHandler XML::Parser::Expat::SetStartCdataHandler (xsub)
67591 | 1 | 1 | 17.8ms | 17.8ms | XML::Parser::Expat::::SetDoctypeHandler XML::Parser::Expat::SetDoctypeHandler (xsub)
67591 | 1 | 1 | 17.8ms | 17.8ms | XML::Parser::Expat::::SetProcessingInstructionHandler XML::Parser::Expat::SetProcessingInstructionHandler (xsub)
67598 | 1 | 1 | 17.4ms | 17.4ms | XML::Parser::Expat::::SetDefaultHandler XML::Parser::Expat::SetDefaultHandler (xsub)
67591 | 1 | 1 | 15.7ms | 15.7ms | XML::Parser::Expat::::SetStartElementHandler XML::Parser::Expat::SetStartElementHandler (xsub)
7 | 1 | 1 | 12.0ms | 70.4s | XML::Parser::Expat::::parse XML::Parser::Expat::parse
33798 | 1 | 1 | 10.5ms | 10.5ms | XML::Parser::Expat::::SetNotationDeclHandler XML::Parser::Expat::SetNotationDeclHandler (xsub)
7 | 1 | 1 | 616µs | 616µs | XML::Parser::Expat::::ParserFree XML::Parser::Expat::ParserFree (xsub)
7 | 1 | 1 | 79µs | 126µs | XML::Parser::Expat::::new XML::Parser::Expat::new
28 | 1 | 1 | 66µs | 66µs | XML::Parser::Expat::::NamespaceStart XML::Parser::Expat::NamespaceStart
7 | 1 | 1 | 47µs | 47µs | XML::Parser::Expat::::ParserCreate XML::Parser::Expat::ParserCreate (xsub)
28 | 1 | 1 | 41µs | 41µs | XML::Parser::Expat::::NamespaceEnd XML::Parser::Expat::NamespaceEnd
7 | 1 | 1 | 15µs | 632µs | XML::Parser::Expat::::DESTROY XML::Parser::Expat::DESTROY
7 | 1 | 1 | 15µs | 18µs | XML::Parser::Expat::::release XML::Parser::Expat::release
1 | 1 | 1 | 10µs | 25µs | XML::Parser::ContentModel::::BEGIN@512XML::Parser::ContentModel::BEGIN@512
1 | 1 | 1 | 8µs | 10µs | XML::Parser::Expat::::BEGIN@3 XML::Parser::Expat::BEGIN@3
1 | 1 | 1 | 8µs | 9µs | XML::Parser::Expat::::BEGIN@7 XML::Parser::Expat::BEGIN@7
1 | 1 | 1 | 7µs | 14µs | XML::Parser::Expat::::BEGIN@460 XML::Parser::Expat::BEGIN@460
1 | 1 | 1 | 5µs | 27µs | XML::Parser::ExpatNB::::BEGIN@600 XML::Parser::ExpatNB::BEGIN@600
7 | 1 | 1 | 3µs | 3µs | XML::Parser::Expat::::ParserRelease XML::Parser::Expat::ParserRelease (xsub)
1 | 1 | 1 | 3µs | 21µs | XML::Parser::Expat::::BEGIN@8 XML::Parser::Expat::BEGIN@8
1 | 1 | 1 | 2µs | 2µs | XML::Parser::Expat::::BEGIN@14 XML::Parser::Expat::BEGIN@14
0 | 0 | 0 | 0s | 0s | XML::Parser::ContentModel::::asStringXML::Parser::ContentModel::asString
0 | 0 | 0 | 0s | 0s | XML::Parser::ContentModel::::childrenXML::Parser::ContentModel::children
0 | 0 | 0 | 0s | 0s | XML::Parser::ContentModel::::isanyXML::Parser::ContentModel::isany
0 | 0 | 0 | 0s | 0s | XML::Parser::ContentModel::::ischoiceXML::Parser::ContentModel::ischoice
0 | 0 | 0 | 0s | 0s | XML::Parser::ContentModel::::isemptyXML::Parser::ContentModel::isempty
0 | 0 | 0 | 0s | 0s | XML::Parser::ContentModel::::ismixedXML::Parser::ContentModel::ismixed
0 | 0 | 0 | 0s | 0s | XML::Parser::ContentModel::::isnameXML::Parser::ContentModel::isname
0 | 0 | 0 | 0s | 0s | XML::Parser::ContentModel::::isseqXML::Parser::ContentModel::isseq
0 | 0 | 0 | 0s | 0s | XML::Parser::ContentModel::::nameXML::Parser::ContentModel::name
0 | 0 | 0 | 0s | 0s | XML::Parser::ContentModel::::quantXML::Parser::ContentModel::quant
0 | 0 | 0 | 0s | 0s | XML::Parser::ContentModel::::thiseqXML::Parser::ContentModel::thiseq
0 | 0 | 0 | 0s | 0s | XML::Parser::Encinfo::::DESTROY XML::Parser::Encinfo::DESTROY
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::base XML::Parser::Expat::base
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::context XML::Parser::Expat::context
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::current_byte XML::Parser::Expat::current_byte
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::current_column XML::Parser::Expat::current_column
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::current_element XML::Parser::Expat::current_element
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::current_line XML::Parser::Expat::current_line
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::default_current XML::Parser::Expat::default_current
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::element_index XML::Parser::Expat::element_index
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::eq_name XML::Parser::Expat::eq_name
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::finish XML::Parser::Expat::finish
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::generate_ns_name XML::Parser::Expat::generate_ns_name
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::in_element XML::Parser::Expat::in_element
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::load_encoding XML::Parser::Expat::load_encoding
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::original_string XML::Parser::Expat::original_string
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::parsefile XML::Parser::Expat::parsefile
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::parsestring XML::Parser::Expat::parsestring
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::position_in_context XML::Parser::Expat::position_in_context
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::skip_until XML::Parser::Expat::skip_until
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::specified_attr XML::Parser::Expat::specified_attr
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::within_element XML::Parser::Expat::within_element
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::xml_escape XML::Parser::Expat::xml_escape
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::xpcarp XML::Parser::Expat::xpcarp
0 | 0 | 0 | 0s | 0s | XML::Parser::Expat::::xpcroak XML::Parser::Expat::xpcroak
0 | 0 | 0 | 0s | 0s | XML::Parser::ExpatNB::::parse XML::Parser::ExpatNB::parse
0 | 0 | 0 | 0s | 0s | XML::Parser::ExpatNB::::parse_done XML::Parser::ExpatNB::parse_done
0 | 0 | 0 | 0s | 0s | XML::Parser::ExpatNB::::parse_more XML::Parser::ExpatNB::parse_more
0 | 0 | 0 | 0s | 0s | XML::Parser::ExpatNB::::parsefile XML::Parser::ExpatNB::parsefile
0 | 0 | 0 | 0s | 0s | XML::Parser::ExpatNB::::parsestring XML::Parser::ExpatNB::parsestring

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package XML::Parser::Expat;
2 |  |  |  |  |
3 | 2 | 17µs | 2 | 11µs | # spent 10µs (8+1) within XML::Parser::Expat::BEGIN@3 which was called: # once (8µs+1µs) by XML::Parser::BEGIN@17 at line 3 use strict; # spent 10µs making 1 call to XML::Parser::Expat::BEGIN@3 # spent 1µs making 1 call to strict::import
4 |  |  |  |  |
5 |  |  |  |  | #use warnings; No warnings numeric??
6 |  |  |  |  |
7 | 2 | 13µs | 2 | 9µs | # spent 9µs (8+700ns) within XML::Parser::Expat::BEGIN@7 which was called: # once (8µs+700ns) by XML::Parser::BEGIN@17 at line 7 use XSLoader; # spent 9µs making 1 call to XML::Parser::Expat::BEGIN@7 # spent 700ns making 1 call to UNIVERSAL::import
8 | 2 | 34µs | 2 | 39µs | # spent 21µs (3+18) within XML::Parser::Expat::BEGIN@8 which was called: # once (3µs+18µs) by XML::Parser::BEGIN@17 at line 8 use Carp; # spent 21µs making 1 call to XML::Parser::Expat::BEGIN@8 # spent 18µs making 1 call to Exporter::import
9 |  |  |  |  |
10 | 1 | 300ns |  |  | our $VERSION = '2.47';
11 |  |  |  |  |
12 |  |  |  |  | our ( %Encoding_Table, @Encoding_Path, $have_File_Spec );
13 |  |  |  |  |
14 | 2 | 1.37ms | 1 | 2µs | # spent 2µs within XML::Parser::Expat::BEGIN@14 which was called: # once (2µs+0s) by XML::Parser::BEGIN@17 at line 14 use File::Spec (); # spent 2µs making 1 call to XML::Parser::Expat::BEGIN@14
15 |  |  |  |  |
16 | 1 | 300ns |  |  | %Encoding_Table = ();
17 | 1 | 500ns |  |  | if ($have_File_Spec) {
18 |  |  |  |  | @Encoding_Path = (
19 |  |  |  |  | grep( -d $_,
20 |  |  |  |  | map( File::Spec->catdir( $_, qw(XML Parser Encodings) ),
21 |  |  |  |  | @INC ) ),
22 |  |  |  |  | File::Spec->curdir
23 |  |  |  |  | );
24 |  |  |  |  | }
25 |  |  |  |  | else {
26 | 1 | 24µs | 5 | 12µs | @Encoding_Path = ( grep( -d $_, map( $_ . '/XML/Parser/Encodings', @INC ) ), '.' ); # spent 12µs making 5 calls to CORE::ftdir, avg 2µs/call
27 |  |  |  |  | }
28 |  |  |  |  |
29 | 1 | 208µs | 1 | 202µs | XSLoader::load( 'XML::Parser::Expat', $VERSION ); # spent 202µs making 1 call to XSLoader::load
30 |  |  |  |  |
31 | 1 | 4µs |  |  | our %Handler_Setters = (
32 |  |  |  |  | Start => \&SetStartElementHandler,
33 |  |  |  |  | End => \&SetEndElementHandler,
34 |  |  |  |  | Char => \&SetCharacterDataHandler,
35 |  |  |  |  | Proc => \&SetProcessingInstructionHandler,
36 |  |  |  |  | Comment => \&SetCommentHandler,
37 |  |  |  |  | CdataStart => \&SetStartCdataHandler,
38 |  |  |  |  | CdataEnd => \&SetEndCdataHandler,
39 |  |  |  |  | Default => \&SetDefaultHandler,
40 |  |  |  |  | Unparsed => \&SetUnparsedEntityDeclHandler,
41 |  |  |  |  | Notation => \&SetNotationDeclHandler,
42 |  |  |  |  | ExternEnt => \&SetExternalEntityRefHandler,
43 |  |  |  |  | ExternEntFin => \&SetExtEntFinishHandler,
44 |  |  |  |  | Entity => \&SetEntityDeclHandler,
45 |  |  |  |  | Element => \&SetElementDeclHandler,
46 |  |  |  |  | Attlist => \&SetAttListDeclHandler,
47 |  |  |  |  | Doctype => \&SetDoctypeHandler,
48 |  |  |  |  | DoctypeFin => \&SetEndDoctypeHandler,
49 |  |  |  |  | XMLDecl => \&SetXMLDeclHandler
50 |  |  |  |  | );
51 |  |  |  |  |
52 |  |  |  |  | # spent 126µs (79+47) within XML::Parser::Expat::new which was called 7 times, avg 18µs/call: # 7 times (79µs+47µs) by XML::Parser::parse at line 171 of XML/Parser.pm, avg 18µs/call sub new {
53 | 7 | 25µs |  |  | my ( $class, %args ) = @_;
54 | 7 | 4µs |  |  | my $self = bless \%args, $_[0];
55 | 7 | 2µs |  |  | $args{_State_} = 0;
56 | 7 | 3µs |  |  | $args{Context} = [];
57 | 7 | 2µs |  |  | $args{Namespaces} ||= 0;
58 | 7 | 2µs |  |  | $args{ErrorMessage} ||= '';
59 | 7 | 3µs |  |  | if ( $args{Namespaces} ) {
60 | 7 | 2µs |  |  | $args{Namespace_Table} = {};
61 | 7 | 3µs |  |  | $args{Namespace_List} = [undef];
62 | 7 | 3µs |  |  | $args{Prefix_Table} = {};
63 | 7 | 2µs |  |  | $args{New_Prefixes} = [];
64 |  |  |  |  | }
65 | 7 | 2µs |  |  | $args{_Setters} = \%Handler_Setters;
66 |  |  |  |  | $args{Parser} = ParserCreate(
67 |  |  |  |  | $self, $args{ProtocolEncoding},
68 |  |  |  |  | $args{Namespaces}
69 | 7 | 66µs | 7 | 47µs | ); # spent 47µs making 7 calls to XML::Parser::Expat::ParserCreate, avg 7µs/call
70 | 7 | 8µs |  |  | $self;
71 |  |  |  |  | }
72 |  |  |  |  |
73 |  |  |  |  | sub load_encoding {
74 |  |  |  |  | my ($file) = @_;
75 |  |  |  |  |
76 |  |  |  |  | $file =~ s!([^/]+)$!\L$1\E!;
77 |  |  |  |  | $file .= '.enc' unless $file =~ /\.enc$/;
78 |  |  |  |  | unless ( $file =~ m!^/! ) {
79 |  |  |  |  | foreach (@Encoding_Path) {
80 |  |  |  |  | my $tmp = (
81 |  |  |  |  | $have_File_Spec
82 |  |  |  |  | ? File::Spec->catfile( $_, $file )
83 |  |  |  |  | : "$_/$file"
84 |  |  |  |  | );
85 |  |  |  |  | if ( -e $tmp ) {
86 |  |  |  |  | $file = $tmp;
87 |  |  |  |  | last;
88 |  |  |  |  | }
89 |  |  |  |  | }
90 |  |  |  |  | }
91 |  |  |  |  |
92 |  |  |  |  | open( my $fh, '<', $file ) or croak("Couldn't open encmap $file:\n$!\n");
93 |  |  |  |  | binmode($fh);
94 |  |  |  |  | my $data;
95 |  |  |  |  | my $br = sysread( $fh, $data, -s $file );
96 |  |  |  |  | croak("Trouble reading $file:\n$!\n")
97 |  |  |  |  | unless defined($br);
98 |  |  |  |  | close($fh);
99 |  |  |  |  |
100 |  |  |  |  | my $name = LoadEncoding( $data, $br );
101 |  |  |  |  | croak("$file isn't an encmap file")
102 |  |  |  |  | unless defined($name);
103 |  |  |  |  |
104 |  |  |  |  | $name;
105 |  |  |  |  | } # End load_encoding
106 |  |  |  |  |
107 |  |  |  |  | # spent 3.36s (3.07+290ms) within XML::Parser::Expat::setHandlers which was called 67598 times, avg 50µs/call: # 33792 times (1.56s+140ms) by XML::Twig::_twig_start_check_roots at line 4144 of XML/Twig.pm, avg 50µs/call # 33792 times (1.51s+150ms) by XML::Twig::_twig_end at line 2371 of XML/Twig.pm, avg 49µs/call # 7 times (218µs+44µs) by XML::Parser::parse at line 176 of XML/Parser.pm, avg 38µs/call # 6 times (26µs+4µs) by XML::Twig::_twig_start at line 2117 of XML/Twig.pm, avg 5µs/call # once (8µs+900ns) by XML::Twig::_twig_start at line 2112 of XML/Twig.pm sub setHandlers {
108 | 67598 | 90.9ms |  |  | my ( $self, @handler_pairs ) = @_;
109 |  |  |  |  |
110 | 67598 | 19.7ms |  |  | croak("Uneven number of arguments to setHandlers method")
111 |  |  |  |  | if ( int(@handler_pairs) & 1 );
112 |  |  |  |  |
113 | 67598 | 6.83ms |  |  | my @ret;
114 |  |  |  |  |
115 | 67598 | 14.7ms |  |  | while (@handler_pairs) {
116 | 980079 | 107ms |  |  | my $type = shift @handler_pairs;
117 | 980079 | 84.3ms |  |  | my $handler = shift @handler_pairs;
118 | 980079 | 141ms |  |  | croak 'Handler for $type not a Code ref'
119 |  |  |  |  | unless ( !defined($handler) or !$handler or ref($handler) eq 'CODE' );
120 |  |  |  |  |
121 | 980079 | 152ms |  |  | my $hndl = $self->{_Setters}->{$type};
122 |  |  |  |  |
123 | 980079 | 64.9ms |  |  | unless ( defined($hndl) ) {
124 |  |  |  |  | my @types = sort keys %{ $self->{_Setters} };
125 |  |  |  |  | croak("Unknown Expat handler type: $type\n Valid types: @types");
126 |  |  |  |  | }
127 |  |  |  |  |
128 | 980079 | 2.30s | 980079 | 290ms | my $old = &$hndl( $self->{Parser}, $handler ); # spent 26.8ms making 67591 calls to XML::Parser::Expat::SetXMLDeclHandler, avg 396ns/call # spent 22.2ms making 67591 calls to XML::Parser::Expat::SetEndElementHandler, avg 329ns/call # spent 21.1ms making 67591 calls to XML::Parser::Expat::SetEntityDeclHandler, avg 312ns/call # spent 20.8ms making 67591 calls to XML::Parser::Expat::SetAttListDeclHandler, avg 308ns/call # spent 20.5ms making 67591 calls to XML::Parser::Expat::SetCommentHandler, avg 303ns/call # spent 20.4ms making 67591 calls to XML::Parser::Expat::SetCharacterDataHandler, avg 301ns/call # spent 20.2ms making 67591 calls to XML::Parser::Expat::SetEndCdataHandler, avg 299ns/call # spent 20.1ms making 67591 calls to XML::Parser::Expat::SetExternalEntityRefHandler, avg 298ns/call # spent 19.4ms making 67591 calls to XML::Parser::Expat::SetElementDeclHandler, avg 287ns/call # spent 18.9ms making 67591 calls to XML::Parser::Expat::SetStartCdataHandler, avg 279ns/call # spent 17.8ms making 67591 calls to XML::Parser::Expat::SetDoctypeHandler, avg 264ns/call # spent 17.8ms making 67591 calls to XML::Parser::Expat::SetProcessingInstructionHandler, avg 263ns/call # spent 17.4ms making 67598 calls to XML::Parser::Expat::SetDefaultHandler, avg 258ns/call # spent 15.7ms making 67591 calls to XML::Parser::Expat::SetStartElementHandler, avg 232ns/call # spent 10.5ms making 33798 calls to XML::Parser::Expat::SetNotationDeclHandler, avg 310ns/call
129 | 980079 | 313ms |  |  | push( @ret, $type, $old );
130 |  |  |  |  | }
131 |  |  |  |  |
132 | 67598 | 173ms |  |  | return @ret;
133 |  |  |  |  | }
134 |  |  |  |  |
135 |  |  |  |  | sub xpcroak {
136 |  |  |  |  | my ( $self, $message ) = @_;
137 |  |  |  |  |
138 |  |  |  |  | my $eclines = $self->{ErrorContext};
139 |  |  |  |  | my $line = GetCurrentLineNumber( $_[0]->{Parser} );
140 |  |  |  |  | $message .= " at line $line";
141 |  |  |  |  | $message .= ":\n" . $self->position_in_context($eclines)
142 |  |  |  |  | if defined($eclines);
143 |  |  |  |  | croak $message;
144 |  |  |  |  | }
145 |  |  |  |  |
146 |  |  |  |  | sub xpcarp {
147 |  |  |  |  | my ( $self, $message ) = @_;
148 |  |  |  |  |
149 |  |  |  |  | my $eclines = $self->{ErrorContext};
150 |  |  |  |  | my $line = GetCurrentLineNumber( $_[0]->{Parser} );
151 |  |  |  |  | $message .= ' at line $line';
152 |  |  |  |  | $message .= ":\n" . $self->position_in_context($eclines)
153 |  |  |  |  | if defined($eclines);
154 |  |  |  |  | carp $message;
155 |  |  |  |  | }
156 |  |  |  |  |
157 |  |  |  |  | sub default_current {
158 |  |  |  |  | my $self = shift;
159 |  |  |  |  | if ( $self->{_State_} == 1 ) {
160 |  |  |  |  | return DefaultCurrent( $self->{Parser} );
161 |  |  |  |  | }
162 |  |  |  |  | }
163 |  |  |  |  |
164 |  |  |  |  | # spent 1.31s (1.09+223ms) within XML::Parser::Expat::recognized_string which was called 364369 times, avg 4µs/call: # 364369 times (1.09s+223ms) by XML::Twig::_twig_start at line 2120 of XML/Twig.pm, avg 4µs/call sub recognized_string {
165 | 364369 | 38.6ms |  |  | my $self = shift;
166 | 364369 | 1.98s | 364369 | 223ms | if ( $self->{_State_} == 1 ) { # spent 223ms making 364369 calls to XML::Parser::Expat::RecognizedString, avg 613ns/call
167 |  |  |  |  | return RecognizedString( $self->{Parser} );
168 |  |  |  |  | }
169 |  |  |  |  | }
170 |  |  |  |  |
171 |  |  |  |  | sub original_string {
172 |  |  |  |  | my $self = shift;
173 |  |  |  |  | if ( $self->{_State_} == 1 ) {
174 |  |  |  |  | return OriginalString( $self->{Parser} );
175 |  |  |  |  | }
176 |  |  |  |  | }
177 |  |  |  |  |
178 |  |  |  |  | sub current_line {
179 |  |  |  |  | my $self = shift;
180 |  |  |  |  | if ( $self->{_State_} == 1 ) {
181 |  |  |  |  | return GetCurrentLineNumber( $self->{Parser} );
182 |  |  |  |  | }
183 |  |  |  |  | }
184 |  |  |  |  |
185 |  |  |  |  | sub current_column {
186 |  |  |  |  | my $self = shift;
187 |  |  |  |  | if ( $self->{_State_} == 1 ) {
188 |  |  |  |  | return GetCurrentColumnNumber( $self->{Parser} );
189 |  |  |  |  | }
190 |  |  |  |  | }
191 |  |  |  |  |
192 |  |  |  |  | sub current_byte {
193 |  |  |  |  | my $self = shift;
194 |  |  |  |  | if ( $self->{_State_} == 1 ) {
195 |  |  |  |  | return GetCurrentByteIndex( $self->{Parser} );
196 |  |  |  |  | }
197 |  |  |  |  | }
198 |  |  |  |  |
199 |  |  |  |  | sub base {
200 |  |  |  |  | my ( $self, $newbase ) = @_;
201 |  |  |  |  | my $p = $self->{Parser};
202 |  |  |  |  | my $oldbase = GetBase($p);
203 |  |  |  |  | SetBase( $p, $newbase ) if @_ > 1;
204 |  |  |  |  | return $oldbase;
205 |  |  |  |  | }
206 |  |  |  |  |
207 |  |  |  |  | sub context {
208 |  |  |  |  | my $ctx = $_[0]->{Context};
209 |  |  |  |  | @$ctx;
210 |  |  |  |  | }
211 |  |  |  |  |
212 |  |  |  |  | sub current_element {
213 |  |  |  |  | my ($self) = @_;
214 |  |  |  |  | @{ $self->{Context} } ? $self->{Context}->[-1] : undef;
215 |  |  |  |  | }
216 |  |  |  |  |
217 |  |  |  |  | sub in_element {
218 |  |  |  |  | my ( $self, $element ) = @_;
219 |  |  |  |  | @{ $self->{Context} }
220 |  |  |  |  | ? $self->eq_name( $self->{Context}->[-1], $element )
221 |  |  |  |  | : undef;
222 |  |  |  |  | }
223 |  |  |  |  |
224 |  |  |  |  | sub within_element {
225 |  |  |  |  | my ( $self, $element ) = @_;
226 |  |  |  |  | my $cnt = 0;
227 |  |  |  |  | foreach ( @{ $self->{Context} } ) {
228 |  |  |  |  | $cnt++ if $self->eq_name( $_, $element );
229 |  |  |  |  | }
230 |  |  |  |  | return $cnt;
231 |  |  |  |  | }
232 |  |  |  |  |
233 |  |  |  |  | # spent 221ms within XML::Parser::Expat::depth which was called 431581 times, avg 513ns/call: # 363976 times (180ms+0s) by XML::Twig::_twig_end at line 2360 of XML/Twig.pm, avg 494ns/call # 33799 times (21.4ms+0s) by XML::Twig::_twig_start_check_roots at line 4134 of XML/Twig.pm, avg 633ns/call # 33792 times (20.3ms+0s) by XML::Twig::_twig_start_check_roots at line 4145 of XML/Twig.pm, avg 600ns/call # 7 times (3µs+0s) by XML::Twig::_twig_start_check_roots at line 4156 of XML/Twig.pm, avg 471ns/call # 7 times (3µs+0s) by XML::Twig::_twig_end_check_roots at line 4214 of XML/Twig.pm, avg 457ns/call sub depth {
234 | 431581 | 45.7ms |  |  | my ($self) = @_;
235 | 431581 | 868ms |  |  | int( @{ $self->{Context} } );
236 |  |  |  |  | }
237 |  |  |  |  |
238 |  |  |  |  | sub element_index {
239 |  |  |  |  | my ($self) = @_;
240 |  |  |  |  |
241 |  |  |  |  | if ( $self->{_State_} == 1 ) {
242 |  |  |  |  | return ElementIndex( $self->{Parser} );
243 |  |  |  |  | }
244 |  |  |  |  | }
245 |  |  |  |  |
246 |  |  |  |  | ################
247 |  |  |  |  | # Namespace methods
248 |  |  |  |  |
249 |  |  |  |  | # spent 1.73s within XML::Parser::Expat::namespace which was called 1460048 times, avg 1µs/call: # 1095679 times (1.29s+0s) by XML::Twig::_ns_info at line 2218 of XML/Twig.pm, avg 1µs/call # 364369 times (448ms+0s) by XML::Twig::_replace_prefix at line 2426 of XML/Twig.pm, avg 1µs/call sub namespace {
250 | 1460048 | 178ms |  |  | my ( $self, $name ) = @_;
251 | 1460048 | 659ms |  |  | local ($^W) = 0;
252 | 1460048 | 3.46s |  |  | $self->{Namespace_List}->[ int($name) ];
253 |  |  |  |  | }
254 |  |  |  |  |
255 |  |  |  |  | sub eq_name {
256 |  |  |  |  | my ( $self, $nm1, $nm2 ) = @_;
257 |  |  |  |  | local ($^W) = 0;
258 |  |  |  |  |
259 |  |  |  |  | int($nm1) == int($nm2) and $nm1 eq $nm2;
260 |  |  |  |  | }
261 |  |  |  |  |
262 |  |  |  |  | sub generate_ns_name {
263 |  |  |  |  | my ( $self, $name, $namespace ) = @_;
264 |  |  |  |  |
265 |  |  |  |  | $namespace
266 |  |  |  |  | ? GenerateNSName(
267 |  |  |  |  | $name, $namespace, $self->{Namespace_Table},
268 |  |  |  |  | $self->{Namespace_List}
269 |  |  |  |  | )
270 |  |  |  |  | : $name;
271 |  |  |  |  | }
272 |  |  |  |  |
273 |  |  |  |  | # spent 243ms within XML::Parser::Expat::new_ns_prefixes which was called 398167 times, avg 611ns/call: # 398167 times (243ms+0s) by XML::Twig::_replace_ns at line 2162 of XML/Twig.pm, avg 611ns/call sub new_ns_prefixes {
274 | 398167 | 39.4ms |  |  | my ($self) = @_;
275 | 398167 | 974ms |  |  | if ( $self->{Namespaces} ) {
276 |  |  |  |  | return @{ $self->{New_Prefixes} };
277 |  |  |  |  | }
278 |  |  |  |  | return ();
279 |  |  |  |  | }
280 |  |  |  |  |
281 |  |  |  |  | # spent 1.31s within XML::Parser::Expat::expand_ns_prefix which was called 1520689 times, avg 864ns/call: # 1520661 times (1.31s+0s) by XML::Twig::_a_proper_ns_prefix at line 2230 of XML/Twig.pm, avg 864ns/call # 28 times (33µs+0s) by XML::Twig::_replace_ns at line 2163 of XML/Twig.pm, avg 1µs/call sub expand_ns_prefix {
282 | 1520689 | 214ms |  |  | my ( $self, $prefix ) = @_;
283 |  |  |  |  |
284 | 1520689 | 158ms |  |  | if ( $self->{Namespaces} ) {
285 | 1520689 | 365ms |  |  | my $stack = $self->{Prefix_Table}->{$prefix};
286 | 1520689 | 3.57s |  |  | return ( defined($stack) and @$stack ) ? $stack->[-1] : undef;
287 |  |  |  |  | }
288 |  |  |  |  |
289 |  |  |  |  | return undef;
290 |  |  |  |  | }
291 |  |  |  |  |
292 |  |  |  |  | # spent 1.51s within XML::Parser::Expat::current_ns_prefixes which was called 380001 times, avg 4µs/call: # 380001 times (1.51s+0s) by XML::Twig::_a_proper_ns_prefix at line 2229 of XML/Twig.pm, avg 4µs/call sub current_ns_prefixes {
293 | 380001 | 42.5ms |  |  | my ($self) = @_;
294 |  |  |  |  |
295 | 380001 | 61.6ms |  |  | if ( $self->{Namespaces} ) {
296 | 380001 | 828ms |  |  | my %set = %{ $self->{Prefix_Table} };
297 |  |  |  |  |
298 | 380001 | 112ms |  |  | if ( exists $set{'#default'} and not defined( $set{'#default'}->[-1] ) ) {
299 |  |  |  |  | delete $set{'#default'};
300 |  |  |  |  | }
301 |  |  |  |  |
302 | 380001 | 1.24s |  |  | return keys %set;
303 |  |  |  |  | }
304 |  |  |  |  |
305 |  |  |  |  | return ();
306 |  |  |  |  | }
307 |  |  |  |  |
308 |  |  |  |  | ################################################################
309 |  |  |  |  | # Namespace declaration handlers
310 |  |  |  |  | #
311 |  |  |  |  |
312 |  |  |  |  | # spent 66µs within XML::Parser::Expat::NamespaceStart which was called 28 times, avg 2µs/call: # 28 times (66µs+0s) by XML::Parser::Expat::ParseString at line 486, avg 2µs/call sub NamespaceStart {
313 | 28 | 7µs |  |  | my ( $self, $prefix, $uri ) = @_;
314 |  |  |  |  |
315 | 28 | 6µs |  |  | $prefix = '#default' unless defined $prefix;
316 | 28 | 10µs |  |  | my $stack = $self->{Prefix_Table}->{$prefix};
317 |  |  |  |  |
318 | 28 | 6µs |  |  | if ( defined $stack ) {
319 |  |  |  |  | push( @$stack, $uri );
320 |  |  |  |  | }
321 |  |  |  |  | else {
322 | 27 | 17µs |  |  | $self->{Prefix_Table}->{$prefix} = [$uri];
323 |  |  |  |  | }
324 |  |  |  |  |
325 |  |  |  |  | # The New_Prefixes list gets emptied at end of startElement function
326 |  |  |  |  | # in Expat.xs
327 |  |  |  |  |
328 | 28 | 31µs |  |  | push( @{ $self->{New_Prefixes} }, $prefix );
329 |  |  |  |  | }
330 |  |  |  |  |
331 |  |  |  |  | # spent 41µs within XML::Parser::Expat::NamespaceEnd which was called 28 times, avg 1µs/call: # 28 times (41µs+0s) by XML::Parser::Expat::ParseString at line 486, avg 1µs/call sub NamespaceEnd {
332 | 28 | 5µs |  |  | my ( $self, $prefix ) = @_;
333 |  |  |  |  |
334 | 28 | 5µs |  |  | $prefix = '#default' unless defined $prefix;
335 |  |  |  |  |
336 | 28 | 8µs |  |  | my $stack = $self->{Prefix_Table}->{$prefix};
337 | 28 | 26µs |  |  | if ( @$stack > 1 ) {
338 |  |  |  |  | pop(@$stack);
339 |  |  |  |  | }
340 |  |  |  |  | else {
341 | 27 | 9µs |  |  | delete $self->{Prefix_Table}->{$prefix};
342 |  |  |  |  | }
343 |  |  |  |  | }
344 |  |  |  |  |
345 |  |  |  |  | ################
346 |  |  |  |  |
347 |  |  |  |  | sub specified_attr {
348 |  |  |  |  | my $self = shift;
349 |  |  |  |  |
350 |  |  |  |  | if ( $self->{_State_} == 1 ) {
351 |  |  |  |  | return GetSpecifiedAttributeCount( $self->{Parser} );
352 |  |  |  |  | }
353 |  |  |  |  | }
354 |  |  |  |  |
355 |  |  |  |  | sub finish {
356 |  |  |  |  | my ($self) = @_;
357 |  |  |  |  | if ( $self->{_State_} == 1 ) {
358 |  |  |  |  | my $parser = $self->{Parser};
359 |  |  |  |  | UnsetAllHandlers($parser);
360 |  |  |  |  | }
361 |  |  |  |  | }
362 |  |  |  |  |
363 |  |  |  |  | sub position_in_context {
364 |  |  |  |  | my ( $self, $lines ) = @_;
365 |  |  |  |  | if ( $self->{_State_} == 1 ) {
366 |  |  |  |  | my $parser = $self->{Parser};
367 |  |  |  |  | my ( $string, $linepos ) = PositionContext( $parser, $lines );
368 |  |  |  |  |
369 |  |  |  |  | return '' unless defined($string);
370 |  |  |  |  |
371 |  |  |  |  | my $col = GetCurrentColumnNumber($parser);
372 |  |  |  |  | my $ptr = ( '=' x ( $col - 1 ) ) . '^' . "\n";
373 |  |  |  |  | my $ret;
374 |  |  |  |  | my $dosplit = $linepos < length($string);
375 |  |  |  |  |
376 |  |  |  |  | $string .= "\n" unless $string =~ /\n$/;
377 |  |  |  |  |
378 |  |  |  |  | if ($dosplit) {
379 |  |  |  |  | $ret = substr( $string, 0, $linepos ) . $ptr . substr( $string, $linepos );
380 |  |  |  |  | }
381 |  |  |  |  | else {
382 |  |  |  |  | $ret = $string . $ptr;
383 |  |  |  |  | }
384 |  |  |  |  |
385 |  |  |  |  | return $ret;
386 |  |  |  |  | }
387 |  |  |  |  | }
388 |  |  |  |  |
389 |  |  |  |  | sub xml_escape {
390 |  |  |  |  | my $self = shift;
391 |  |  |  |  | my $text = shift;
392 |  |  |  |  |
393 |  |  |  |  | study $text;
394 |  |  |  |  | $text =~ s/\&/\&amp;/g;
395 |  |  |  |  | $text =~ s/</\&lt;/g;
396 |  |  |  |  | foreach (@_) {
397 |  |  |  |  | croak "xml_escape: '$_' isn't a single character" if length($_) > 1;
398 |  |  |  |  |
399 |  |  |  |  | if ( $_ eq '>' ) {
400 |  |  |  |  | $text =~ s/>/\&gt;/g;
401 |  |  |  |  | }
402 |  |  |  |  | elsif ( $_ eq '"' ) {
403 |  |  |  |  | $text =~ s/\"/\&quot;/;
404 |  |  |  |  | }
405 |  |  |  |  | elsif ( $_ eq "'" ) {
406 |  |  |  |  | $text =~ s/\'/\&apos;/;
407 |  |  |  |  | }
408 |  |  |  |  | else {
409 |  |  |  |  | my $rep = '&#' . sprintf( 'x%X', ord($_) ) . ';';
410 |  |  |  |  | if (/\W/) {
411 |  |  |  |  | my $ptrn = "\\$_";
412 |  |  |  |  | $text =~ s/$ptrn/$rep/g;
413 |  |  |  |  | }
414 |  |  |  |  | else {
415 |  |  |  |  | $text =~ s/$_/$rep/g;
416 |  |  |  |  | }
417 |  |  |  |  | }
418 |  |  |  |  | }
419 |  |  |  |  | $text;
420 |  |  |  |  | }
421 |  |  |  |  |
422 |  |  |  |  | sub skip_until {
423 |  |  |  |  | my $self = shift;
424 |  |  |  |  | if ( $self->{_State_} <= 1 ) {
425 |  |  |  |  | SkipUntil( $self->{Parser}, $_[0] );
426 |  |  |  |  | }
427 |  |  |  |  | }
428 |  |  |  |  |
429 |  |  |  |  | # spent 18µs (15+3) within XML::Parser::Expat::release which was called 7 times, avg 3µs/call: # 7 times (15µs+3µs) by XML::Parser::parse at line 203 of XML/Parser.pm, avg 3µs/call sub release {
430 | 7 | 1µs |  |  | my $self = shift;
431 | 7 | 18µs | 7 | 3µs | ParserRelease( $self->{Parser} ); # spent 3µs making 7 calls to XML::Parser::Expat::ParserRelease, avg 486ns/call
432 |  |  |  |  | }
433 |  |  |  |  |
434 |  |  |  |  | # spent 632µs (15+616) within XML::Parser::Expat::DESTROY which was called 7 times, avg 90µs/call: # 7 times (15µs+616µs) by XML::Parser::parse at line 206 of XML/Parser.pm, avg 90µs/call sub DESTROY {
435 | 7 | 1µs |  |  | my $self = shift;
436 | 7 | 634µs | 7 | 616µs | ParserFree( $self->{Parser} ); # spent 616µs making 7 calls to XML::Parser::Expat::ParserFree, avg 88µs/call
437 |  |  |  |  | }
438 |  |  |  |  |
439 |  |  |  |  | # spent 70.4s (12.0ms+70.4) within XML::Parser::Expat::parse which was called 7 times, avg 10.1s/call: # 7 times (12.0ms+70.4s) by XML::Parser::parse at line 187 of XML/Parser.pm, avg 10.1s/call sub parse {
440 | 7 | 1µs |  |  | my $self = shift;
441 | 7 | 1µs |  |  | my $arg = shift;
442 | 7 | 2µs |  |  | croak 'Parse already in progress (Expat)' if $self->{_State_};
443 | 7 | 3µs |  |  | $self->{_State_} = 1;
444 | 7 | 2µs |  |  | my $parser = $self->{Parser};
445 | 7 | 500ns |  |  | my $ioref;
446 | 7 | 400ns |  |  | my $result = 0;
447 |  |  |  |  |
448 | 7 | 2µs |  |  | if ( defined $arg ) {
449 | 7 | 5µs |  |  | local *@;
450 | 7 | 6µs |  |  | if ( ref($arg) and UNIVERSAL::isa( $arg, 'IO::Handle' ) ) {
451 |  |  |  |  | $ioref = $arg;
452 |  |  |  |  | }
453 |  |  |  |  | elsif ( $] < 5.008 and defined tied($arg) ) {
454 |  |  |  |  | require IO::Handle;
455 |  |  |  |  | $ioref = $arg;
456 |  |  |  |  | }
457 |  |  |  |  | else {
458 | 7 | 3µs |  |  | require IO::Handle;
459 | 7 | 2µs |  |  | eval {
460 | 2 | 203µs | 2 | 20µs | # spent 14µs (7+6) within XML::Parser::Expat::BEGIN@460 which was called: # once (7µs+6µs) by XML::Parser::BEGIN@17 at line 460 no strict 'refs'; # spent 14µs making 1 call to XML::Parser::Expat::BEGIN@460 # spent 6µs making 1 call to strict::unimport
461 | 7 | 11.9ms |  |  | $ioref = *{$arg}{IO} if defined *{$arg};
462 |  |  |  |  | };
463 | 7 | 2µs |  |  | if ( ref($ioref) eq 'FileHandle' ) {
464 |  |  |  |  |
465 |  |  |  |  | #for perl 5.10.x and possibly earlier, see t/file_open_scalar.t
466 |  |  |  |  | require FileHandle;
467 |  |  |  |  | }
468 |  |  |  |  | }
469 |  |  |  |  | }
470 |  |  |  |  |
471 | 7 | 3µs |  |  | if ( defined($ioref) ) {
472 |  |  |  |  | my $delim = $self->{Stream_Delimiter};
473 |  |  |  |  | my $prev_rs;
474 |  |  |  |  | my $ioclass = ref $ioref;
475 |  |  |  |  | $ioclass = 'IO::Handle' if !length $ioclass;
476 |  |  |  |  |
477 |  |  |  |  | $prev_rs = $ioclass->input_record_separator("\n$delim\n")
478 |  |  |  |  | if defined($delim);
479 |  |  |  |  |
480 |  |  |  |  | $result = ParseStream( $parser, $ioref, $delim );
481 |  |  |  |  |
482 |  |  |  |  | $ioclass->input_record_separator($prev_rs)
483 |  |  |  |  | if defined($delim);
484 |  |  |  |  | }
485 |  |  |  |  | else {
486 | 7 | 1.34s | 856119 | 138s | $result = ParseString( $parser, $arg ); # spent 70.4s making 7 calls to XML::Parser::Expat::ParseString, avg 10.1s/call # spent 32.4s making 330576 calls to XML::Twig::_twig_start, avg 98µs/call # spent 25.4s making 364368 calls to XML::Twig::_twig_end, avg 70µs/call # spent 8.21s making 33799 calls to XML::Twig::_twig_start_check_roots, avg 243µs/call # spent 1.91s making 127292 calls to XML::Twig::_twig_char, avg 15µs/call # spent 80µs making 7 calls to XML::Twig::_twig_end_check_roots, avg 11µs/call # spent 66µs making 28 calls to XML::Parser::Expat::NamespaceStart, avg 2µs/call # spent 41µs making 28 calls to XML::Parser::Expat::NamespaceEnd, avg 1µs/call # spent 32µs making 7 calls to XML::Twig::_twig_xmldecl, avg 5µs/call # spent 23µs making 6 calls to XML::Twig::_twig_default, avg 4µs/call # spent 2µs making 1 call to XML::Twig::__ANON__[XML/Twig.pm:265]
487 |  |  |  |  | }
488 |  |  |  |  |
489 | 7 | 2µs |  |  | $self->{_State_} = 2;
490 | 7 | 10µs |  |  | $result or croak $self->{ErrorMessage};
491 |  |  |  |  | }
492 |  |  |  |  |
493 |  |  |  |  | sub parsestring {
494 |  |  |  |  | my $self = shift;
495 |  |  |  |  | $self->parse(@_);
496 |  |  |  |  | }
497 |  |  |  |  |
498 |  |  |  |  | sub parsefile {
499 |  |  |  |  | my $self = shift;
500 |  |  |  |  | croak 'Parser has already been used' if $self->{_State_};
501 |  |  |  |  |
502 |  |  |  |  | open( my $fh, '<', $_[0] ) or croak "Couldn't open $_[0]:\n$!";
503 |  |  |  |  | binmode($fh);
504 |  |  |  |  | my $ret = $self->parse($fh);
505 |  |  |  |  | close($fh);
506 |  |  |  |  | $ret;
507 |  |  |  |  | }
508 |  |  |  |  |
509 |  |  |  |  | ################################################################
510 |  |  |  |  | package #hide from PAUSE
511 |  |  |  |  | XML::Parser::ContentModel;
512 | 2 | 277µs | 2 | 40µs | # spent 25µs (10+15) within XML::Parser::ContentModel::BEGIN@512 which was called: # once (10µs+15µs) by XML::Parser::BEGIN@17 at line 512 use overload '""' => \&asString, 'eq' => \&thiseq; # spent 25µs making 1 call to XML::Parser::ContentModel::BEGIN@512 # spent 15µs making 1 call to overload::import
513 |  |  |  |  |
514 |  |  |  |  | sub EMPTY () { 1 }
515 |  |  |  |  | sub ANY () { 2 }
516 |  |  |  |  | sub MIXED () { 3 }
517 |  |  |  |  | sub NAME () { 4 }
518 |  |  |  |  | sub CHOICE () { 5 }
519 |  |  |  |  | sub SEQ () { 6 }
520 |  |  |  |  |
521 |  |  |  |  | sub isempty {
522 |  |  |  |  | return $_[0]->{Type} == EMPTY;
523 |  |  |  |  | }
524 |  |  |  |  |
525 |  |  |  |  | sub isany {
526 |  |  |  |  | return $_[0]->{Type} == ANY;
527 |  |  |  |  | }
528 |  |  |  |  |
529 |  |  |  |  | sub ismixed {
530 |  |  |  |  | return $_[0]->{Type} == MIXED;
531 |  |  |  |  | }
532 |  |  |  |  |
533 |  |  |  |  | sub isname {
534 |  |  |  |  | return $_[0]->{Type} == NAME;
535 |  |  |  |  | }
536 |  |  |  |  |
537 |  |  |  |  | sub name {
538 |  |  |  |  | return $_[0]->{Tag};
539 |  |  |  |  | }
540 |  |  |  |  |
541 |  |  |  |  | sub ischoice {
542 |  |  |  |  | return $_[0]->{Type} == CHOICE;
543 |  |  |  |  | }
544 |  |  |  |  |
545 |  |  |  |  | sub isseq {
546 |  |  |  |  | return $_[0]->{Type} == SEQ;
547 |  |  |  |  | }
548 |  |  |  |  |
549 |  |  |  |  | sub quant {
550 |  |  |  |  | return $_[0]->{Quant};
551 |  |  |  |  | }
552 |  |  |  |  |
553 |  |  |  |  | sub children {
554 |  |  |  |  | my $children = $_[0]->{Children};
555 |  |  |  |  | if ( defined $children ) {
556 |  |  |  |  | return @$children;
557 |  |  |  |  | }
558 |  |  |  |  | return undef;
559 |  |  |  |  | }
560 |  |  |  |  |
561 |  |  |  |  | sub asString {
562 |  |  |  |  | my ($self) = @_;
563 |  |  |  |  | my $ret;
564 |  |  |  |  |
565 |  |  |  |  | if ( $self->{Type} == NAME ) {
566 |  |  |  |  | $ret = $self->{Tag};
567 |  |  |  |  | }
568 |  |  |  |  | elsif ( $self->{Type} == EMPTY ) {
569 |  |  |  |  | return 'EMPTY';
570 |  |  |  |  | }
571 |  |  |  |  | elsif ( $self->{Type} == ANY ) {
572 |  |  |  |  | return 'ANY';
573 |  |  |  |  | }
574 |  |  |  |  | elsif ( $self->{Type} == MIXED ) {
575 |  |  |  |  | $ret = '(#PCDATA';
576 |  |  |  |  | foreach ( @{ $self->{Children} } ) {
577 |  |  |  |  | $ret .= '|' . $_;
578 |  |  |  |  | }
579 |  |  |  |  | $ret .= ')';
580 |  |  |  |  | }
581 |  |  |  |  | else {
582 |  |  |  |  | my $sep = $self->{Type} == CHOICE ? '|' : ',';
583 |  |  |  |  | $ret = '(' . join( $sep, map { $_->asString } @{ $self->{Children} } ) . ')';
584 |  |  |  |  | }
585 |  |  |  |  |
586 |  |  |  |  | $ret .= $self->{Quant} if $self->{Quant};
587 |  |  |  |  | return $ret;
588 |  |  |  |  | }
589 |  |  |  |  |
590 |  |  |  |  | sub thiseq {
591 |  |  |  |  | my $self = shift;
592 |  |  |  |  |
593 |  |  |  |  | return $self->asString eq $_[0];
594 |  |  |  |  | }
595 |  |  |  |  |
596 |  |  |  |  | ################################################################
597 |  |  |  |  | package #hide from PAUSE
598 |  |  |  |  | XML::Parser::ExpatNB;
599 |  |  |  |  |
600 | 2 | 223µs | 2 | 49µs | # spent 27µs (5+22) within XML::Parser::ExpatNB::BEGIN@600 which was called: # once (5µs+22µs) by XML::Parser::BEGIN@17 at line 600 use Carp; # spent 27µs making 1 call to XML::Parser::ExpatNB::BEGIN@600 # spent 22µs making 1 call to Exporter::import
601 |  |  |  |  |
602 | 1 | 5µs |  |  | our @ISA = qw(XML::Parser::Expat);
603 |  |  |  |  |
604 |  |  |  |  | sub parse {
605 |  |  |  |  | my $self = shift;
606 |  |  |  |  | my $class = ref($self);
607 |  |  |  |  | croak "parse method not supported in $class";
608 |  |  |  |  | }
609 |  |  |  |  |
610 |  |  |  |  | sub parsestring {
611 |  |  |  |  | my $self = shift;
612 |  |  |  |  | my $class = ref($self);
613 |  |  |  |  | croak "parsestring method not supported in $class";
614 |  |  |  |  | }
615 |  |  |  |  |
616 |  |  |  |  | sub parsefile {
617 |  |  |  |  | my $self = shift;
618 |  |  |  |  | my $class = ref($self);
619 |  |  |  |  | croak "parsefile method not supported in $class";
620 |  |  |  |  | }
621 |  |  |  |  |
622 |  |  |  |  | sub parse_more {
623 |  |  |  |  | my ( $self, $data ) = @_;
624 |  |  |  |  |
625 |  |  |  |  | $self->{_State_} = 1;
626 |  |  |  |  | my $ret = XML::Parser::Expat::ParsePartial( $self->{Parser}, $data );
627 |  |  |  |  |
628 |  |  |  |  | croak $self->{ErrorMessage} unless $ret;
629 |  |  |  |  | }
630 |  |  |  |  |
631 |  |  |  |  | sub parse_done {
632 |  |  |  |  | my $self = shift;
633 |  |  |  |  |
634 |  |  |  |  | my $ret = XML::Parser::Expat::ParseDone( $self->{Parser} );
635 |  |  |  |  | unless ($ret) {
636 |  |  |  |  | my $msg = $self->{ErrorMessage};
637 |  |  |  |  | $self->release;
638 |  |  |  |  | croak $msg;
639 |  |  |  |  | }
640 |  |  |  |  |
641 |  |  |  |  | $self->{_State_} = 2;
642 |  |  |  |  |
643 |  |  |  |  | my $result = $ret;
644 |  |  |  |  | my @result = ();
645 |  |  |  |  | my $final = $self->{FinalHandler};
646 |  |  |  |  | if ( defined $final ) {
647 |  |  |  |  | if (wantarray) {
648 |  |  |  |  | @result = &$final($self);
649 |  |  |  |  | }
650 |  |  |  |  | else {
651 |  |  |  |  | $result = &$final($self);
652 |  |  |  |  | }
653 |  |  |  |  | }
654 |  |  |  |  |
655 |  |  |  |  | $self->release;
656 |  |  |  |  |
657 |  |  |  |  | return unless defined wantarray;
658 |  |  |  |  | return wantarray ? @result : $result;
659 |  |  |  |  | }
660 |  |  |  |  |
661 |  |  |  |  | ################################################################
662 |  |  |  |  |
663 |  |  |  |  | package #hide from PAUSE
664 |  |  |  |  | XML::Parser::Encinfo;
665 |  |  |  |  |
666 |  |  |  |  | sub DESTROY {
667 |  |  |  |  | my $self = shift;
668 |  |  |  |  | XML::Parser::Expat::FreeEncoding($self);
669 |  |  |  |  | }
670 |  |  |  |  |
671 | 1 | 9µs |  |  | 1;
672 |  |  |  |  |
673 |  |  |  |  | __END__
|  |  |  |  | # spent 70.4s (2.57+67.9) within XML::Parser::Expat::ParseString which was called 7 times, avg 10.1s/call: # 7 times (2.57s+67.9s) by XML::Parser::Expat::parse at line 486, avg 10.1s/call sub XML::Parser::Expat::ParseString; # xsub
|  |  |  |  | # spent 47µs within XML::Parser::Expat::ParserCreate which was called 7 times, avg 7µs/call: # 7 times (47µs+0s) by XML::Parser::Expat::new at line 69, avg 7µs/call sub XML::Parser::Expat::ParserCreate; # xsub
|  |  |  |  | # spent 616µs within XML::Parser::Expat::ParserFree which was called 7 times, avg 88µs/call: # 7 times (616µs+0s) by XML::Parser::Expat::DESTROY at line 436, avg 88µs/call sub XML::Parser::Expat::ParserFree; # xsub
|  |  |  |  | # spent 3µs within XML::Parser::Expat::ParserRelease which was called 7 times, avg 486ns/call: # 7 times (3µs+0s) by XML::Parser::Expat::release at line 431, avg 486ns/call sub XML::Parser::Expat::ParserRelease; # xsub
|  |  |  |  | # spent 223ms within XML::Parser::Expat::RecognizedString which was called 364369 times, avg 613ns/call: # 364369 times (223ms+0s) by XML::Parser::Expat::recognized_string at line 166, avg 613ns/call sub XML::Parser::Expat::RecognizedString; # xsub
|  |  |  |  | # spent 20.8ms within XML::Parser::Expat::SetAttListDeclHandler which was called 67591 times, avg 308ns/call: # 67591 times (20.8ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 308ns/call sub XML::Parser::Expat::SetAttListDeclHandler; # xsub
|  |  |  |  | # spent 20.4ms within XML::Parser::Expat::SetCharacterDataHandler which was called 67591 times, avg 301ns/call: # 67591 times (20.4ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 301ns/call sub XML::Parser::Expat::SetCharacterDataHandler; # xsub
|  |  |  |  | # spent 20.5ms within XML::Parser::Expat::SetCommentHandler which was called 67591 times, avg 303ns/call: # 67591 times (20.5ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 303ns/call sub XML::Parser::Expat::SetCommentHandler; # xsub
|  |  |  |  | # spent 17.4ms within XML::Parser::Expat::SetDefaultHandler which was called 67598 times, avg 258ns/call: # 67598 times (17.4ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 258ns/call sub XML::Parser::Expat::SetDefaultHandler; # xsub
|  |  |  |  | # spent 17.8ms within XML::Parser::Expat::SetDoctypeHandler which was called 67591 times, avg 264ns/call: # 67591 times (17.8ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 264ns/call sub XML::Parser::Expat::SetDoctypeHandler; # xsub
|  |  |  |  | # spent 19.4ms within XML::Parser::Expat::SetElementDeclHandler which was called 67591 times, avg 287ns/call: # 67591 times (19.4ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 287ns/call sub XML::Parser::Expat::SetElementDeclHandler; # xsub
|  |  |  |  | # spent 20.2ms within XML::Parser::Expat::SetEndCdataHandler which was called 67591 times, avg 299ns/call: # 67591 times (20.2ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 299ns/call sub XML::Parser::Expat::SetEndCdataHandler; # xsub
|  |  |  |  | # spent 22.2ms within XML::Parser::Expat::SetEndElementHandler which was called 67591 times, avg 329ns/call: # 67591 times (22.2ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 329ns/call sub XML::Parser::Expat::SetEndElementHandler; # xsub
|  |  |  |  | # spent 21.1ms within XML::Parser::Expat::SetEntityDeclHandler which was called 67591 times, avg 312ns/call: # 67591 times (21.1ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 312ns/call sub XML::Parser::Expat::SetEntityDeclHandler; # xsub
|  |  |  |  | # spent 20.1ms within XML::Parser::Expat::SetExternalEntityRefHandler which was called 67591 times, avg 298ns/call: # 67591 times (20.1ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 298ns/call sub XML::Parser::Expat::SetExternalEntityRefHandler; # xsub
|  |  |  |  | # spent 10.5ms within XML::Parser::Expat::SetNotationDeclHandler which was called 33798 times, avg 310ns/call: # 33798 times (10.5ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 310ns/call sub XML::Parser::Expat::SetNotationDeclHandler; # xsub
|  |  |  |  | # spent 17.8ms within XML::Parser::Expat::SetProcessingInstructionHandler which was called 67591 times, avg 263ns/call: # 67591 times (17.8ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 263ns/call sub XML::Parser::Expat::SetProcessingInstructionHandler; # xsub
|  |  |  |  | # spent 18.9ms within XML::Parser::Expat::SetStartCdataHandler which was called 67591 times, avg 279ns/call: # 67591 times (18.9ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 279ns/call sub XML::Parser::Expat::SetStartCdataHandler; # xsub
|  |  |  |  | # spent 15.7ms within XML::Parser::Expat::SetStartElementHandler which was called 67591 times, avg 232ns/call: # 67591 times (15.7ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 232ns/call sub XML::Parser::Expat::SetStartElementHandler; # xsub
|  |  |  |  | # spent 26.8ms within XML::Parser::Expat::SetXMLDeclHandler which was called 67591 times, avg 396ns/call: # 67591 times (26.8ms+0s) by XML::Parser::Expat::setHandlers at line 128, avg 396ns/call sub XML::Parser::Expat::SetXMLDeclHandler; # xsub