Filename | /usr/lib/x86_64-linux-gnu/perl5/5.20/XML/Parser/Expat.pm |
Statements | Executed 344 statements in 5.66ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
2 | 1 | 1 | 4.78ms | 15.7ms | ParseStream (xsub) | XML::Parser::Expat::
10 | 1 | 1 | 1.05ms | 1.05ms | CORE:ftdir (opcode) | XML::Parser::Expat::
2 | 1 | 1 | 162µs | 209µs | setHandlers | XML::Parser::Expat::
1 | 1 | 1 | 43µs | 43µs | bootstrap (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 37µs | 15.7ms | parse | XML::Parser::Expat::
2 | 1 | 1 | 30µs | 30µs | ParserCreate (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 24µs | 54µs | new | XML::Parser::Expat::
2 | 1 | 1 | 15µs | 21µs | base | XML::Parser::Expat::
1 | 1 | 1 | 12µs | 22µs | BEGIN@5 | XML::Parser::Expat::
2 | 1 | 1 | 11µs | 11µs | ParserFree (xsub) | XML::Parser::Expat::
1 | 1 | 1 | 11µs | 22µs | BEGIN@455 | XML::Parser::Expat::
1 | 1 | 1 | 11µs | 39µs | BEGIN@591 | XML::Parser::ExpatNB::
1 | 1 | 1 | 10µs | 36µs | BEGIN@501 | XML::Parser::ContentModel::
2 | 1 | 1 | 9µs | 11µs | release | XML::Parser::Expat::
2 | 1 | 1 | 8µs | 20µs | DESTROY | XML::Parser::Expat::
1 | 1 | 1 | 8µs | 25µs | BEGIN@590 | XML::Parser::ExpatNB::
1 | 1 | 1 | 7µs | 63µs | BEGIN@6 | XML::Parser::Expat::
1 | 1 | 1 | 7µs | 36µs | BEGIN@8 | XML::Parser::Expat::
2 | 1 | 1 | 4µs | 4µs | SetBase (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 4µs | 4µs | SetAttListDeclHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 4µs | 4µs | SetCommentHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 4µs | 4µs | SetNotationDeclHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 3µs | 3µs | SetUnparsedEntityDeclHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 3µs | 3µs | SetElementDeclHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 3µs | 3µs | SetProcessingInstructionHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 3µs | 3µs | SetEntityDeclHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 3µs | 3µs | SetExternalEntityRefHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 3µs | 3µs | SetStartCdataHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 3µs | 3µs | SetCharacterDataHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 3µs | 3µs | SetXMLDeclHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 3µs | 3µs | SetEndDoctypeHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 2µs | 2µs | SetEndCdataHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 2µs | 2µs | GetBase (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 2µs | 2µs | SetDoctypeHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 2µs | 2µs | SetEndElementHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 2µs | 2µs | SetStartElementHandler (xsub) | XML::Parser::Expat::
2 | 1 | 1 | 2µs | 2µs | ParserRelease (xsub) | 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 | 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 | 11µs | require 5.004; | ||
4 | |||||
5 | 2 | 31µs | 2 | 32µs | # spent 22µs (12+10) within XML::Parser::Expat::BEGIN@5 which was called:
# once (12µs+10µs) by XML::Parser::BEGIN@17 at line 5 # spent 22µs making 1 call to XML::Parser::Expat::BEGIN@5
# spent 10µs making 1 call to strict::import |
6 | 1 | 3µs | 1 | 57µs | # spent 63µs (7+57) within XML::Parser::Expat::BEGIN@6 which was called:
# once (7µs+57µs) by XML::Parser::BEGIN@17 at line 7 # spent 57µs making 1 call to vars::import |
7 | 1 | 21µs | 1 | 63µs | $have_File_Spec); # spent 63µs making 1 call to XML::Parser::Expat::BEGIN@6 |
8 | 2 | 1.71ms | 2 | 66µs | # spent 36µs (7+30) within XML::Parser::Expat::BEGIN@8 which was called:
# once (7µs+30µs) by XML::Parser::BEGIN@17 at line 8 # spent 36µs making 1 call to XML::Parser::Expat::BEGIN@8
# spent 30µs making 1 call to Exporter::import |
9 | |||||
10 | 1 | 400ns | require DynaLoader; | ||
11 | |||||
12 | 1 | 6µs | @ISA = qw(DynaLoader); | ||
13 | 1 | 200ns | $VERSION = "2.41"; | ||
14 | |||||
15 | 1 | 1µs | $have_File_Spec = $INC{'File/Spec.pm'} || do 'File/Spec.pm'; | ||
16 | |||||
17 | 1 | 400ns | %Encoding_Table = (); | ||
18 | 1 | 900ns | if ($have_File_Spec) { | ||
19 | 1 | 1.14ms | 31 | 1.09ms | @Encoding_Path = (grep(-d $_, # spent 1.05ms making 10 calls to XML::Parser::Expat::CORE:ftdir, avg 105µs/call
# spent 29µs making 10 calls to File::Spec::Unix::catdir, avg 3µs/call
# spent 4µs making 10 calls to File::Spec::Unix::canonpath, avg 430ns/call
# spent 3µ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 | 8µs | 1 | 906µs | bootstrap XML::Parser::Expat $VERSION; # spent 906µs making 1 call to DynaLoader::bootstrap |
30 | |||||
31 | 1 | 10µ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 54µs (24+30) within XML::Parser::Expat::new which was called 2 times, avg 27µs/call:
# 2 times (24µs+30µs) by XML::Parser::parse at line 170 of XML/Parser.pm, avg 27µs/call | ||||
53 | 2 | 3µs | my ($class, %args) = @_; | ||
54 | 2 | 2µs | my $self = bless \%args, $_[0]; | ||
55 | 2 | 900ns | $args{_State_} = 0; | ||
56 | 2 | 1µs | $args{Context} = []; | ||
57 | 2 | 1µs | $args{Namespaces} ||= 0; | ||
58 | 2 | 2µs | $args{ErrorMessage} ||= ''; | ||
59 | 2 | 500ns | if ($args{Namespaces}) { | ||
60 | $args{Namespace_Table} = {}; | ||||
61 | $args{Namespace_List} = [undef]; | ||||
62 | $args{Prefix_Table} = {}; | ||||
63 | $args{New_Prefixes} = []; | ||||
64 | } | ||||
65 | 2 | 1µs | $args{_Setters} = \%Handler_Setters; | ||
66 | 2 | 40µs | 2 | 30µs | $args{Parser} = ParserCreate($self, $args{ProtocolEncoding}, # spent 30µs making 2 calls to XML::Parser::Expat::ParserCreate, avg 15µs/call |
67 | $args{Namespaces}); | ||||
68 | 2 | 4µs | $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 209µs (162+47) within XML::Parser::Expat::setHandlers which was called 2 times, avg 105µs/call:
# 2 times (162µs+47µs) by XML::Parser::parse at line 175 of XML/Parser.pm, avg 105µs/call | ||||
105 | 2 | 4µs | my ($self, @handler_pairs) = @_; | ||
106 | |||||
107 | 2 | 1µs | croak("Uneven number of arguments to setHandlers method") | ||
108 | if (int(@handler_pairs) & 1); | ||||
109 | |||||
110 | 2 | 300ns | my @ret; | ||
111 | |||||
112 | 2 | 1µs | while (@handler_pairs) { | ||
113 | 32 | 6µs | my $type = shift @handler_pairs; | ||
114 | 32 | 4µs | my $handler = shift @handler_pairs; | ||
115 | 32 | 13µs | croak "Handler for $type not a Code ref" | ||
116 | unless (! defined($handler) or ! $handler or ref($handler) eq 'CODE'); | ||||
117 | |||||
118 | 32 | 13µs | my $hndl = $self->{_Setters}->{$type}; | ||
119 | |||||
120 | 32 | 2µs | unless (defined($hndl)) { | ||
121 | my @types = sort keys %{$self->{_Setters}}; | ||||
122 | croak("Unknown Expat handler type: $type\n Valid types: @types"); | ||||
123 | } | ||||
124 | |||||
125 | 32 | 138µs | 32 | 47µs | my $old = &$hndl($self->{Parser}, $handler); # spent 4µs making 2 calls to XML::Parser::Expat::SetAttListDeclHandler, avg 2µs/call
# spent 4µs making 2 calls to XML::Parser::Expat::SetCommentHandler, avg 2µs/call
# spent 4µs making 2 calls to XML::Parser::Expat::SetNotationDeclHandler, avg 2µs/call
# spent 3µs making 2 calls to XML::Parser::Expat::SetUnparsedEntityDeclHandler, avg 2µs/call
# spent 3µs making 2 calls to XML::Parser::Expat::SetElementDeclHandler, avg 2µs/call
# spent 3µs making 2 calls to XML::Parser::Expat::SetProcessingInstructionHandler, avg 2µs/call
# spent 3µs making 2 calls to XML::Parser::Expat::SetEntityDeclHandler, avg 2µs/call
# spent 3µs making 2 calls to XML::Parser::Expat::SetExternalEntityRefHandler, avg 2µs/call
# spent 3µs making 2 calls to XML::Parser::Expat::SetStartCdataHandler, avg 2µs/call
# spent 3µs making 2 calls to XML::Parser::Expat::SetCharacterDataHandler, avg 1µs/call
# spent 3µs making 2 calls to XML::Parser::Expat::SetXMLDeclHandler, avg 1µs/call
# spent 3µs making 2 calls to XML::Parser::Expat::SetEndDoctypeHandler, avg 1µs/call
# spent 2µs making 2 calls to XML::Parser::Expat::SetEndCdataHandler, avg 1µs/call
# spent 2µs making 2 calls to XML::Parser::Expat::SetDoctypeHandler, avg 1µs/call
# spent 2µs making 2 calls to XML::Parser::Expat::SetEndElementHandler, avg 1µs/call
# spent 2µs making 2 calls to XML::Parser::Expat::SetStartElementHandler, avg 800ns/call |
126 | 32 | 22µs | push (@ret, $type, $old); | ||
127 | } | ||||
128 | |||||
129 | 2 | 5µs | 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 | # spent 21µs (15+6) within XML::Parser::Expat::base which was called 2 times, avg 11µs/call:
# 2 times (15µs+6µs) by XML::Parser::parse at line 177 of XML/Parser.pm, avg 11µs/call | ||||
198 | 2 | 900ns | my ($self, $newbase) = @_; | ||
199 | 2 | 600ns | my $p = $self->{Parser}; | ||
200 | 2 | 7µs | 2 | 2µs | my $oldbase = GetBase($p); # spent 2µs making 2 calls to XML::Parser::Expat::GetBase, avg 1µs/call |
201 | 2 | 10µs | 2 | 4µs | SetBase($p, $newbase) if @_ > 1; # spent 4µs making 2 calls to XML::Parser::Expat::SetBase, avg 2µs/call |
202 | 2 | 8µs | 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 11µs (9+1) within XML::Parser::Expat::release which was called 2 times, avg 5µs/call:
# 2 times (9µs+1µs) by XML::Parser::parse at line 204 of XML/Parser.pm, avg 5µs/call | ||||
426 | 2 | 700ns | my $self = shift; | ||
427 | 2 | 11µs | 2 | 2µs | ParserRelease($self->{Parser}); # spent 2µs making 2 calls to XML::Parser::Expat::ParserRelease, avg 750ns/call |
428 | } | ||||
429 | |||||
430 | # spent 20µs (8+11) within XML::Parser::Expat::DESTROY which was called 2 times, avg 10µs/call:
# 2 times (8µs+11µs) by XML::Parser::parse at line 233 of XML/Parser.pm, avg 10µs/call | ||||
431 | 2 | 500ns | my $self = shift; | ||
432 | 2 | 20µs | 2 | 11µs | ParserFree($self->{Parser}); # spent 11µs making 2 calls to XML::Parser::Expat::ParserFree, avg 6µs/call |
433 | } | ||||
434 | |||||
435 | # spent 15.7ms (37µs+15.7) within XML::Parser::Expat::parse which was called 2 times, avg 7.86ms/call:
# 2 times (37µs+15.7ms) by XML::Parser::parse at line 187 of XML/Parser.pm, avg 7.86ms/call | ||||
436 | 2 | 500ns | my $self = shift; | ||
437 | 2 | 2µs | my $arg = shift; | ||
438 | 2 | 1µs | croak "Parse already in progress (Expat)" if $self->{_State_}; | ||
439 | 2 | 800ns | $self->{_State_} = 1; | ||
440 | 2 | 600ns | my $parser = $self->{Parser}; | ||
441 | 2 | 200ns | my $ioref; | ||
442 | 2 | 500ns | my $result = 0; | ||
443 | |||||
444 | 2 | 1µs | if (defined $arg) { | ||
445 | 2 | 2µs | local *@; | ||
446 | 2 | 4µs | if (ref($arg) and UNIVERSAL::isa($arg, 'IO::Handle')) { | ||
447 | $ioref = $arg; | ||||
448 | } elsif ($] < 5.008 and defined tied($arg)) { | ||||
449 | require IO::Handle; | ||||
450 | $ioref = $arg; | ||||
451 | } | ||||
452 | else { | ||||
453 | 2 | 2µs | require IO::Handle; | ||
454 | 2 | 1µs | eval { | ||
455 | 2 | 226µs | 2 | 32µs | # spent 22µs (11+11) within XML::Parser::Expat::BEGIN@455 which was called:
# once (11µs+11µs) by XML::Parser::BEGIN@17 at line 455 # spent 22µs making 1 call to XML::Parser::Expat::BEGIN@455
# spent 11µs making 1 call to strict::unimport |
456 | 2 | 3µs | $ioref = *{$arg}{IO} if defined *{$arg}; | ||
457 | }; | ||||
458 | } | ||||
459 | } | ||||
460 | |||||
461 | 2 | 800ns | if (defined($ioref)) { | ||
462 | 2 | 700ns | my $delim = $self->{Stream_Delimiter}; | ||
463 | 2 | 300ns | my $prev_rs; | ||
464 | 2 | 1µs | my $ioclass = ref $ioref; | ||
465 | 2 | 1µs | $ioclass = "IO::Handle" if !length $ioclass; | ||
466 | |||||
467 | 2 | 400ns | $prev_rs = $ioclass->input_record_separator("\n$delim\n") | ||
468 | if defined($delim); | ||||
469 | |||||
470 | 2 | 1.44ms | 814 | 26.6ms | $result = ParseStream($parser, $ioref, $delim); # spent 15.7ms making 2 calls to XML::Parser::Expat::ParseStream, avg 7.84ms/call
# spent 4.64ms making 142 calls to XML::SAX::Expat::_handle_start, avg 33µs/call
# spent 3.91ms making 478 calls to XML::SAX::Expat::_handle_char, avg 8µs/call
# spent 2.02ms making 142 calls to XML::SAX::Expat::_handle_end, avg 14µs/call
# spent 281µs making 46 calls to XML::SAX::Expat::_handle_comment, avg 6µs/call
# spent 57µs making 4 calls to IO::Handle::read, avg 14µs/call |
471 | |||||
472 | 2 | 2µs | $ioclass->input_record_separator($prev_rs) | ||
473 | if defined($delim); | ||||
474 | } else { | ||||
475 | $result = ParseString($parser, $arg); | ||||
476 | } | ||||
477 | |||||
478 | 2 | 1µs | $self->{_State_} = 2; | ||
479 | 2 | 6µs | $result or croak $self->{ErrorMessage}; | ||
480 | } | ||||
481 | |||||
482 | sub parsestring { | ||||
483 | my $self = shift; | ||||
484 | $self->parse(@_); | ||||
485 | } | ||||
486 | |||||
487 | sub parsefile { | ||||
488 | my $self = shift; | ||||
489 | croak "Parser has already been used" if $self->{_State_}; | ||||
490 | local(*FILE); | ||||
491 | open(FILE, $_[0]) or croak "Couldn't open $_[0]:\n$!"; | ||||
492 | binmode(FILE); | ||||
493 | my $ret = $self->parse(*FILE); | ||||
494 | close(FILE); | ||||
495 | $ret; | ||||
496 | } | ||||
497 | |||||
498 | ################################################################ | ||||
499 | package #hide from PAUSE | ||||
500 | XML::Parser::ContentModel; | ||||
501 | 2 | 362µs | 2 | 62µs | # spent 36µs (10+26) within XML::Parser::ContentModel::BEGIN@501 which was called:
# once (10µs+26µs) by XML::Parser::BEGIN@17 at line 501 # spent 36µs making 1 call to XML::Parser::ContentModel::BEGIN@501
# spent 26µs making 1 call to overload::import |
502 | |||||
503 | sub EMPTY () {1} | ||||
504 | sub ANY () {2} | ||||
505 | sub MIXED () {3} | ||||
506 | sub NAME () {4} | ||||
507 | sub CHOICE () {5} | ||||
508 | sub SEQ () {6} | ||||
509 | |||||
510 | |||||
511 | sub isempty { | ||||
512 | return $_[0]->{Type} == EMPTY; | ||||
513 | } | ||||
514 | |||||
515 | sub isany { | ||||
516 | return $_[0]->{Type} == ANY; | ||||
517 | } | ||||
518 | |||||
519 | sub ismixed { | ||||
520 | return $_[0]->{Type} == MIXED; | ||||
521 | } | ||||
522 | |||||
523 | sub isname { | ||||
524 | return $_[0]->{Type} == NAME; | ||||
525 | } | ||||
526 | |||||
527 | sub name { | ||||
528 | return $_[0]->{Tag}; | ||||
529 | } | ||||
530 | |||||
531 | sub ischoice { | ||||
532 | return $_[0]->{Type} == CHOICE; | ||||
533 | } | ||||
534 | |||||
535 | sub isseq { | ||||
536 | return $_[0]->{Type} == SEQ; | ||||
537 | } | ||||
538 | |||||
539 | sub quant { | ||||
540 | return $_[0]->{Quant}; | ||||
541 | } | ||||
542 | |||||
543 | sub children { | ||||
544 | my $children = $_[0]->{Children}; | ||||
545 | if (defined $children) { | ||||
546 | return @$children; | ||||
547 | } | ||||
548 | return undef; | ||||
549 | } | ||||
550 | |||||
551 | sub asString { | ||||
552 | my ($self) = @_; | ||||
553 | my $ret; | ||||
554 | |||||
555 | if ($self->{Type} == NAME) { | ||||
556 | $ret = $self->{Tag}; | ||||
557 | } | ||||
558 | elsif ($self->{Type} == EMPTY) { | ||||
559 | return "EMPTY"; | ||||
560 | } | ||||
561 | elsif ($self->{Type} == ANY) { | ||||
562 | return "ANY"; | ||||
563 | } | ||||
564 | elsif ($self->{Type} == MIXED) { | ||||
565 | $ret = '(#PCDATA'; | ||||
566 | foreach (@{$self->{Children}}) { | ||||
567 | $ret .= '|' . $_; | ||||
568 | } | ||||
569 | $ret .= ')'; | ||||
570 | } | ||||
571 | else { | ||||
572 | my $sep = $self->{Type} == CHOICE ? '|' : ','; | ||||
573 | $ret = '(' . join($sep, map { $_->asString } @{$self->{Children}}) . ')'; | ||||
574 | } | ||||
575 | |||||
576 | $ret .= $self->{Quant} if $self->{Quant}; | ||||
577 | return $ret; | ||||
578 | } | ||||
579 | |||||
580 | sub thiseq { | ||||
581 | my $self = shift; | ||||
582 | |||||
583 | return $self->asString eq $_[0]; | ||||
584 | } | ||||
585 | |||||
586 | ################################################################ | ||||
587 | package #hide from PAUSE | ||||
588 | XML::Parser::ExpatNB; | ||||
589 | |||||
590 | 2 | 28µs | 2 | 42µs | # spent 25µs (8+17) within XML::Parser::ExpatNB::BEGIN@590 which was called:
# once (8µs+17µs) by XML::Parser::BEGIN@17 at line 590 # spent 25µs making 1 call to XML::Parser::ExpatNB::BEGIN@590
# spent 17µs making 1 call to vars::import |
591 | 2 | 289µs | 2 | 66µs | # spent 39µs (11+28) within XML::Parser::ExpatNB::BEGIN@591 which was called:
# once (11µs+28µs) by XML::Parser::BEGIN@17 at line 591 # spent 39µs making 1 call to XML::Parser::ExpatNB::BEGIN@591
# spent 28µs making 1 call to Exporter::import |
592 | |||||
593 | 1 | 5µs | @ISA = qw(XML::Parser::Expat); | ||
594 | |||||
595 | sub parse { | ||||
596 | my $self = shift; | ||||
597 | my $class = ref($self); | ||||
598 | croak "parse method not supported in $class"; | ||||
599 | } | ||||
600 | |||||
601 | sub parsestring { | ||||
602 | my $self = shift; | ||||
603 | my $class = ref($self); | ||||
604 | croak "parsestring method not supported in $class"; | ||||
605 | } | ||||
606 | |||||
607 | sub parsefile { | ||||
608 | my $self = shift; | ||||
609 | my $class = ref($self); | ||||
610 | croak "parsefile method not supported in $class"; | ||||
611 | } | ||||
612 | |||||
613 | sub parse_more { | ||||
614 | my ($self, $data) = @_; | ||||
615 | |||||
616 | $self->{_State_} = 1; | ||||
617 | my $ret = XML::Parser::Expat::ParsePartial($self->{Parser}, $data); | ||||
618 | |||||
619 | croak $self->{ErrorMessage} unless $ret; | ||||
620 | } | ||||
621 | |||||
622 | sub parse_done { | ||||
623 | my $self = shift; | ||||
624 | |||||
625 | my $ret = XML::Parser::Expat::ParseDone($self->{Parser}); | ||||
626 | unless ($ret) { | ||||
627 | my $msg = $self->{ErrorMessage}; | ||||
628 | $self->release; | ||||
629 | croak $msg; | ||||
630 | } | ||||
631 | |||||
632 | $self->{_State_} = 2; | ||||
633 | |||||
634 | my $result = $ret; | ||||
635 | my @result = (); | ||||
636 | my $final = $self->{FinalHandler}; | ||||
637 | if (defined $final) { | ||||
638 | if (wantarray) { | ||||
639 | @result = &$final($self); | ||||
640 | } | ||||
641 | else { | ||||
642 | $result = &$final($self); | ||||
643 | } | ||||
644 | } | ||||
645 | |||||
646 | $self->release; | ||||
647 | |||||
648 | return unless defined wantarray; | ||||
649 | return wantarray ? @result : $result; | ||||
650 | } | ||||
651 | |||||
652 | ################################################################ | ||||
653 | |||||
654 | package #hide from PAUSE | ||||
655 | XML::Parser::Encinfo; | ||||
656 | |||||
657 | sub DESTROY { | ||||
658 | my $self = shift; | ||||
659 | XML::Parser::Expat::FreeEncoding($self); | ||||
660 | } | ||||
661 | |||||
662 | 1 | 11µs | 1; | ||
663 | |||||
664 | __END__ | ||||
# spent 1.05ms within XML::Parser::Expat::CORE:ftdir which was called 10 times, avg 105µs/call:
# 10 times (1.05ms+0s) by XML::Parser::BEGIN@17 at line 19, avg 105µs/call | |||||
# spent 2µs within XML::Parser::Expat::GetBase which was called 2 times, avg 1µs/call:
# 2 times (2µs+0s) by XML::Parser::Expat::base at line 200, avg 1µs/call | |||||
# spent 15.7ms (4.78+10.9) within XML::Parser::Expat::ParseStream which was called 2 times, avg 7.84ms/call:
# 2 times (4.78ms+10.9ms) by XML::Parser::Expat::parse at line 470, avg 7.84ms/call | |||||
# spent 30µs within XML::Parser::Expat::ParserCreate which was called 2 times, avg 15µs/call:
# 2 times (30µs+0s) by XML::Parser::Expat::new at line 66, avg 15µs/call | |||||
# spent 11µs within XML::Parser::Expat::ParserFree which was called 2 times, avg 6µs/call:
# 2 times (11µs+0s) by XML::Parser::Expat::DESTROY at line 432, avg 6µs/call | |||||
# spent 2µs within XML::Parser::Expat::ParserRelease which was called 2 times, avg 750ns/call:
# 2 times (2µs+0s) by XML::Parser::Expat::release at line 427, avg 750ns/call | |||||
# spent 4µs within XML::Parser::Expat::SetAttListDeclHandler which was called 2 times, avg 2µs/call:
# 2 times (4µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 2µs/call | |||||
# spent 4µs within XML::Parser::Expat::SetBase which was called 2 times, avg 2µs/call:
# 2 times (4µs+0s) by XML::Parser::Expat::base at line 201, avg 2µs/call | |||||
# spent 3µs within XML::Parser::Expat::SetCharacterDataHandler which was called 2 times, avg 1µs/call:
# 2 times (3µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 1µs/call | |||||
# spent 4µs within XML::Parser::Expat::SetCommentHandler which was called 2 times, avg 2µs/call:
# 2 times (4µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 2µs/call | |||||
# spent 2µs within XML::Parser::Expat::SetDoctypeHandler which was called 2 times, avg 1µs/call:
# 2 times (2µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 1µs/call | |||||
# spent 3µs within XML::Parser::Expat::SetElementDeclHandler which was called 2 times, avg 2µs/call:
# 2 times (3µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 2µs/call | |||||
# spent 2µs within XML::Parser::Expat::SetEndCdataHandler which was called 2 times, avg 1µs/call:
# 2 times (2µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 1µs/call | |||||
# spent 3µs within XML::Parser::Expat::SetEndDoctypeHandler which was called 2 times, avg 1µs/call:
# 2 times (3µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 1µs/call | |||||
# spent 2µs within XML::Parser::Expat::SetEndElementHandler which was called 2 times, avg 1µs/call:
# 2 times (2µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 1µs/call | |||||
# spent 3µs within XML::Parser::Expat::SetEntityDeclHandler which was called 2 times, avg 2µs/call:
# 2 times (3µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 2µs/call | |||||
# spent 3µs within XML::Parser::Expat::SetExternalEntityRefHandler which was called 2 times, avg 2µs/call:
# 2 times (3µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 2µs/call | |||||
# spent 4µs within XML::Parser::Expat::SetNotationDeclHandler which was called 2 times, avg 2µs/call:
# 2 times (4µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 2µs/call | |||||
# spent 3µs within XML::Parser::Expat::SetProcessingInstructionHandler which was called 2 times, avg 2µs/call:
# 2 times (3µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 2µs/call | |||||
# spent 3µs within XML::Parser::Expat::SetStartCdataHandler which was called 2 times, avg 2µs/call:
# 2 times (3µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 2µs/call | |||||
# spent 2µs within XML::Parser::Expat::SetStartElementHandler which was called 2 times, avg 800ns/call:
# 2 times (2µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 800ns/call | |||||
# spent 3µs within XML::Parser::Expat::SetUnparsedEntityDeclHandler which was called 2 times, avg 2µs/call:
# 2 times (3µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 2µs/call | |||||
# spent 3µs within XML::Parser::Expat::SetXMLDeclHandler which was called 2 times, avg 1µs/call:
# 2 times (3µs+0s) by XML::Parser::Expat::setHandlers at line 125, avg 1µs/call | |||||
# spent 43µs within XML::Parser::Expat::bootstrap which was called:
# once (43µs+0s) by DynaLoader::bootstrap at line 210 of DynaLoader.pm |