| Filename | /usr/share/perl5/XML/SAX.pm |
| Statements | Executed 186 statements in 3.61ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 2.79ms | 3.08ms | XML::SAX::BEGIN@16 |
| 1 | 1 | 1 | 1.88ms | 3.79ms | XML::SAX::BEGIN@15 |
| 1 | 1 | 1 | 1.15ms | 4.16ms | XML::SAX::BEGIN@18 |
| 1 | 1 | 1 | 899µs | 1.06ms | XML::SAX::BEGIN@17 |
| 1 | 1 | 1 | 506µs | 805µs | XML::SAX::_parse_ini_file |
| 51 | 3 | 1 | 154µs | 154µs | XML::SAX::CORE:subst (opcode) |
| 33 | 2 | 1 | 94µs | 94µs | XML::SAX::CORE:match (opcode) |
| 1 | 1 | 1 | 64µs | 1.22ms | XML::SAX::load_parsers |
| 1 | 1 | 1 | 61µs | 61µs | XML::SAX::CORE:open (opcode) |
| 18 | 1 | 1 | 51µs | 51µs | XML::SAX::CORE:readline (opcode) |
| 1 | 1 | 1 | 22µs | 118µs | XML::SAX::BEGIN@20 |
| 1 | 1 | 1 | 21µs | 27µs | XML::SAX::BEGIN@5 |
| 1 | 1 | 1 | 15µs | 112µs | XML::SAX::BEGIN@22 |
| 1 | 1 | 1 | 15µs | 85µs | XML::SAX::BEGIN@23 |
| 1 | 1 | 1 | 15µs | 1.24ms | XML::SAX::parsers |
| 1 | 1 | 1 | 14µs | 104µs | XML::SAX::BEGIN@6 |
| 1 | 1 | 1 | 8µs | 8µs | XML::SAX::BEGIN@10 |
| 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 |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::save_parsers_debian |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # $Id: SAX.pm,v 1.29 2007/06/27 09:09:12 grant Exp $ | ||||
| 2 | |||||
| 3 | package XML::SAX; | ||||
| 4 | |||||
| 5 | 3 | 41µs | 2 | 33µs | # spent 27µs (21+6) within XML::SAX::BEGIN@5 which was called:
# once (21µs+6µs) by MARC::File::SAX::BEGIN@10 at line 5 # spent 27µs making 1 call to XML::SAX::BEGIN@5
# spent 6µs making 1 call to strict::import |
| 6 | 3 | 49µs | 2 | 194µs | # spent 104µs (14+90) within XML::SAX::BEGIN@6 which was called:
# once (14µs+90µs) by MARC::File::SAX::BEGIN@10 at line 6 # spent 104µs making 1 call to XML::SAX::BEGIN@6
# spent 90µs making 1 call to vars::import |
| 7 | |||||
| 8 | 1 | 2µs | $VERSION = '0.16'; | ||
| 9 | |||||
| 10 | 3 | 64µs | 1 | 8µs | # spent 8µs within XML::SAX::BEGIN@10 which was called:
# once (8µs+0s) by MARC::File::SAX::BEGIN@10 at line 10 # spent 8µs making 1 call to XML::SAX::BEGIN@10 |
| 11 | 1 | 13µs | @ISA = ('Exporter'); | ||
| 12 | |||||
| 13 | 1 | 2µs | @EXPORT_OK = qw(Namespaces Validation); | ||
| 14 | |||||
| 15 | 3 | 234µs | 2 | 3.89ms | # spent 3.79ms (1.88+1.91) within XML::SAX::BEGIN@15 which was called:
# once (1.88ms+1.91ms) by MARC::File::SAX::BEGIN@10 at line 15 # spent 3.79ms making 1 call to XML::SAX::BEGIN@15
# spent 100µs making 1 call to Exporter::import |
| 16 | 3 | 155µs | 1 | 3.08ms | # spent 3.08ms (2.79+281µs) within XML::SAX::BEGIN@16 which was called:
# once (2.79ms+281µs) by MARC::File::SAX::BEGIN@10 at line 16 # spent 3.08ms making 1 call to XML::SAX::BEGIN@16 |
| 17 | 3 | 254µs | 2 | 1.18ms | # spent 1.06ms (899µs+159µs) within XML::SAX::BEGIN@17 which was called:
# once (899µs+159µs) by MARC::File::SAX::BEGIN@10 at line 17 # spent 1.06ms making 1 call to XML::SAX::BEGIN@17
# spent 120µs making 1 call to Exporter::import |
| 18 | 3 | 192µs | 1 | 4.16ms | # spent 4.16ms (1.15+3.00) within XML::SAX::BEGIN@18 which was called:
# once (1.15ms+3.00ms) by MARC::File::SAX::BEGIN@10 at line 18 # spent 4.16ms making 1 call to XML::SAX::BEGIN@18 |
| 19 | |||||
| 20 | 3 | 54µs | 2 | 214µs | # spent 118µs (22+96) within XML::SAX::BEGIN@20 which was called:
# once (22µs+96µs) by MARC::File::SAX::BEGIN@10 at line 20 # spent 118µs making 1 call to XML::SAX::BEGIN@20
# spent 96µs making 1 call to constant::import |
| 21 | |||||
| 22 | 3 | 45µs | 2 | 209µs | # spent 112µs (15+97) within XML::SAX::BEGIN@22 which was called:
# once (15µs+97µs) by MARC::File::SAX::BEGIN@10 at line 22 # spent 112µs making 1 call to XML::SAX::BEGIN@22
# spent 97µs making 1 call to constant::import |
| 23 | 3 | 1.55ms | 2 | 155µs | # spent 85µs (15+70) within XML::SAX::BEGIN@23 which was called:
# once (15µs+70µs) by MARC::File::SAX::BEGIN@10 at line 23 # spent 85µs making 1 call to XML::SAX::BEGIN@23
# spent 70µs making 1 call to constant::import |
| 24 | |||||
| 25 | 1 | 1µ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 | |||||
| - - | |||||
| 47 | # spent 1.22ms (64µs+1.16) within XML::SAX::load_parsers which was called:
# once (64µs+1.16ms) by XML::SAX::parsers at line 114 | ||||
| 48 | 8 | 114µs | my $class = shift; | ||
| 49 | my $dir = shift; | ||||
| 50 | |||||
| 51 | # reset parsers | ||||
| 52 | $known_parsers = []; | ||||
| 53 | |||||
| 54 | # get directory from wherever XML::SAX is installed | ||||
| 55 | 2 | 8µs | if (!$dir) { | ||
| 56 | $dir = $INC{'XML/SAX.pm'}; | ||||
| 57 | 1 | 137µs | $dir = dirname($dir); # spent 137µs making 1 call to File::Basename::dirname | ||
| 58 | } | ||||
| 59 | |||||
| 60 | 1 | 15µs | my $fh = gensym(); # spent 15µs making 1 call to Symbol::gensym | ||
| 61 | 2 | 203µs | if (!open($fh, File::Spec->catfile($dir, "SAX", PARSER_DETAILS))) { # spent 142µs making 1 call to File::Spec::Unix::catfile
# spent 61µ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 | 805µs | $known_parsers = $class->_parse_ini_file($fh); # spent 805µs making 1 call to XML::SAX::_parse_ini_file | ||
| 67 | |||||
| 68 | return $class; | ||||
| 69 | } | ||||
| 70 | |||||
| 71 | # spent 805µs (506+299) within XML::SAX::_parse_ini_file which was called:
# once (506µs+299µs) by XML::SAX::load_parsers at line 66 | ||||
| 72 | 6 | 147µs | my $class = shift; | ||
| 73 | my ($fh) = @_; | ||||
| 74 | |||||
| 75 | my @config; | ||||
| 76 | |||||
| 77 | my $lineno = 0; | ||||
| 78 | 112 | 599µs | 18 | 51µs | while (defined(my $line = <$fh>)) { # spent 51µs making 18 calls to XML::SAX::CORE:readline, avg 3µs/call |
| 79 | $lineno++; | ||||
| 80 | my $original = $line; | ||||
| 81 | # strip whitespace | ||||
| 82 | 17 | 105µs | $line =~ s/\s*$//m; # spent 105µs making 17 calls to XML::SAX::CORE:subst, avg 6µs/call | ||
| 83 | 17 | 28µs | $line =~ s/^\s*//m; # spent 28µs making 17 calls to XML::SAX::CORE:subst, avg 2µs/call | ||
| 84 | # strip comments | ||||
| 85 | 17 | 21µs | $line =~ s/[#;].*$//m; # spent 21µs making 17 calls to XML::SAX::CORE:subst, avg 1µs/call | ||
| 86 | # ignore blanks | ||||
| 87 | 17 | 23µs | next if $line =~ /^$/m; # spent 23µs making 17 calls to XML::SAX::CORE:match, avg 1µs/call | ||
| 88 | |||||
| 89 | # heading | ||||
| 90 | 20 | 61µs | 16 | 71µs | if ($line =~ /^\[\s*(.*)\s*\]$/m) { # spent 71µs making 16 calls to XML::SAX::CORE:match, avg 4µs/call |
| 91 | push @config, { Name => $1 }; | ||||
| 92 | next; | ||||
| 93 | } | ||||
| 94 | |||||
| 95 | # instruction | ||||
| 96 | elsif ($line =~ /^(.*?)\s*?=\s*(.*)$/) { | ||||
| 97 | unless(@config) { | ||||
| 98 | push @config, { Name => '' }; | ||||
| 99 | } | ||||
| 100 | $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 | return \@config; | ||||
| 110 | } | ||||
| 111 | |||||
| 112 | # spent 1.24ms (15µs+1.22) within XML::SAX::parsers which was called:
# once (15µs+1.22ms) by XML::SAX::ParserFactory::new at line 18 of XML/SAX/ParserFactory.pm | ||||
| 113 | 3 | 16µs | my $class = shift; | ||
| 114 | 1 | 1.22ms | if (!$known_parsers) { # spent 1.22ms making 1 call to XML::SAX::load_parsers | ||
| 115 | $class->load_parsers(); | ||||
| 116 | } | ||||
| 117 | 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 | ### DEBIAN MODIFICATION | ||||
| 183 | print "\n"; | ||||
| 184 | print "Please use 'update-perl-sax-parsers(8) to register this parser.'\n"; | ||||
| 185 | print "See /usr/share/doc/libxml-sax-perl/README.Debian.gz for more info.\n"; | ||||
| 186 | print "\n"; | ||||
| 187 | |||||
| 188 | return $class; # rest of the function is disabled on Debian. | ||||
| 189 | ### END DEBIAN MODIFICATION | ||||
| 190 | |||||
| 191 | # get directory from wherever XML::SAX is installed | ||||
| 192 | my $dir = $INC{'XML/SAX.pm'}; | ||||
| 193 | $dir = dirname($dir); | ||||
| 194 | |||||
| 195 | my $file = File::Spec->catfile($dir, "SAX", PARSER_DETAILS); | ||||
| 196 | chmod 0644, $file; | ||||
| 197 | unlink($file); | ||||
| 198 | |||||
| 199 | my $fh = gensym(); | ||||
| 200 | open($fh, ">$file") || | ||||
| 201 | die "Cannot write to $file: $!"; | ||||
| 202 | |||||
| 203 | foreach my $p (@$known_parsers) { | ||||
| 204 | print $fh "[$p->{Name}]\n"; | ||||
| 205 | foreach my $key (keys %{$p->{Features}}) { | ||||
| 206 | print $fh "$key = $p->{Features}{$key}\n"; | ||||
| 207 | } | ||||
| 208 | print $fh "\n"; | ||||
| 209 | } | ||||
| 210 | |||||
| 211 | print $fh "\n"; | ||||
| 212 | |||||
| 213 | close $fh; | ||||
| 214 | |||||
| 215 | return $class; | ||||
| 216 | } | ||||
| 217 | |||||
| 218 | sub save_parsers_debian { | ||||
| 219 | my $class = shift; | ||||
| 220 | my ($parser_module,$directory, $priority) = @_; | ||||
| 221 | |||||
| 222 | # add parser | ||||
| 223 | $known_parsers = []; | ||||
| 224 | $class->add_parser($parser_module); | ||||
| 225 | |||||
| 226 | # get parser's ParserDetails file | ||||
| 227 | my $file = $parser_module; | ||||
| 228 | $file = "${priority}-$file" if $priority != 0; | ||||
| 229 | $file = File::Spec->catfile($directory, $file); | ||||
| 230 | chmod 0644, $file; | ||||
| 231 | unlink($file); | ||||
| 232 | |||||
| 233 | my $fh = gensym(); | ||||
| 234 | open($fh, ">$file") || | ||||
| 235 | die "Cannot write to $file: $!"; | ||||
| 236 | |||||
| 237 | foreach my $p (@$known_parsers) { | ||||
| 238 | print $fh "[$p->{Name}]\n"; | ||||
| 239 | foreach my $key (keys %{$p->{Features}}) { | ||||
| 240 | print $fh "$key = $p->{Features}{$key}\n"; | ||||
| 241 | } | ||||
| 242 | print $fh "\n"; | ||||
| 243 | } | ||||
| 244 | |||||
| 245 | print $fh "\n"; | ||||
| 246 | |||||
| 247 | close $fh; | ||||
| 248 | |||||
| 249 | return $class; | ||||
| 250 | } | ||||
| 251 | |||||
| 252 | sub do_warn { | ||||
| 253 | my $class = shift; | ||||
| 254 | # Don't output warnings if running under Test::Harness | ||||
| 255 | warn(@_) unless $ENV{HARNESS_ACTIVE}; | ||||
| 256 | } | ||||
| 257 | |||||
| 258 | 1 | 8µs | 1; | ||
| 259 | __END__ | ||||
sub XML::SAX::CORE:match; # opcode | |||||
# spent 61µs within XML::SAX::CORE:open which was called:
# once (61µs+0s) by XML::SAX::load_parsers at line 61 | |||||
# spent 51µs within XML::SAX::CORE:readline which was called 18 times, avg 3µs/call:
# 18 times (51µs+0s) by XML::SAX::_parse_ini_file at line 78, avg 3µs/call | |||||
# spent 154µs within XML::SAX::CORE:subst which was called 51 times, avg 3µs/call:
# 17 times (105µs+0s) by XML::SAX::_parse_ini_file at line 82, avg 6µs/call
# 17 times (28µs+0s) by XML::SAX::_parse_ini_file at line 83, avg 2µs/call
# 17 times (21µs+0s) by XML::SAX::_parse_ini_file at line 85, avg 1µs/call |