Filename | /usr/lib/x86_64-linux-gnu/perl5/5.20/XML/Parser.pm |
Statements | Executed 319 statements in 2.10ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 3.36ms | 5.59ms | BEGIN@17 | XML::Parser::
2 | 1 | 1 | 106µs | 16.2ms | parse | XML::Parser::
2 | 1 | 1 | 58µs | 58µs | setHandlers | XML::Parser::
2 | 1 | 1 | 40µs | 40µs | new | XML::Parser::
2 | 1 | 1 | 39µs | 16.3ms | parsefile | XML::Parser::
2 | 1 | 1 | 26µs | 26µs | CORE:open (opcode) | XML::Parser::
1 | 1 | 1 | 11µs | 22µs | BEGIN@11 | XML::Parser::
2 | 1 | 1 | 10µs | 10µs | CORE:close (opcode) | XML::Parser::
1 | 1 | 1 | 8µs | 43µs | BEGIN@15 | XML::Parser::
1 | 1 | 1 | 6µs | 32µs | BEGIN@13 | XML::Parser::
2 | 1 | 1 | 5µs | 5µs | CORE:binmode (opcode) | XML::Parser::
0 | 0 | 0 | 0s | 0s | file_ext_ent_cleanup | XML::Parser::
0 | 0 | 0 | 0s | 0s | file_ext_ent_handler | XML::Parser::
0 | 0 | 0 | 0s | 0s | initial_ext_ent_handler | XML::Parser::
0 | 0 | 0 | 0s | 0s | parse_start | XML::Parser::
0 | 0 | 0 | 0s | 0s | parsestring | XML::Parser::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # XML::Parser | ||||
2 | # | ||||
3 | # Copyright (c) 1998-2000 Larry Wall and Clark Cooper | ||||
4 | # All rights reserved. | ||||
5 | # | ||||
6 | # This program is free software; you can redistribute it and/or | ||||
7 | # modify it under the same terms as Perl itself. | ||||
8 | |||||
9 | package XML::Parser; | ||||
10 | |||||
11 | 2 | 28µs | 2 | 33µs | # spent 22µs (11+11) within XML::Parser::BEGIN@11 which was called:
# once (11µs+11µs) by XML::SAX::Expat::BEGIN@11 at line 11 # spent 22µs making 1 call to XML::Parser::BEGIN@11
# spent 11µs making 1 call to strict::import |
12 | |||||
13 | 2 | 23µs | 2 | 57µs | # spent 32µs (6+25) within XML::Parser::BEGIN@13 which was called:
# once (6µs+25µs) by XML::SAX::Expat::BEGIN@11 at line 13 # spent 32µs making 1 call to XML::Parser::BEGIN@13
# spent 25µs making 1 call to vars::import |
14 | |||||
15 | 2 | 43µs | 2 | 78µs | # spent 43µs (8+35) within XML::Parser::BEGIN@15 which was called:
# once (8µs+35µs) by XML::SAX::Expat::BEGIN@11 at line 15 # spent 43µs making 1 call to XML::Parser::BEGIN@15
# spent 35µs making 1 call to Exporter::import |
16 | |||||
17 | # spent 5.59ms (3.36+2.23) within XML::Parser::BEGIN@17 which was called:
# once (3.36ms+2.23ms) by XML::SAX::Expat::BEGIN@11 at line 22 | ||||
18 | 1 | 620µs | require XML::Parser::Expat; | ||
19 | 1 | 200ns | $VERSION = '2.41'; | ||
20 | 1 | 3µs | die "Parser.pm and Expat.pm versions don't match" | ||
21 | unless $VERSION eq $XML::Parser::Expat::VERSION; | ||||
22 | 1 | 1.11ms | 1 | 5.59ms | } # spent 5.59ms making 1 call to XML::Parser::BEGIN@17 |
23 | |||||
24 | 1 | 300ns | $LWP_load_failed = 0; | ||
25 | |||||
26 | # spent 40µs within XML::Parser::new which was called 2 times, avg 20µs/call:
# 2 times (40µs+0s) by XML::SAX::Expat::_create_parser at line 96 of XML/SAX/Expat.pm, avg 20µs/call | ||||
27 | 2 | 2µs | my ($class, %args) = @_; | ||
28 | 2 | 1µs | my $style = $args{Style}; | ||
29 | |||||
30 | 2 | 2µs | my $nonexopt = $args{Non_Expat_Options} ||= {}; | ||
31 | |||||
32 | 2 | 1µs | $nonexopt->{Style} = 1; | ||
33 | 2 | 600ns | $nonexopt->{Non_Expat_Options} = 1; | ||
34 | 2 | 700ns | $nonexopt->{Handlers} = 1; | ||
35 | 2 | 1µs | $nonexopt->{_HNDL_TYPES} = 1; | ||
36 | 2 | 800ns | $nonexopt->{NoLWP} = 1; | ||
37 | |||||
38 | 2 | 16µs | $args{_HNDL_TYPES} = {%XML::Parser::Expat::Handler_Setters}; | ||
39 | 2 | 1µs | $args{_HNDL_TYPES}->{Init} = 1; | ||
40 | 2 | 2µs | $args{_HNDL_TYPES}->{Final} = 1; | ||
41 | |||||
42 | 2 | 900ns | $args{Handlers} ||= {}; | ||
43 | 2 | 600ns | my $handlers = $args{Handlers}; | ||
44 | |||||
45 | 2 | 600ns | if (defined($style)) { | ||
46 | my $stylepkg = $style; | ||||
47 | |||||
48 | if ($stylepkg !~ /::/) { | ||||
49 | $stylepkg = "\u$style"; | ||||
50 | |||||
51 | eval { | ||||
52 | my $fullpkg = 'XML::Parser::Style::' . $stylepkg; | ||||
53 | my $stylefile = $fullpkg; | ||||
54 | $stylefile =~ s/::/\//g; | ||||
55 | require "$stylefile.pm"; | ||||
56 | $stylepkg = $fullpkg; | ||||
57 | }; | ||||
58 | if ($@) { | ||||
59 | # fallback to old behaviour | ||||
60 | $stylepkg = 'XML::Parser::' . $stylepkg; | ||||
61 | } | ||||
62 | } | ||||
63 | |||||
64 | my $htype; | ||||
65 | foreach $htype (keys %{$args{_HNDL_TYPES}}) { | ||||
66 | # Handlers explicity given override | ||||
67 | # handlers from the Style package | ||||
68 | unless (defined($handlers->{$htype})) { | ||||
69 | |||||
70 | # A handler in the style package must either have | ||||
71 | # exactly the right case as the type name or a | ||||
72 | # completely lower case version of it. | ||||
73 | |||||
74 | my $hname = "${stylepkg}::$htype"; | ||||
75 | if (defined(&$hname)) { | ||||
76 | $handlers->{$htype} = \&$hname; | ||||
77 | next; | ||||
78 | } | ||||
79 | |||||
80 | $hname = "${stylepkg}::\L$htype"; | ||||
81 | if (defined(&$hname)) { | ||||
82 | $handlers->{$htype} = \&$hname; | ||||
83 | next; | ||||
84 | } | ||||
85 | } | ||||
86 | } | ||||
87 | } | ||||
88 | |||||
89 | 2 | 1µs | unless (defined($handlers->{ExternEnt}) | ||
90 | or defined ($handlers->{ExternEntFin})) { | ||||
91 | |||||
92 | 2 | 1µs | if ($args{NoLWP} or $LWP_load_failed) { | ||
93 | $handlers->{ExternEnt} = \&file_ext_ent_handler; | ||||
94 | $handlers->{ExternEntFin} = \&file_ext_ent_cleanup; | ||||
95 | } | ||||
96 | else { | ||||
97 | # The following just bootstraps the real LWP external entity | ||||
98 | # handler | ||||
99 | |||||
100 | 2 | 2µs | $handlers->{ExternEnt} = \&initial_ext_ent_handler; | ||
101 | |||||
102 | # No cleanup function available until LWPExternEnt.pl loaded | ||||
103 | } | ||||
104 | } | ||||
105 | |||||
106 | 2 | 2µs | $args{Pkg} ||= caller; | ||
107 | 2 | 7µs | bless \%args, $class; | ||
108 | } # End of new | ||||
109 | |||||
110 | # spent 58µs within XML::Parser::setHandlers which was called 2 times, avg 29µs/call:
# 2 times (58µs+0s) by XML::SAX::Expat::_create_parser at line 98 of XML/SAX/Expat.pm, avg 29µs/call | ||||
111 | 2 | 8µs | my ($self, @handler_pairs) = @_; | ||
112 | |||||
113 | 2 | 2µs | croak("Uneven number of arguments to setHandlers method") | ||
114 | if (int(@handler_pairs) & 1); | ||||
115 | |||||
116 | 2 | 400ns | my @ret; | ||
117 | 2 | 1µs | while (@handler_pairs) { | ||
118 | 34 | 5µs | my $type = shift @handler_pairs; | ||
119 | 34 | 3µs | my $handler = shift @handler_pairs; | ||
120 | 34 | 7µs | unless (defined($self->{_HNDL_TYPES}->{$type})) { | ||
121 | my @types = sort keys %{$self->{_HNDL_TYPES}}; | ||||
122 | |||||
123 | croak("Unknown Parser handler type: $type\n Valid types: @types"); | ||||
124 | } | ||||
125 | 34 | 10µs | push(@ret, $type, $self->{Handlers}->{$type}); | ||
126 | 34 | 17µs | $self->{Handlers}->{$type} = $handler; | ||
127 | } | ||||
128 | |||||
129 | 2 | 6µs | return @ret; | ||
130 | } | ||||
131 | |||||
132 | sub parse_start { | ||||
133 | my $self = shift; | ||||
134 | my @expat_options = (); | ||||
135 | |||||
136 | my ($key, $val); | ||||
137 | while (($key, $val) = each %{$self}) { | ||||
138 | push (@expat_options, $key, $val) | ||||
139 | unless exists $self->{Non_Expat_Options}->{$key}; | ||||
140 | } | ||||
141 | |||||
142 | my %handlers = %{$self->{Handlers}}; | ||||
143 | my $init = delete $handlers{Init}; | ||||
144 | my $final = delete $handlers{Final}; | ||||
145 | |||||
146 | my $expatnb = XML::Parser::ExpatNB->new(@expat_options, @_); | ||||
147 | $expatnb->setHandlers(%handlers); | ||||
148 | |||||
149 | &$init($expatnb) | ||||
150 | if defined($init); | ||||
151 | |||||
152 | $expatnb->{_State_} = 1; | ||||
153 | |||||
154 | $expatnb->{FinalHandler} = $final | ||||
155 | if defined($final); | ||||
156 | |||||
157 | return $expatnb; | ||||
158 | } | ||||
159 | |||||
160 | # spent 16.2ms (106µs+16.1) within XML::Parser::parse which was called 2 times, avg 8.10ms/call:
# 2 times (106µs+16.1ms) by XML::Parser::parsefile at line 233, avg 8.10ms/call | ||||
161 | 2 | 800ns | my $self = shift; | ||
162 | 2 | 2µs | my $arg = shift; | ||
163 | 2 | 1µs | my @expat_options = (); | ||
164 | 2 | 200ns | my ($key, $val); | ||
165 | 2 | 4µs | while (($key, $val) = each %{$self}) { | ||
166 | 14 | 12µs | push(@expat_options, $key, $val) | ||
167 | unless exists $self->{Non_Expat_Options}->{$key}; | ||||
168 | } | ||||
169 | |||||
170 | 2 | 8µs | 2 | 54µs | my $expat = XML::Parser::Expat->new(@expat_options, @_); # spent 54µs making 2 calls to XML::Parser::Expat::new, avg 27µs/call |
171 | 2 | 10µs | my %handlers = %{$self->{Handlers}}; | ||
172 | 2 | 2µs | my $init = delete $handlers{Init}; | ||
173 | 2 | 700ns | my $final = delete $handlers{Final}; | ||
174 | |||||
175 | 2 | 6µs | 2 | 209µs | $expat->setHandlers(%handlers); # spent 209µs making 2 calls to XML::Parser::Expat::setHandlers, avg 105µs/call |
176 | |||||
177 | 2 | 4µs | 2 | 21µs | if ($self->{Base}) { # spent 21µs making 2 calls to XML::Parser::Expat::base, avg 11µs/call |
178 | $expat->base($self->{Base}); | ||||
179 | } | ||||
180 | |||||
181 | 2 | 4µs | 2 | 3µs | &$init($expat) # spent 3µs making 2 calls to XML::SAX::Expat::_handle_init, avg 1µs/call |
182 | if defined($init); | ||||
183 | |||||
184 | 2 | 1µs | my @result = (); | ||
185 | 2 | 300ns | my $result; | ||
186 | 2 | 1µs | eval { | ||
187 | 2 | 5µs | 2 | 15.7ms | $result = $expat->parse($arg); # spent 15.7ms making 2 calls to XML::Parser::Expat::parse, avg 7.86ms/call |
188 | }; | ||||
189 | 2 | 800ns | my $err = $@; | ||
190 | 2 | 300ns | if ($err) { | ||
191 | $expat->release; | ||||
192 | die $err; | ||||
193 | } | ||||
194 | |||||
195 | 2 | 2µs | if ($result and defined($final)) { | ||
196 | if (wantarray) { | ||||
197 | @result = &$final($expat); | ||||
198 | } | ||||
199 | else { | ||||
200 | 2 | 3µs | 2 | 52µs | $result = &$final($expat); # spent 52µs making 2 calls to XML::SAX::Expat::_handle_final, avg 26µs/call |
201 | } | ||||
202 | } | ||||
203 | |||||
204 | 2 | 4µs | 2 | 11µs | $expat->release; # spent 11µs making 2 calls to XML::Parser::Expat::release, avg 5µs/call |
205 | |||||
206 | 2 | 800ns | return unless defined wantarray; | ||
207 | 2 | 9µs | return wantarray ? @result : $result; | ||
208 | } | ||||
209 | |||||
210 | sub parsestring { | ||||
211 | my $self = shift; | ||||
212 | $self->parse(@_); | ||||
213 | } | ||||
214 | |||||
215 | # spent 16.3ms (39µs+16.2) within XML::Parser::parsefile which was called 2 times, avg 8.14ms/call:
# 2 times (39µs+16.2ms) by XML::SAX::Expat::_parse_systemid at line 75 of XML/SAX/Expat.pm, avg 8.14ms/call | ||||
216 | 2 | 500ns | my $self = shift; | ||
217 | 2 | 500ns | my $file = shift; | ||
218 | 2 | 2µs | local(*FILE); | ||
219 | 2 | 34µs | 2 | 26µs | open(FILE, $file) or croak "Couldn't open $file:\n$!"; # spent 26µs making 2 calls to XML::Parser::CORE:open, avg 13µs/call |
220 | 2 | 10µs | 2 | 5µs | binmode(FILE); # spent 5µs making 2 calls to XML::Parser::CORE:binmode, avg 3µs/call |
221 | 2 | 500ns | my @ret; | ||
222 | my $ret; | ||||
223 | |||||
224 | 2 | 1µs | $self->{Base} = $file; | ||
225 | |||||
226 | 2 | 1µs | if (wantarray) { | ||
227 | eval { | ||||
228 | @ret = $self->parse(*FILE, @_); | ||||
229 | }; | ||||
230 | } | ||||
231 | else { | ||||
232 | 2 | 1µs | eval { | ||
233 | 2 | 14µs | 4 | 16.2ms | $ret = $self->parse(*FILE, @_); # spent 16.2ms making 2 calls to XML::Parser::parse, avg 8.10ms/call
# spent 20µs making 2 calls to XML::Parser::Expat::DESTROY, avg 10µs/call |
234 | }; | ||||
235 | } | ||||
236 | 2 | 700ns | my $err = $@; | ||
237 | 2 | 16µs | 2 | 10µs | close(FILE); # spent 10µs making 2 calls to XML::Parser::CORE:close, avg 5µs/call |
238 | 2 | 500ns | die $err if $err; | ||
239 | |||||
240 | 2 | 700ns | return unless defined wantarray; | ||
241 | 2 | 7µs | return wantarray ? @ret : $ret; | ||
242 | } | ||||
243 | |||||
244 | sub initial_ext_ent_handler { | ||||
245 | # This just bootstraps in the real lwp_ext_ent_handler which | ||||
246 | # also loads the URI and LWP modules. | ||||
247 | |||||
248 | unless ($LWP_load_failed) { | ||||
249 | local($^W) = 0; | ||||
250 | |||||
251 | my $stat = | ||||
252 | eval { | ||||
253 | require('XML/Parser/LWPExternEnt.pl'); | ||||
254 | }; | ||||
255 | |||||
256 | if ($stat) { | ||||
257 | $_[0]->setHandlers(ExternEnt => \&lwp_ext_ent_handler, | ||||
258 | ExternEntFin => \&lwp_ext_ent_cleanup); | ||||
259 | |||||
260 | goto &lwp_ext_ent_handler; | ||||
261 | } | ||||
262 | |||||
263 | # Failed to load lwp handler, act as if NoLWP | ||||
264 | |||||
265 | $LWP_load_failed = 1; | ||||
266 | |||||
267 | my $cmsg = "Couldn't load LWP based external entity handler\n"; | ||||
268 | $cmsg .= "Switching to file-based external entity handler\n"; | ||||
269 | $cmsg .= " (To avoid this message, use NoLWP option to XML::Parser)\n"; | ||||
270 | warn($cmsg); | ||||
271 | } | ||||
272 | |||||
273 | $_[0]->setHandlers(ExternEnt => \&file_ext_ent_handler, | ||||
274 | ExternEntFin => \&file_ext_ent_cleanup); | ||||
275 | goto &file_ext_ent_handler; | ||||
276 | |||||
277 | } | ||||
278 | |||||
279 | sub file_ext_ent_handler { | ||||
280 | my ($xp, $base, $path) = @_; | ||||
281 | |||||
282 | # Prepend base only for relative paths | ||||
283 | |||||
284 | if (defined($base) | ||||
285 | and not ($path =~ m!^(?:[\\/]|\w+:)!)) | ||||
286 | { | ||||
287 | my $newpath = $base; | ||||
288 | $newpath =~ s![^\\/:]*$!$path!; | ||||
289 | $path = $newpath; | ||||
290 | } | ||||
291 | |||||
292 | if ($path =~ /^\s*[|>+]/ | ||||
293 | or $path =~ /\|\s*$/) { | ||||
294 | $xp->{ErrorMessage} | ||||
295 | .= "System ID ($path) contains Perl IO control characters"; | ||||
296 | return undef; | ||||
297 | } | ||||
298 | |||||
299 | require IO::File; | ||||
300 | my $fh = IO::File->new($path); | ||||
301 | unless (defined $fh) { | ||||
302 | $xp->{ErrorMessage} | ||||
303 | .= "Failed to open $path:\n$!"; | ||||
304 | return undef; | ||||
305 | } | ||||
306 | |||||
307 | $xp->{_BaseStack} ||= []; | ||||
308 | $xp->{_FhStack} ||= []; | ||||
309 | |||||
310 | push(@{$xp->{_BaseStack}}, $base); | ||||
311 | push(@{$xp->{_FhStack}}, $fh); | ||||
312 | |||||
313 | $xp->base($path); | ||||
314 | |||||
315 | return $fh; | ||||
316 | } | ||||
317 | |||||
318 | sub file_ext_ent_cleanup { | ||||
319 | my ($xp) = @_; | ||||
320 | |||||
321 | my $fh = pop(@{$xp->{_FhStack}}); | ||||
322 | $fh->close; | ||||
323 | |||||
324 | my $base = pop(@{$xp->{_BaseStack}}); | ||||
325 | $xp->base($base); | ||||
326 | } | ||||
327 | |||||
328 | 1 | 2µs | 1; | ||
329 | |||||
330 | __END__ | ||||
# spent 5µs within XML::Parser::CORE:binmode which was called 2 times, avg 3µs/call:
# 2 times (5µs+0s) by XML::Parser::parsefile at line 220, avg 3µs/call | |||||
# spent 10µs within XML::Parser::CORE:close which was called 2 times, avg 5µs/call:
# 2 times (10µs+0s) by XML::Parser::parsefile at line 237, avg 5µs/call | |||||
# spent 26µs within XML::Parser::CORE:open which was called 2 times, avg 13µs/call:
# 2 times (26µs+0s) by XML::Parser::parsefile at line 219, avg 13µs/call |