Filename | /usr/lib/perl5/XML/Parser/Expat.pm |
Statements | Executed 740036 statements in 8.34s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
5000 | 1 | 1 | 6.75s | 83.2s | ParseString (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 1.22s | 1.47s | setHandlers | XML::Parser::Expat::
5000 | 1 | 1 | 227ms | 83.4s | parse | XML::Parser::Expat::
5000 | 1 | 1 | 143ms | 198ms | new | XML::Parser::Expat::
5000 | 1 | 1 | 78.2ms | 78.2ms | ParserFree (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 55.0ms | 55.0ms | ParserCreate (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 49.2ms | 127ms | DESTROY | XML::Parser::Expat::
5000 | 1 | 1 | 46.7ms | 61.0ms | release | XML::Parser::Expat::
5000 | 1 | 1 | 17.2ms | 17.2ms | SetEndCdataHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 16.7ms | 16.7ms | SetUnparsedEntityDeclHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 15.5ms | 15.5ms | SetProcessingInstructionHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 15.5ms | 15.5ms | SetExternalEntityRefHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 15.2ms | 15.2ms | SetDoctypeHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 15.1ms | 15.1ms | SetCharacterDataHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 14.9ms | 14.9ms | SetElementDeclHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 14.9ms | 14.9ms | SetStartElementHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 14.9ms | 14.9ms | SetXMLDeclHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 14.9ms | 14.9ms | SetEndDoctypeHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 14.8ms | 14.8ms | SetNotationDeclHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 14.7ms | 14.7ms | SetCommentHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 14.7ms | 14.7ms | SetStartCdataHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 14.2ms | 14.2ms | ParserRelease (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 14.2ms | 14.2ms | SetAttListDeclHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 14.0ms | 14.0ms | SetEndElementHandler (xsub) | XML::Parser::Expat::
5000 | 1 | 1 | 14.0ms | 14.0ms | SetEntityDeclHandler (xsub) | XML::Parser::Expat::
1 | 1 | 1 | 94µs | 94µs | bootstrap (xsub) | XML::Parser::Expat::
11 | 1 | 1 | 57µs | 57µs | CORE:ftdir (opcode) | XML::Parser::Expat::
1 | 1 | 1 | 40µs | 112µs | BEGIN@499 | XML::Parser::ContentModel::
1 | 1 | 1 | 22µs | 27µs | BEGIN@5 | XML::Parser::Expat::
1 | 1 | 1 | 18µs | 47µs | BEGIN@449 | XML::Parser::Expat::
1 | 1 | 1 | 17µs | 40µs | BEGIN@455 | XML::Parser::Expat::
1 | 1 | 1 | 17µs | 104µs | BEGIN@588 | XML::Parser::ExpatNB::
1 | 1 | 1 | 16µs | 63µs | BEGIN@587 | XML::Parser::ExpatNB::
1 | 1 | 1 | 14µs | 86µs | BEGIN@8 | XML::Parser::Expat::
1 | 1 | 1 | 14µs | 205µs | BEGIN@6 | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | asString | XML::Parser::ContentModel::
0 | 0 | 0 | 0s | 0s | children | XML::Parser::ContentModel::
0 | 0 | 0 | 0s | 0s | isany | XML::Parser::ContentModel::
0 | 0 | 0 | 0s | 0s | ischoice | XML::Parser::ContentModel::
0 | 0 | 0 | 0s | 0s | isempty | XML::Parser::ContentModel::
0 | 0 | 0 | 0s | 0s | ismixed | XML::Parser::ContentModel::
0 | 0 | 0 | 0s | 0s | isname | XML::Parser::ContentModel::
0 | 0 | 0 | 0s | 0s | isseq | XML::Parser::ContentModel::
0 | 0 | 0 | 0s | 0s | name | XML::Parser::ContentModel::
0 | 0 | 0 | 0s | 0s | quant | XML::Parser::ContentModel::
0 | 0 | 0 | 0s | 0s | thiseq | XML::Parser::ContentModel::
0 | 0 | 0 | 0s | 0s | DESTROY | XML::Parser::Encinfo::
0 | 0 | 0 | 0s | 0s | NamespaceEnd | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | NamespaceStart | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | base | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | context | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | current_byte | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | current_column | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | current_element | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | current_line | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | current_ns_prefixes | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | default_current | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | depth | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | element_index | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | eq_name | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | expand_ns_prefix | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | finish | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | generate_ns_name | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | in_element | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | load_encoding | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | namespace | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | new_ns_prefixes | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | original_string | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | parsefile | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | parsestring | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | position_in_context | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | recognized_string | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | skip_until | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | specified_attr | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | within_element | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | xml_escape | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | xpcarp | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | xpcroak | XML::Parser::Expat::
0 | 0 | 0 | 0s | 0s | parse | XML::Parser::ExpatNB::
0 | 0 | 0 | 0s | 0s | parse_done | XML::Parser::ExpatNB::
0 | 0 | 0 | 0s | 0s | parse_more | XML::Parser::ExpatNB::
0 | 0 | 0 | 0s | 0s | parsefile | XML::Parser::ExpatNB::
0 | 0 | 0 | 0s | 0s | parsestring | XML::Parser::ExpatNB::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package XML::Parser::Expat; | ||||
2 | |||||
3 | 1 | 64µs | require 5.004; | ||
4 | |||||
5 | 3 | 47µs | 2 | 32µs | # spent 27µs (22+5) within XML::Parser::Expat::BEGIN@5 which was called:
# once (22µs+5µs) by XML::Parser::BEGIN@13 at line 5 # spent 27µs making 1 call to XML::Parser::Expat::BEGIN@5
# spent 5µs making 1 call to strict::import |
6 | 1 | 191µs | # spent 205µs (14+191) within XML::Parser::Expat::BEGIN@6 which was called:
# once (14µs+191µs) by XML::Parser::BEGIN@13 at line 7 # spent 191µs making 1 call to vars::import | ||
7 | 3 | 41µs | 1 | 205µs | $have_File_Spec); # spent 205µs making 1 call to XML::Parser::Expat::BEGIN@6 |
8 | 3 | 3.10ms | 2 | 158µs | # spent 86µs (14+72) within XML::Parser::Expat::BEGIN@8 which was called:
# once (14µs+72µs) by XML::Parser::BEGIN@13 at line 8 # spent 86µs making 1 call to XML::Parser::Expat::BEGIN@8
# spent 72µs making 1 call to Exporter::import |
9 | |||||
10 | 1 | 1µs | require DynaLoader; | ||
11 | |||||
12 | 1 | 19µs | @ISA = qw(DynaLoader); | ||
13 | 1 | 2µs | $VERSION = "2.36" ; | ||
14 | |||||
15 | 1 | 2µs | $have_File_Spec = $INC{'File/Spec.pm'} || do 'File/Spec.pm'; | ||
16 | |||||
17 | 1 | 1µs | %Encoding_Table = (); | ||
18 | 2 | 157µs | if ($have_File_Spec) { | ||
19 | 23 | 619µs | @Encoding_Path = (grep(-d $_, # spent 560µs making 11 calls to File::Spec::Unix::catdir, avg 51µs/call
# spent 57µs making 11 calls to XML::Parser::Expat::CORE:ftdir, avg 5µs/call
# spent 2µs making 1 call to File::Spec::Unix::curdir | ||
20 | map(File::Spec->catdir($_, qw(XML Parser Encodings)), | ||||
21 | @INC)), | ||||
22 | File::Spec->curdir); | ||||
23 | } | ||||
24 | else { | ||||
25 | @Encoding_Path = (grep(-d $_, map($_ . '/XML/Parser/Encodings', @INC)), '.'); | ||||
26 | } | ||||
27 | |||||
28 | |||||
29 | 1 | 9µs | 1 | 568µs | bootstrap XML::Parser::Expat $VERSION; # spent 568µs making 1 call to DynaLoader::bootstrap |
30 | |||||
31 | 1 | 21µs | %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 198ms (143+55.0) within XML::Parser::Expat::new which was called 5000 times, avg 40µs/call:
# 5000 times (143ms+55.0ms) by XML::Parser::parse at line 170 of XML/Parser.pm, avg 40µs/call | ||||
53 | 50000 | 201ms | my ($class, %args) = @_; | ||
54 | my $self = bless \%args, $_[0]; | ||||
55 | $args{_State_} = 0; | ||||
56 | $args{Context} = []; | ||||
57 | $args{Namespaces} ||= 0; | ||||
58 | $args{ErrorMessage} ||= ''; | ||||
59 | if ($args{Namespaces}) { | ||||
60 | $args{Namespace_Table} = {}; | ||||
61 | $args{Namespace_List} = [undef]; | ||||
62 | $args{Prefix_Table} = {}; | ||||
63 | $args{New_Prefixes} = []; | ||||
64 | } | ||||
65 | $args{_Setters} = \%Handler_Setters; | ||||
66 | 5000 | 55.0ms | $args{Parser} = ParserCreate($self, $args{ProtocolEncoding}, # spent 55.0ms making 5000 calls to XML::Parser::Expat::ParserCreate, avg 11µs/call | ||
67 | $args{Namespaces}); | ||||
68 | $self; | ||||
69 | } | ||||
70 | |||||
71 | sub load_encoding { | ||||
72 | my ($file) = @_; | ||||
73 | |||||
74 | $file =~ s!([^/]+)$!\L$1\E!; | ||||
75 | $file .= '.enc' unless $file =~ /\.enc$/; | ||||
76 | unless ($file =~ m!^/!) { | ||||
77 | foreach (@Encoding_Path) { | ||||
78 | my $tmp = ($have_File_Spec | ||||
79 | ? File::Spec->catfile($_, $file) | ||||
80 | : "$_/$file"); | ||||
81 | if (-e $tmp) { | ||||
82 | $file = $tmp; | ||||
83 | last; | ||||
84 | } | ||||
85 | } | ||||
86 | } | ||||
87 | |||||
88 | local(*ENC); | ||||
89 | open(ENC, $file) or croak("Couldn't open encmap $file:\n$!\n"); | ||||
90 | binmode(ENC); | ||||
91 | my $data; | ||||
92 | my $br = sysread(ENC, $data, -s $file); | ||||
93 | croak("Trouble reading $file:\n$!\n") | ||||
94 | unless defined($br); | ||||
95 | close(ENC); | ||||
96 | |||||
97 | my $name = LoadEncoding($data, $br); | ||||
98 | croak("$file isn't an encmap file") | ||||
99 | unless defined($name); | ||||
100 | |||||
101 | $name; | ||||
102 | } # End load_encoding | ||||
103 | |||||
104 | # spent 1.47s (1.22+241ms) within XML::Parser::Expat::setHandlers which was called 5000 times, avg 293µs/call:
# 5000 times (1.22s+241ms) by XML::Parser::parse at line 175 of XML/Parser.pm, avg 293µs/call | ||||
105 | 25000 | 96.6ms | my ($self, @handler_pairs) = @_; | ||
106 | |||||
107 | croak("Uneven number of arguments to setHandlers method") | ||||
108 | if (int(@handler_pairs) & 1); | ||||
109 | |||||
110 | my @ret; | ||||
111 | |||||
112 | while (@handler_pairs) { | ||||
113 | 560000 | 1.37s | my $type = shift @handler_pairs; | ||
114 | my $handler = shift @handler_pairs; | ||||
115 | croak "Handler for $type not a Code ref" | ||||
116 | unless (! defined($handler) or ! $handler or ref($handler) eq 'CODE'); | ||||
117 | |||||
118 | my $hndl = $self->{_Setters}->{$type}; | ||||
119 | |||||
120 | unless (defined($hndl)) { | ||||
121 | my @types = sort keys %{$self->{_Setters}}; | ||||
122 | croak("Unknown Expat handler type: $type\n Valid types: @types"); | ||||
123 | } | ||||
124 | |||||
125 | 80000 | 241ms | my $old = &$hndl($self->{Parser}, $handler); # spent 17.2ms making 5000 calls to XML::Parser::Expat::SetEndCdataHandler, avg 3µs/call
# spent 16.7ms making 5000 calls to XML::Parser::Expat::SetUnparsedEntityDeclHandler, avg 3µs/call
# spent 15.5ms making 5000 calls to XML::Parser::Expat::SetProcessingInstructionHandler, avg 3µs/call
# spent 15.5ms making 5000 calls to XML::Parser::Expat::SetExternalEntityRefHandler, avg 3µs/call
# spent 15.2ms making 5000 calls to XML::Parser::Expat::SetDoctypeHandler, avg 3µs/call
# spent 15.1ms making 5000 calls to XML::Parser::Expat::SetCharacterDataHandler, avg 3µs/call
# spent 14.9ms making 5000 calls to XML::Parser::Expat::SetElementDeclHandler, avg 3µs/call
# spent 14.9ms making 5000 calls to XML::Parser::Expat::SetStartElementHandler, avg 3µs/call
# spent 14.9ms making 5000 calls to XML::Parser::Expat::SetXMLDeclHandler, avg 3µs/call
# spent 14.9ms making 5000 calls to XML::Parser::Expat::SetEndDoctypeHandler, avg 3µs/call
# spent 14.8ms making 5000 calls to XML::Parser::Expat::SetNotationDeclHandler, avg 3µs/call
# spent 14.7ms making 5000 calls to XML::Parser::Expat::SetCommentHandler, avg 3µs/call
# spent 14.7ms making 5000 calls to XML::Parser::Expat::SetStartCdataHandler, avg 3µs/call
# spent 14.2ms making 5000 calls to XML::Parser::Expat::SetAttListDeclHandler, avg 3µs/call
# spent 14.0ms making 5000 calls to XML::Parser::Expat::SetEndElementHandler, avg 3µs/call
# spent 14.0ms making 5000 calls to XML::Parser::Expat::SetEntityDeclHandler, avg 3µs/call | ||
126 | push (@ret, $type, $old); | ||||
127 | } | ||||
128 | |||||
129 | return @ret; | ||||
130 | } | ||||
131 | |||||
132 | sub xpcroak | ||||
133 | { | ||||
134 | my ($self, $message) = @_; | ||||
135 | |||||
136 | my $eclines = $self->{ErrorContext}; | ||||
137 | my $line = GetCurrentLineNumber($_[0]->{Parser}); | ||||
138 | $message .= " at line $line"; | ||||
139 | $message .= ":\n" . $self->position_in_context($eclines) | ||||
140 | if defined($eclines); | ||||
141 | croak $message; | ||||
142 | } | ||||
143 | |||||
144 | sub xpcarp { | ||||
145 | my ($self, $message) = @_; | ||||
146 | |||||
147 | my $eclines = $self->{ErrorContext}; | ||||
148 | my $line = GetCurrentLineNumber($_[0]->{Parser}); | ||||
149 | $message .= " at line $line"; | ||||
150 | $message .= ":\n" . $self->position_in_context($eclines) | ||||
151 | if defined($eclines); | ||||
152 | carp $message; | ||||
153 | } | ||||
154 | |||||
155 | sub default_current { | ||||
156 | my $self = shift; | ||||
157 | if ($self->{_State_} == 1) { | ||||
158 | return DefaultCurrent($self->{Parser}); | ||||
159 | } | ||||
160 | } | ||||
161 | |||||
162 | sub recognized_string { | ||||
163 | my $self = shift; | ||||
164 | if ($self->{_State_} == 1) { | ||||
165 | return RecognizedString($self->{Parser}); | ||||
166 | } | ||||
167 | } | ||||
168 | |||||
169 | sub original_string { | ||||
170 | my $self = shift; | ||||
171 | if ($self->{_State_} == 1) { | ||||
172 | return OriginalString($self->{Parser}); | ||||
173 | } | ||||
174 | } | ||||
175 | |||||
176 | sub current_line { | ||||
177 | my $self = shift; | ||||
178 | if ($self->{_State_} == 1) { | ||||
179 | return GetCurrentLineNumber($self->{Parser}); | ||||
180 | } | ||||
181 | } | ||||
182 | |||||
183 | sub current_column { | ||||
184 | my $self = shift; | ||||
185 | if ($self->{_State_} == 1) { | ||||
186 | return GetCurrentColumnNumber($self->{Parser}); | ||||
187 | } | ||||
188 | } | ||||
189 | |||||
190 | sub current_byte { | ||||
191 | my $self = shift; | ||||
192 | if ($self->{_State_} == 1) { | ||||
193 | return GetCurrentByteIndex($self->{Parser}); | ||||
194 | } | ||||
195 | } | ||||
196 | |||||
197 | sub base { | ||||
198 | my ($self, $newbase) = @_; | ||||
199 | my $p = $self->{Parser}; | ||||
200 | my $oldbase = GetBase($p); | ||||
201 | SetBase($p, $newbase) if @_ > 1; | ||||
202 | return $oldbase; | ||||
203 | } | ||||
204 | |||||
205 | sub context { | ||||
206 | my $ctx = $_[0]->{Context}; | ||||
207 | @$ctx; | ||||
208 | } | ||||
209 | |||||
210 | sub current_element { | ||||
211 | my ($self) = @_; | ||||
212 | @{$self->{Context}} ? $self->{Context}->[-1] : undef; | ||||
213 | } | ||||
214 | |||||
215 | sub in_element { | ||||
216 | my ($self, $element) = @_; | ||||
217 | @{$self->{Context}} ? $self->eq_name($self->{Context}->[-1], $element) | ||||
218 | : undef; | ||||
219 | } | ||||
220 | |||||
221 | sub within_element { | ||||
222 | my ($self, $element) = @_; | ||||
223 | my $cnt = 0; | ||||
224 | foreach (@{$self->{Context}}) { | ||||
225 | $cnt++ if $self->eq_name($_, $element); | ||||
226 | } | ||||
227 | return $cnt; | ||||
228 | } | ||||
229 | |||||
230 | sub depth { | ||||
231 | my ($self) = @_; | ||||
232 | int(@{$self->{Context}}); | ||||
233 | } | ||||
234 | |||||
235 | sub element_index { | ||||
236 | my ($self) = @_; | ||||
237 | |||||
238 | if ($self->{_State_} == 1) { | ||||
239 | return ElementIndex($self->{Parser}); | ||||
240 | } | ||||
241 | } | ||||
242 | |||||
243 | ################ | ||||
244 | # Namespace methods | ||||
245 | |||||
246 | sub namespace { | ||||
247 | my ($self, $name) = @_; | ||||
248 | local($^W) = 0; | ||||
249 | $self->{Namespace_List}->[int($name)]; | ||||
250 | } | ||||
251 | |||||
252 | sub eq_name { | ||||
253 | my ($self, $nm1, $nm2) = @_; | ||||
254 | local($^W) = 0; | ||||
255 | |||||
256 | int($nm1) == int($nm2) and $nm1 eq $nm2; | ||||
257 | } | ||||
258 | |||||
259 | sub generate_ns_name { | ||||
260 | my ($self, $name, $namespace) = @_; | ||||
261 | |||||
262 | $namespace ? | ||||
263 | GenerateNSName($name, $namespace, $self->{Namespace_Table}, | ||||
264 | $self->{Namespace_List}) | ||||
265 | : $name; | ||||
266 | } | ||||
267 | |||||
268 | sub new_ns_prefixes { | ||||
269 | my ($self) = @_; | ||||
270 | if ($self->{Namespaces}) { | ||||
271 | return @{$self->{New_Prefixes}}; | ||||
272 | } | ||||
273 | return (); | ||||
274 | } | ||||
275 | |||||
276 | sub expand_ns_prefix { | ||||
277 | my ($self, $prefix) = @_; | ||||
278 | |||||
279 | if ($self->{Namespaces}) { | ||||
280 | my $stack = $self->{Prefix_Table}->{$prefix}; | ||||
281 | return (defined($stack) and @$stack) ? $stack->[-1] : undef; | ||||
282 | } | ||||
283 | |||||
284 | return undef; | ||||
285 | } | ||||
286 | |||||
287 | sub current_ns_prefixes { | ||||
288 | my ($self) = @_; | ||||
289 | |||||
290 | if ($self->{Namespaces}) { | ||||
291 | my %set = %{$self->{Prefix_Table}}; | ||||
292 | |||||
293 | if (exists $set{'#default'} and not defined($set{'#default'}->[-1])) { | ||||
294 | delete $set{'#default'}; | ||||
295 | } | ||||
296 | |||||
297 | return keys %set; | ||||
298 | } | ||||
299 | |||||
300 | return (); | ||||
301 | } | ||||
302 | |||||
303 | |||||
304 | ################################################################ | ||||
305 | # Namespace declaration handlers | ||||
306 | # | ||||
307 | |||||
308 | sub NamespaceStart { | ||||
309 | my ($self, $prefix, $uri) = @_; | ||||
310 | |||||
311 | $prefix = '#default' unless defined $prefix; | ||||
312 | my $stack = $self->{Prefix_Table}->{$prefix}; | ||||
313 | |||||
314 | if (defined $stack) { | ||||
315 | push(@$stack, $uri); | ||||
316 | } | ||||
317 | else { | ||||
318 | $self->{Prefix_Table}->{$prefix} = [$uri]; | ||||
319 | } | ||||
320 | |||||
321 | # The New_Prefixes list gets emptied at end of startElement function | ||||
322 | # in Expat.xs | ||||
323 | |||||
324 | push(@{$self->{New_Prefixes}}, $prefix); | ||||
325 | } | ||||
326 | |||||
327 | sub NamespaceEnd { | ||||
328 | my ($self, $prefix) = @_; | ||||
329 | |||||
330 | $prefix = '#default' unless defined $prefix; | ||||
331 | |||||
332 | my $stack = $self->{Prefix_Table}->{$prefix}; | ||||
333 | if (@$stack > 1) { | ||||
334 | pop(@$stack); | ||||
335 | } | ||||
336 | else { | ||||
337 | delete $self->{Prefix_Table}->{$prefix}; | ||||
338 | } | ||||
339 | } | ||||
340 | |||||
341 | ################ | ||||
342 | |||||
343 | sub specified_attr { | ||||
344 | my $self = shift; | ||||
345 | |||||
346 | if ($self->{_State_} == 1) { | ||||
347 | return GetSpecifiedAttributeCount($self->{Parser}); | ||||
348 | } | ||||
349 | } | ||||
350 | |||||
351 | sub finish { | ||||
352 | my ($self) = @_; | ||||
353 | if ($self->{_State_} == 1) { | ||||
354 | my $parser = $self->{Parser}; | ||||
355 | UnsetAllHandlers($parser); | ||||
356 | } | ||||
357 | } | ||||
358 | |||||
359 | sub position_in_context { | ||||
360 | my ($self, $lines) = @_; | ||||
361 | if ($self->{_State_} == 1) { | ||||
362 | my $parser = $self->{Parser}; | ||||
363 | my ($string, $linepos) = PositionContext($parser, $lines); | ||||
364 | |||||
365 | return '' unless defined($string); | ||||
366 | |||||
367 | my $col = GetCurrentColumnNumber($parser); | ||||
368 | my $ptr = ('=' x ($col - 1)) . '^' . "\n"; | ||||
369 | my $ret; | ||||
370 | my $dosplit = $linepos < length($string); | ||||
371 | |||||
372 | $string .= "\n" unless $string =~ /\n$/; | ||||
373 | |||||
374 | if ($dosplit) { | ||||
375 | $ret = substr($string, 0, $linepos) . $ptr | ||||
376 | . substr($string, $linepos); | ||||
377 | } else { | ||||
378 | $ret = $string . $ptr; | ||||
379 | } | ||||
380 | |||||
381 | return $ret; | ||||
382 | } | ||||
383 | } | ||||
384 | |||||
385 | sub xml_escape { | ||||
386 | my $self = shift; | ||||
387 | my $text = shift; | ||||
388 | |||||
389 | study $text; | ||||
390 | $text =~ s/\&/\&/g; | ||||
391 | $text =~ s/</\</g; | ||||
392 | foreach (@_) { | ||||
393 | croak "xml_escape: '$_' isn't a single character" if length($_) > 1; | ||||
394 | |||||
395 | if ($_ eq '>') { | ||||
396 | $text =~ s/>/\>/g; | ||||
397 | } | ||||
398 | elsif ($_ eq '"') { | ||||
399 | $text =~ s/\"/\"/; | ||||
400 | } | ||||
401 | elsif ($_ eq "'") { | ||||
402 | $text =~ s/\'/\'/; | ||||
403 | } | ||||
404 | else { | ||||
405 | my $rep = '&#' . sprintf('x%X', ord($_)) . ';'; | ||||
406 | if (/\W/) { | ||||
407 | my $ptrn = "\\$_"; | ||||
408 | $text =~ s/$ptrn/$rep/g; | ||||
409 | } | ||||
410 | else { | ||||
411 | $text =~ s/$_/$rep/g; | ||||
412 | } | ||||
413 | } | ||||
414 | } | ||||
415 | $text; | ||||
416 | } | ||||
417 | |||||
418 | sub skip_until { | ||||
419 | my $self = shift; | ||||
420 | if ($self->{_State_} <= 1) { | ||||
421 | SkipUntil($self->{Parser}, $_[0]); | ||||
422 | } | ||||
423 | } | ||||
424 | |||||
425 | # spent 61.0ms (46.7+14.3) within XML::Parser::Expat::release which was called 5000 times, avg 12µs/call:
# 5000 times (46.7ms+14.3ms) by XML::Parser::parse at line 204 of XML/Parser.pm, avg 12µs/call | ||||
426 | 10000 | 61.2ms | my $self = shift; | ||
427 | 5000 | 14.2ms | ParserRelease($self->{Parser}); # spent 14.2ms making 5000 calls to XML::Parser::Expat::ParserRelease, avg 3µs/call | ||
428 | } | ||||
429 | |||||
430 | # spent 127ms (49.2+78.2) within XML::Parser::Expat::DESTROY which was called 5000 times, avg 25µs/call:
# 5000 times (49.2ms+78.2ms) by XML::Parser::parse at line 60 of XML/SAX/Expat.pm, avg 25µs/call | ||||
431 | 10000 | 127ms | my $self = shift; | ||
432 | 5000 | 78.2ms | ParserFree($self->{Parser}); # spent 78.2ms making 5000 calls to XML::Parser::Expat::ParserFree, avg 16µs/call | ||
433 | } | ||||
434 | |||||
435 | # spent 83.4s (227ms+83.2) within XML::Parser::Expat::parse which was called 5000 times, avg 16.7ms/call:
# 5000 times (227ms+83.2s) by XML::Parser::parse at line 187 of XML/Parser.pm, avg 16.7ms/call | ||||
436 | 55000 | 102ms | my $self = shift; | ||
437 | my $arg = shift; | ||||
438 | croak "Parse already in progress (Expat)" if $self->{_State_}; | ||||
439 | $self->{_State_} = 1; | ||||
440 | my $parser = $self->{Parser}; | ||||
441 | my $ioref; | ||||
442 | my $result = 0; | ||||
443 | |||||
444 | 5000 | 13.6ms | if (defined $arg) { | ||
445 | 15000 | 28.2ms | if (ref($arg) and UNIVERSAL::isa($arg, 'IO::Handle')) { | ||
446 | $ioref = $arg; | ||||
447 | } elsif (tied($arg)) { | ||||
448 | my $class = ref($arg); | ||||
449 | 3 | 77µs | 2 | 76µs | # spent 47µs (18+29) within XML::Parser::Expat::BEGIN@449 which was called:
# once (18µs+29µs) by XML::Parser::BEGIN@13 at line 449 # spent 47µs making 1 call to XML::Parser::Expat::BEGIN@449
# spent 29µs making 1 call to strict::unimport |
450 | $ioref = $arg if defined &{"${class}::TIEHANDLE"}; | ||||
451 | } | ||||
452 | else { | ||||
453 | require IO::Handle; | ||||
454 | 5000 | 62.5ms | eval { | ||
455 | 3 | 386µs | 2 | 63µs | # spent 40µs (17+23) within XML::Parser::Expat::BEGIN@455 which was called:
# once (17µs+23µs) by XML::Parser::BEGIN@13 at line 455 # spent 40µs making 1 call to XML::Parser::Expat::BEGIN@455
# spent 23µs making 1 call to strict::unimport |
456 | $ioref = *{$arg}{IO} if defined *{$arg}; | ||||
457 | }; | ||||
458 | undef $@; | ||||
459 | } | ||||
460 | } | ||||
461 | |||||
462 | 5000 | 79.4ms | if (defined($ioref)) { | ||
463 | my $delim = $self->{Stream_Delimiter}; | ||||
464 | my $prev_rs; | ||||
465 | |||||
466 | $prev_rs = ref($ioref)->input_record_separator("\n$delim\n") | ||||
467 | if defined($delim); | ||||
468 | |||||
469 | $result = ParseStream($parser, $ioref, $delim); | ||||
470 | |||||
471 | ref($ioref)->input_record_separator($prev_rs) | ||||
472 | if defined($delim); | ||||
473 | } else { | ||||
474 | 1 | 6.19s | 983004 | 160s | $result = ParseString($parser, $arg); # spent 83.2s making 5000 calls to XML::Parser::Expat::ParseString, avg 16.6ms/call
# spent 34.3s making 185299 calls to XML::SAX::Expat::_handle_start, avg 185µs/call
# spent 22.3s making 607406 calls to XML::SAX::Expat::_handle_char, avg 37µs/call
# spent 19.8s making 185299 calls to XML::SAX::Expat::_handle_end, avg 107µs/call |
475 | } | ||||
476 | |||||
477 | $self->{_State_} = 2; | ||||
478 | $result or croak $self->{ErrorMessage}; | ||||
479 | } | ||||
480 | |||||
481 | sub parsestring { | ||||
482 | my $self = shift; | ||||
483 | $self->parse(@_); | ||||
484 | } | ||||
485 | |||||
486 | sub parsefile { | ||||
487 | my $self = shift; | ||||
488 | croak "Parser has already been used" if $self->{_State_}; | ||||
489 | local(*FILE); | ||||
490 | open(FILE, $_[0]) or croak "Couldn't open $_[0]:\n$!"; | ||||
491 | binmode(FILE); | ||||
492 | my $ret = $self->parse(*FILE); | ||||
493 | close(FILE); | ||||
494 | $ret; | ||||
495 | } | ||||
496 | |||||
497 | ################################################################ | ||||
498 | package XML::Parser::ContentModel; | ||||
499 | 3 | 636µs | 2 | 184µs | # spent 112µs (40+72) within XML::Parser::ContentModel::BEGIN@499 which was called:
# once (40µs+72µs) by XML::Parser::BEGIN@13 at line 499 # spent 112µs making 1 call to XML::Parser::ContentModel::BEGIN@499
# spent 72µs making 1 call to overload::import |
500 | |||||
501 | sub EMPTY () {1} | ||||
502 | sub ANY () {2} | ||||
503 | sub MIXED () {3} | ||||
504 | sub NAME () {4} | ||||
505 | sub CHOICE () {5} | ||||
506 | sub SEQ () {6} | ||||
507 | |||||
508 | |||||
509 | sub isempty { | ||||
510 | return $_[0]->{Type} == EMPTY; | ||||
511 | } | ||||
512 | |||||
513 | sub isany { | ||||
514 | return $_[0]->{Type} == ANY; | ||||
515 | } | ||||
516 | |||||
517 | sub ismixed { | ||||
518 | return $_[0]->{Type} == MIXED; | ||||
519 | } | ||||
520 | |||||
521 | sub isname { | ||||
522 | return $_[0]->{Type} == NAME; | ||||
523 | } | ||||
524 | |||||
525 | sub name { | ||||
526 | return $_[0]->{Tag}; | ||||
527 | } | ||||
528 | |||||
529 | sub ischoice { | ||||
530 | return $_[0]->{Type} == CHOICE; | ||||
531 | } | ||||
532 | |||||
533 | sub isseq { | ||||
534 | return $_[0]->{Type} == SEQ; | ||||
535 | } | ||||
536 | |||||
537 | sub quant { | ||||
538 | return $_[0]->{Quant}; | ||||
539 | } | ||||
540 | |||||
541 | sub children { | ||||
542 | my $children = $_[0]->{Children}; | ||||
543 | if (defined $children) { | ||||
544 | return @$children; | ||||
545 | } | ||||
546 | return undef; | ||||
547 | } | ||||
548 | |||||
549 | sub asString { | ||||
550 | my ($self) = @_; | ||||
551 | my $ret; | ||||
552 | |||||
553 | if ($self->{Type} == NAME) { | ||||
554 | $ret = $self->{Tag}; | ||||
555 | } | ||||
556 | elsif ($self->{Type} == EMPTY) { | ||||
557 | return "EMPTY"; | ||||
558 | } | ||||
559 | elsif ($self->{Type} == ANY) { | ||||
560 | return "ANY"; | ||||
561 | } | ||||
562 | elsif ($self->{Type} == MIXED) { | ||||
563 | $ret = '(#PCDATA'; | ||||
564 | foreach (@{$self->{Children}}) { | ||||
565 | $ret .= '|' . $_; | ||||
566 | } | ||||
567 | $ret .= ')'; | ||||
568 | } | ||||
569 | else { | ||||
570 | my $sep = $self->{Type} == CHOICE ? '|' : ','; | ||||
571 | $ret = '(' . join($sep, map { $_->asString } @{$self->{Children}}) . ')'; | ||||
572 | } | ||||
573 | |||||
574 | $ret .= $self->{Quant} if $self->{Quant}; | ||||
575 | return $ret; | ||||
576 | } | ||||
577 | |||||
578 | sub thiseq { | ||||
579 | my $self = shift; | ||||
580 | |||||
581 | return $self->asString eq $_[0]; | ||||
582 | } | ||||
583 | |||||
584 | ################################################################ | ||||
585 | package XML::Parser::ExpatNB; | ||||
586 | |||||
587 | 3 | 42µs | 2 | 110µs | # spent 63µs (16+47) within XML::Parser::ExpatNB::BEGIN@587 which was called:
# once (16µs+47µs) by XML::Parser::BEGIN@13 at line 587 # spent 63µs making 1 call to XML::Parser::ExpatNB::BEGIN@587
# spent 47µs making 1 call to vars::import |
588 | 3 | 487µs | 2 | 191µs | # spent 104µs (17+87) within XML::Parser::ExpatNB::BEGIN@588 which was called:
# once (17µs+87µs) by XML::Parser::BEGIN@13 at line 588 # spent 104µs making 1 call to XML::Parser::ExpatNB::BEGIN@588
# spent 87µs making 1 call to Exporter::import |
589 | |||||
590 | 1 | 11µs | @ISA = qw(XML::Parser::Expat); | ||
591 | |||||
592 | sub parse { | ||||
593 | my $self = shift; | ||||
594 | my $class = ref($self); | ||||
595 | croak "parse method not supported in $class"; | ||||
596 | } | ||||
597 | |||||
598 | sub parsestring { | ||||
599 | my $self = shift; | ||||
600 | my $class = ref($self); | ||||
601 | croak "parsestring method not supported in $class"; | ||||
602 | } | ||||
603 | |||||
604 | sub parsefile { | ||||
605 | my $self = shift; | ||||
606 | my $class = ref($self); | ||||
607 | croak "parsefile method not supported in $class"; | ||||
608 | } | ||||
609 | |||||
610 | sub parse_more { | ||||
611 | my ($self, $data) = @_; | ||||
612 | |||||
613 | $self->{_State_} = 1; | ||||
614 | my $ret = XML::Parser::Expat::ParsePartial($self->{Parser}, $data); | ||||
615 | |||||
616 | croak $self->{ErrorMessage} unless $ret; | ||||
617 | } | ||||
618 | |||||
619 | sub parse_done { | ||||
620 | my $self = shift; | ||||
621 | |||||
622 | my $ret = XML::Parser::Expat::ParseDone($self->{Parser}); | ||||
623 | unless ($ret) { | ||||
624 | my $msg = $self->{ErrorMessage}; | ||||
625 | $self->release; | ||||
626 | croak $msg; | ||||
627 | } | ||||
628 | |||||
629 | $self->{_State_} = 2; | ||||
630 | |||||
631 | my $result = $ret; | ||||
632 | my @result = (); | ||||
633 | my $final = $self->{FinalHandler}; | ||||
634 | if (defined $final) { | ||||
635 | if (wantarray) { | ||||
636 | @result = &$final($self); | ||||
637 | } | ||||
638 | else { | ||||
639 | $result = &$final($self); | ||||
640 | } | ||||
641 | } | ||||
642 | |||||
643 | $self->release; | ||||
644 | |||||
645 | return unless defined wantarray; | ||||
646 | return wantarray ? @result : $result; | ||||
647 | } | ||||
648 | |||||
649 | ################################################################ | ||||
650 | |||||
651 | package XML::Parser::Encinfo; | ||||
652 | |||||
653 | sub DESTROY { | ||||
654 | my $self = shift; | ||||
655 | XML::Parser::Expat::FreeEncoding($self); | ||||
656 | } | ||||
657 | |||||
658 | 1 | 31µs | 1; | ||
659 | |||||
660 | __END__ | ||||
# spent 57µs within XML::Parser::Expat::CORE:ftdir which was called 11 times, avg 5µs/call:
# 11 times (57µs+0s) by XML::Parser::BEGIN@13 at line 19, avg 5µs/call | |||||
# spent 83.2s (6.75+76.4) within XML::Parser::Expat::ParseString which was called 5000 times, avg 16.6ms/call:
# 5000 times (6.75s+76.4s) by XML::Parser::Expat::parse at line 474, avg 16.6ms/call | |||||
# spent 55.0ms within XML::Parser::Expat::ParserCreate which was called 5000 times, avg 11µs/call:
# 5000 times (55.0ms+0s) by XML::Parser::Expat::new at line 66, avg 11µs/call | |||||
# spent 78.2ms within XML::Parser::Expat::ParserFree which was called 5000 times, avg 16µs/call:
# 5000 times (78.2ms+0s) by XML::Parser::Expat::DESTROY at line 432, avg 16µs/call | |||||
# spent 14.2ms within XML::Parser::Expat::ParserRelease which was called 5000 times, avg 3µs/call:
# 5000 times (14.2ms+0s) by XML::Parser::Expat::release at line 427, avg 3µs/call | |||||
# spent 14.2ms within XML::Parser::Expat::SetAttListDeclHandler which was called 5000 times, avg 3µs/call:
# 5000 times (14.2ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 15.1ms within XML::Parser::Expat::SetCharacterDataHandler which was called 5000 times, avg 3µs/call:
# 5000 times (15.1ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 14.7ms within XML::Parser::Expat::SetCommentHandler which was called 5000 times, avg 3µs/call:
# 5000 times (14.7ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 15.2ms within XML::Parser::Expat::SetDoctypeHandler which was called 5000 times, avg 3µs/call:
# 5000 times (15.2ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 14.9ms within XML::Parser::Expat::SetElementDeclHandler which was called 5000 times, avg 3µs/call:
# 5000 times (14.9ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 17.2ms within XML::Parser::Expat::SetEndCdataHandler which was called 5000 times, avg 3µs/call:
# 5000 times (17.2ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 14.9ms within XML::Parser::Expat::SetEndDoctypeHandler which was called 5000 times, avg 3µs/call:
# 5000 times (14.9ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 14.0ms within XML::Parser::Expat::SetEndElementHandler which was called 5000 times, avg 3µs/call:
# 5000 times (14.0ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 14.0ms within XML::Parser::Expat::SetEntityDeclHandler which was called 5000 times, avg 3µs/call:
# 5000 times (14.0ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 15.5ms within XML::Parser::Expat::SetExternalEntityRefHandler which was called 5000 times, avg 3µs/call:
# 5000 times (15.5ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 14.8ms within XML::Parser::Expat::SetNotationDeclHandler which was called 5000 times, avg 3µs/call:
# 5000 times (14.8ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 15.5ms within XML::Parser::Expat::SetProcessingInstructionHandler which was called 5000 times, avg 3µs/call:
# 5000 times (15.5ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 14.7ms within XML::Parser::Expat::SetStartCdataHandler which was called 5000 times, avg 3µs/call:
# 5000 times (14.7ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 14.9ms within XML::Parser::Expat::SetStartElementHandler which was called 5000 times, avg 3µs/call:
# 5000 times (14.9ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 16.7ms within XML::Parser::Expat::SetUnparsedEntityDeclHandler which was called 5000 times, avg 3µs/call:
# 5000 times (16.7ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 14.9ms within XML::Parser::Expat::SetXMLDeclHandler which was called 5000 times, avg 3µs/call:
# 5000 times (14.9ms+0s) by XML::Parser::Expat::setHandlers at line 125, avg 3µs/call | |||||
# spent 94µs within XML::Parser::Expat::bootstrap which was called:
# once (94µs+0s) by DynaLoader::bootstrap at line 215 of DynaLoader.pm |