| Filename | /usr/lib64/perl5/vendor_perl/5.16.0/XML/SAX.pm |
| Statements | Executed 125 statements in 9.53ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 3.78ms | 8.60ms | XML::SAX::BEGIN@18 |
| 1 | 1 | 1 | 835µs | 1.34ms | XML::SAX::_parse_ini_file |
| 30 | 3 | 1 | 274µs | 274µs | XML::SAX::CORE:subst (opcode) |
| 1 | 1 | 1 | 238µs | 2.33ms | XML::SAX::load_parsers |
| 19 | 2 | 1 | 150µs | 150µs | XML::SAX::CORE:match (opcode) |
| 1 | 1 | 1 | 89µs | 89µs | XML::SAX::CORE:open (opcode) |
| 11 | 1 | 1 | 84µs | 84µs | XML::SAX::CORE:readline (opcode) |
| 1 | 1 | 1 | 81µs | 178µs | XML::SAX::BEGIN@5 |
| 2 | 1 | 1 | 56µs | 2.39ms | XML::SAX::parsers |
| 1 | 1 | 1 | 55µs | 230µs | XML::SAX::BEGIN@15 |
| 1 | 1 | 1 | 55µs | 294µs | XML::SAX::BEGIN@20 |
| 1 | 1 | 1 | 52µs | 305µs | XML::SAX::BEGIN@17 |
| 1 | 1 | 1 | 50µs | 349µs | XML::SAX::BEGIN@6 |
| 1 | 1 | 1 | 48µs | 227µs | XML::SAX::BEGIN@22 |
| 1 | 1 | 1 | 44µs | 214µs | XML::SAX::BEGIN@23 |
| 1 | 1 | 1 | 31µs | 31µs | XML::SAX::BEGIN@10 |
| 1 | 1 | 1 | 23µs | 23µs | XML::SAX::BEGIN@16 |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::add_parser |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::do_warn |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::remove_parser |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::save_parsers |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # $Id$ | ||||
| 2 | |||||
| 3 | package XML::SAX; | ||||
| 4 | |||||
| 5 | 2 | 175µs | 2 | 275µs | # spent 178µs (81+97) within XML::SAX::BEGIN@5 which was called:
# once (81µs+97µs) by XML::Simple::build_tree at line 5 # spent 178µs making 1 call to XML::SAX::BEGIN@5
# spent 97µs making 1 call to strict::import |
| 6 | 2 | 623µs | 2 | 648µs | # spent 349µs (50+299) within XML::SAX::BEGIN@6 which was called:
# once (50µs+299µs) by XML::Simple::build_tree at line 6 # spent 349µs making 1 call to XML::SAX::BEGIN@6
# spent 299µs making 1 call to vars::import |
| 7 | |||||
| 8 | 1 | 6µs | $VERSION = '0.99'; | ||
| 9 | |||||
| 10 | 2 | 230µs | 1 | 31µs | # spent 31µs within XML::SAX::BEGIN@10 which was called:
# once (31µs+0s) by XML::Simple::build_tree at line 10 # spent 31µs making 1 call to XML::SAX::BEGIN@10 |
| 11 | 1 | 57µs | @ISA = ('Exporter'); | ||
| 12 | |||||
| 13 | 1 | 7µs | @EXPORT_OK = qw(Namespaces Validation); | ||
| 14 | |||||
| 15 | 2 | 150µs | 2 | 405µs | # spent 230µs (55+175) within XML::SAX::BEGIN@15 which was called:
# once (55µs+175µs) by XML::Simple::build_tree at line 15 # spent 230µs making 1 call to XML::SAX::BEGIN@15
# spent 175µs making 1 call to Exporter::import |
| 16 | 2 | 134µs | 1 | 23µs | # spent 23µs within XML::SAX::BEGIN@16 which was called:
# once (23µs+0s) by XML::Simple::build_tree at line 16 # spent 23µs making 1 call to XML::SAX::BEGIN@16 |
| 17 | 2 | 142µs | 2 | 558µs | # spent 305µs (52+253) within XML::SAX::BEGIN@17 which was called:
# once (52µs+253µs) by XML::Simple::build_tree at line 17 # spent 305µs making 1 call to XML::SAX::BEGIN@17
# spent 253µs making 1 call to Exporter::import |
| 18 | 2 | 696µs | 1 | 8.60ms | # spent 8.60ms (3.78+4.83) within XML::SAX::BEGIN@18 which was called:
# once (3.78ms+4.83ms) by XML::Simple::build_tree at line 18 # spent 8.60ms making 1 call to XML::SAX::BEGIN@18 |
| 19 | |||||
| 20 | 2 | 178µs | 2 | 533µs | # spent 294µs (55+239) within XML::SAX::BEGIN@20 which was called:
# once (55µs+239µs) by XML::Simple::build_tree at line 20 # spent 294µs making 1 call to XML::SAX::BEGIN@20
# spent 239µs making 1 call to constant::import |
| 21 | |||||
| 22 | 2 | 160µs | 2 | 405µs | # spent 227µs (48+179) within XML::SAX::BEGIN@22 which was called:
# once (48µs+179µs) by XML::Simple::build_tree at line 22 # spent 227µs making 1 call to XML::SAX::BEGIN@22
# spent 179µs making 1 call to constant::import |
| 23 | 2 | 5.23ms | 2 | 384µs | # spent 214µs (44+170) within XML::SAX::BEGIN@23 which was called:
# once (44µs+170µs) by XML::Simple::build_tree at line 23 # spent 214µs making 1 call to XML::SAX::BEGIN@23
# spent 170µs making 1 call to constant::import |
| 24 | |||||
| 25 | 1 | 2µs | my $known_parsers = undef; | ||
| 26 | |||||
| 27 | # load_parsers takes the ParserDetails.ini file out of the same directory | ||||
| 28 | # that XML::SAX is in, and looks at it. Format in POD below | ||||
| 29 | |||||
| 30 | =begin EXAMPLE | ||||
| 31 | |||||
| 32 | [XML::SAX::PurePerl] | ||||
| 33 | http://xml.org/sax/features/namespaces = 1 | ||||
| 34 | http://xml.org/sax/features/validation = 0 | ||||
| 35 | # a comment | ||||
| 36 | |||||
| 37 | # blank lines ignored | ||||
| 38 | |||||
| 39 | [XML::SAX::AnotherParser] | ||||
| 40 | http://xml.org/sax/features/namespaces = 0 | ||||
| 41 | http://xml.org/sax/features/validation = 1 | ||||
| 42 | |||||
| 43 | =end EXAMPLE | ||||
| 44 | |||||
| 45 | =cut | ||||
| 46 | |||||
| 47 | # spent 2.33ms (238µs+2.10) within XML::SAX::load_parsers which was called:
# once (238µs+2.10ms) by XML::SAX::parsers at line 114 | ||||
| 48 | 1 | 3µs | my $class = shift; | ||
| 49 | 1 | 1µs | my $dir = shift; | ||
| 50 | |||||
| 51 | # reset parsers | ||||
| 52 | 1 | 4µs | $known_parsers = []; | ||
| 53 | |||||
| 54 | # get directory from wherever XML::SAX is installed | ||||
| 55 | 1 | 5µs | if (!$dir) { | ||
| 56 | 1 | 5µs | $dir = $INC{'XML/SAX.pm'}; | ||
| 57 | 1 | 13µs | 1 | 312µs | $dir = dirname($dir); # spent 312µs making 1 call to File::Basename::dirname |
| 58 | } | ||||
| 59 | |||||
| 60 | 1 | 13µs | 1 | 48µs | my $fh = gensym(); # spent 48µs making 1 call to Symbol::gensym |
| 61 | 1 | 146µs | 2 | 394µs | if (!open($fh, File::Spec->catfile($dir, "SAX", PARSER_DETAILS))) { # spent 305µs making 1 call to File::Spec::Unix::catfile
# spent 89µs making 1 call to XML::SAX::CORE:open |
| 62 | XML::SAX->do_warn("could not find " . PARSER_DETAILS . " in $dir/SAX\n"); | ||||
| 63 | return $class; | ||||
| 64 | } | ||||
| 65 | |||||
| 66 | 1 | 22µs | 1 | 1.34ms | $known_parsers = $class->_parse_ini_file($fh); # spent 1.34ms making 1 call to XML::SAX::_parse_ini_file |
| 67 | |||||
| 68 | 1 | 85µs | return $class; | ||
| 69 | } | ||||
| 70 | |||||
| 71 | # spent 1.34ms (835µs+508µs) within XML::SAX::_parse_ini_file which was called:
# once (835µs+508µs) by XML::SAX::load_parsers at line 66 | ||||
| 72 | 1 | 4µs | my $class = shift; | ||
| 73 | 1 | 3µs | my ($fh) = @_; | ||
| 74 | |||||
| 75 | 1 | 1µs | my @config; | ||
| 76 | |||||
| 77 | 1 | 1µs | my $lineno = 0; | ||
| 78 | 1 | 239µs | 11 | 84µs | while (defined(my $line = <$fh>)) { # spent 84µs making 11 calls to XML::SAX::CORE:readline, avg 8µs/call |
| 79 | 10 | 7µs | $lineno++; | ||
| 80 | 10 | 17µs | my $original = $line; | ||
| 81 | # strip whitespace | ||||
| 82 | 10 | 312µs | 10 | 197µs | $line =~ s/\s*$//m; # spent 197µs making 10 calls to XML::SAX::CORE:subst, avg 20µs/call |
| 83 | 10 | 150µs | 10 | 51µs | $line =~ s/^\s*//m; # spent 51µs making 10 calls to XML::SAX::CORE:subst, avg 5µs/call |
| 84 | # strip comments | ||||
| 85 | 10 | 117µs | 10 | 26µs | $line =~ s/[#;].*$//m; # spent 26µs making 10 calls to XML::SAX::CORE:subst, avg 3µs/call |
| 86 | # ignore blanks | ||||
| 87 | 10 | 160µs | 10 | 42µs | next if $line =~ /^$/m; # spent 42µs making 10 calls to XML::SAX::CORE:match, avg 4µs/call |
| 88 | |||||
| 89 | # heading | ||||
| 90 | 6 | 207µs | 9 | 108µs | if ($line =~ /^\[\s*(.*)\s*\]$/m) { # spent 108µs making 9 calls to XML::SAX::CORE:match, avg 12µs/call |
| 91 | 3 | 43µs | push @config, { Name => $1 }; | ||
| 92 | 3 | 12µs | next; | ||
| 93 | } | ||||
| 94 | |||||
| 95 | # instruction | ||||
| 96 | elsif ($line =~ /^(.*?)\s*?=\s*(.*)$/) { | ||||
| 97 | 3 | 7µs | unless(@config) { | ||
| 98 | push @config, { Name => '' }; | ||||
| 99 | } | ||||
| 100 | 3 | 48µs | $config[-1]{Features}{$1} = $2; | ||
| 101 | } | ||||
| 102 | |||||
| 103 | # not whitespace, comment, or instruction | ||||
| 104 | else { | ||||
| 105 | die "Invalid line in ini: $lineno\n>>> $original\n"; | ||||
| 106 | } | ||||
| 107 | } | ||||
| 108 | |||||
| 109 | 1 | 25µs | return \@config; | ||
| 110 | } | ||||
| 111 | |||||
| 112 | # spent 2.39ms (56µs+2.33) within XML::SAX::parsers which was called 2 times, avg 1.19ms/call:
# 2 times (56µs+2.33ms) by XML::SAX::ParserFactory::new at line 18 of XML/SAX/ParserFactory.pm, avg 1.19ms/call | ||||
| 113 | 2 | 6µs | my $class = shift; | ||
| 114 | 2 | 15µs | 1 | 2.33ms | if (!$known_parsers) { # spent 2.33ms making 1 call to XML::SAX::load_parsers |
| 115 | $class->load_parsers(); | ||||
| 116 | } | ||||
| 117 | 2 | 37µs | return $known_parsers; | ||
| 118 | } | ||||
| 119 | |||||
| 120 | sub remove_parser { | ||||
| 121 | my $class = shift; | ||||
| 122 | my ($parser_module) = @_; | ||||
| 123 | |||||
| 124 | if (!$known_parsers) { | ||||
| 125 | $class->load_parsers(); | ||||
| 126 | } | ||||
| 127 | |||||
| 128 | @$known_parsers = grep { $_->{Name} ne $parser_module } @$known_parsers; | ||||
| 129 | |||||
| 130 | return $class; | ||||
| 131 | } | ||||
| 132 | |||||
| 133 | sub add_parser { | ||||
| 134 | my $class = shift; | ||||
| 135 | my ($parser_module) = @_; | ||||
| 136 | |||||
| 137 | if (!$known_parsers) { | ||||
| 138 | $class->load_parsers(); | ||||
| 139 | } | ||||
| 140 | |||||
| 141 | # first load module, then query features, then push onto known_parsers, | ||||
| 142 | |||||
| 143 | my $parser_file = $parser_module; | ||||
| 144 | $parser_file =~ s/::/\//g; | ||||
| 145 | $parser_file .= ".pm"; | ||||
| 146 | |||||
| 147 | require $parser_file; | ||||
| 148 | |||||
| 149 | my @features = $parser_module->supported_features(); | ||||
| 150 | |||||
| 151 | my $new = { Name => $parser_module }; | ||||
| 152 | foreach my $feature (@features) { | ||||
| 153 | $new->{Features}{$feature} = 1; | ||||
| 154 | } | ||||
| 155 | |||||
| 156 | # If exists in list already, move to end. | ||||
| 157 | my $done = 0; | ||||
| 158 | my $pos = undef; | ||||
| 159 | for (my $i = 0; $i < @$known_parsers; $i++) { | ||||
| 160 | my $p = $known_parsers->[$i]; | ||||
| 161 | if ($p->{Name} eq $parser_module) { | ||||
| 162 | $pos = $i; | ||||
| 163 | } | ||||
| 164 | } | ||||
| 165 | if (defined $pos) { | ||||
| 166 | splice(@$known_parsers, $pos, 1); | ||||
| 167 | push @$known_parsers, $new; | ||||
| 168 | $done++; | ||||
| 169 | } | ||||
| 170 | |||||
| 171 | # Otherwise (not in list), add at end of list. | ||||
| 172 | if (!$done) { | ||||
| 173 | push @$known_parsers, $new; | ||||
| 174 | } | ||||
| 175 | |||||
| 176 | return $class; | ||||
| 177 | } | ||||
| 178 | |||||
| 179 | sub save_parsers { | ||||
| 180 | my $class = shift; | ||||
| 181 | |||||
| 182 | # get directory from wherever XML::SAX is installed | ||||
| 183 | my $dir = $INC{'XML/SAX.pm'}; | ||||
| 184 | $dir = dirname($dir); | ||||
| 185 | |||||
| 186 | my $file = File::Spec->catfile($dir, "SAX", PARSER_DETAILS); | ||||
| 187 | chmod 0644, $file; | ||||
| 188 | unlink($file); | ||||
| 189 | |||||
| 190 | my $fh = gensym(); | ||||
| 191 | open($fh, ">$file") || | ||||
| 192 | die "Cannot write to $file: $!"; | ||||
| 193 | |||||
| 194 | foreach my $p (@$known_parsers) { | ||||
| 195 | print $fh "[$p->{Name}]\n"; | ||||
| 196 | foreach my $key (keys %{$p->{Features}}) { | ||||
| 197 | print $fh "$key = $p->{Features}{$key}\n"; | ||||
| 198 | } | ||||
| 199 | print $fh "\n"; | ||||
| 200 | } | ||||
| 201 | |||||
| 202 | print $fh "\n"; | ||||
| 203 | |||||
| 204 | close $fh; | ||||
| 205 | |||||
| 206 | return $class; | ||||
| 207 | } | ||||
| 208 | |||||
| 209 | sub do_warn { | ||||
| 210 | my $class = shift; | ||||
| 211 | # Don't output warnings if running under Test::Harness | ||||
| 212 | warn(@_) unless $ENV{HARNESS_ACTIVE}; | ||||
| 213 | } | ||||
| 214 | |||||
| 215 | 1 | 23µs | 1; | ||
| 216 | __END__ | ||||
sub XML::SAX::CORE:match; # opcode | |||||
# spent 89µs within XML::SAX::CORE:open which was called:
# once (89µs+0s) by XML::SAX::load_parsers at line 61 | |||||
# spent 84µs within XML::SAX::CORE:readline which was called 11 times, avg 8µs/call:
# 11 times (84µs+0s) by XML::SAX::_parse_ini_file at line 78, avg 8µs/call | |||||
# spent 274µs within XML::SAX::CORE:subst which was called 30 times, avg 9µs/call:
# 10 times (197µs+0s) by XML::SAX::_parse_ini_file at line 82, avg 20µs/call
# 10 times (51µs+0s) by XML::SAX::_parse_ini_file at line 83, avg 5µs/call
# 10 times (26µs+0s) by XML::SAX::_parse_ini_file at line 85, avg 3µs/call |