Filename | /usr/share/perl5/XML/SAX.pm |
Statements | Executed 144 statements in 1.91ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 774µs | 951µs | BEGIN@18 | XML::SAX::
1 | 1 | 1 | 200µs | 327µs | _parse_ini_file | XML::SAX::
1 | 1 | 1 | 85µs | 723µs | load_parsers | XML::SAX::
36 | 3 | 1 | 63µs | 63µs | CORE:subst (opcode) | XML::SAX::
1 | 1 | 1 | 52µs | 52µs | CORE:open (opcode) | XML::SAX::
21 | 2 | 1 | 40µs | 40µs | CORE:match (opcode) | XML::SAX::
13 | 1 | 1 | 24µs | 24µs | CORE:readline (opcode) | XML::SAX::
1 | 1 | 1 | 21µs | 24µs | BEGIN@5 | XML::SAX::
1 | 1 | 1 | 18µs | 741µs | parsers | XML::SAX::
1 | 1 | 1 | 15µs | 77µs | BEGIN@15 | XML::SAX::
1 | 1 | 1 | 15µs | 66µs | BEGIN@17 | XML::SAX::
1 | 1 | 1 | 13µs | 65µs | BEGIN@20 | XML::SAX::
1 | 1 | 1 | 13µs | 67µs | BEGIN@6 | XML::SAX::
1 | 1 | 1 | 9µs | 9µs | BEGIN@10 | XML::SAX::
1 | 1 | 1 | 8µs | 42µs | BEGIN@23 | XML::SAX::
1 | 1 | 1 | 8µs | 38µs | BEGIN@22 | XML::SAX::
1 | 1 | 1 | 6µs | 6µs | BEGIN@16 | XML::SAX::
0 | 0 | 0 | 0s | 0s | _is_vendor_supplied | XML::SAX::
0 | 0 | 0 | 0s | 0s | add_parser | XML::SAX::
0 | 0 | 0 | 0s | 0s | do_warn | XML::SAX::
0 | 0 | 0 | 0s | 0s | remove_parser | XML::SAX::
0 | 0 | 0 | 0s | 0s | save_parsers | XML::SAX::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # $Id: SAX.pm,v 1.31 2008-08-05 12:36:24 grant Exp $ | ||||
2 | |||||
3 | package XML::SAX; | ||||
4 | |||||
5 | 3 | 38µs | 2 | 28µs | # spent 24µs (21+4) within XML::SAX::BEGIN@5 which was called:
# once (21µs+4µs) by MARC::File::SAX::BEGIN@10 at line 5 # spent 24µs making 1 call to XML::SAX::BEGIN@5
# spent 4µs making 1 call to strict::import |
6 | 3 | 36µs | 2 | 121µs | # spent 67µs (13+54) within XML::SAX::BEGIN@6 which was called:
# once (13µs+54µs) by MARC::File::SAX::BEGIN@10 at line 6 # spent 67µs making 1 call to XML::SAX::BEGIN@6
# spent 54µs making 1 call to vars::import |
7 | |||||
8 | 1 | 1µs | $VERSION = '0.96'; | ||
9 | |||||
10 | 3 | 55µs | 1 | 9µs | # spent 9µs within XML::SAX::BEGIN@10 which was called:
# once (9µs+0s) by MARC::File::SAX::BEGIN@10 at line 10 # spent 9µs making 1 call to XML::SAX::BEGIN@10 |
11 | 1 | 15µs | @ISA = ('Exporter'); | ||
12 | |||||
13 | 1 | 800ns | @EXPORT_OK = qw(Namespaces Validation); | ||
14 | |||||
15 | 3 | 35µs | 2 | 139µs | # spent 77µs (15+62) within XML::SAX::BEGIN@15 which was called:
# once (15µs+62µs) by MARC::File::SAX::BEGIN@10 at line 15 # spent 77µs making 1 call to XML::SAX::BEGIN@15
# spent 62µs making 1 call to Exporter::import |
16 | 3 | 26µs | 1 | 6µs | # spent 6µs within XML::SAX::BEGIN@16 which was called:
# once (6µs+0s) by MARC::File::SAX::BEGIN@10 at line 16 # spent 6µs making 1 call to XML::SAX::BEGIN@16 |
17 | 3 | 38µs | 2 | 118µs | # spent 66µs (15+51) within XML::SAX::BEGIN@17 which was called:
# once (15µs+51µs) by MARC::File::SAX::BEGIN@10 at line 17 # spent 66µs making 1 call to XML::SAX::BEGIN@17
# spent 51µs making 1 call to Exporter::import |
18 | 3 | 128µs | 1 | 951µs | # spent 951µs (774+177) within XML::SAX::BEGIN@18 which was called:
# once (774µs+177µs) by MARC::File::SAX::BEGIN@10 at line 18 # spent 951µs making 1 call to XML::SAX::BEGIN@18 |
19 | |||||
20 | 3 | 34µs | 2 | 117µs | # spent 65µs (13+52) within XML::SAX::BEGIN@20 which was called:
# once (13µs+52µs) by MARC::File::SAX::BEGIN@10 at line 20 # spent 65µs making 1 call to XML::SAX::BEGIN@20
# spent 52µs making 1 call to constant::import |
21 | |||||
22 | 3 | 30µs | 2 | 68µs | # spent 38µs (8+30) within XML::SAX::BEGIN@22 which was called:
# once (8µs+30µs) by MARC::File::SAX::BEGIN@10 at line 22 # spent 38µs making 1 call to XML::SAX::BEGIN@22
# spent 30µs making 1 call to constant::import |
23 | 3 | 991µs | 2 | 76µs | # spent 42µs (8+34) within XML::SAX::BEGIN@23 which was called:
# once (8µs+34µs) by MARC::File::SAX::BEGIN@10 at line 23 # spent 42µs making 1 call to XML::SAX::BEGIN@23
# spent 34µs making 1 call to constant::import |
24 | |||||
25 | 1 | 600ns | 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 723µs (85+638) within XML::SAX::load_parsers which was called:
# once (85µs+638µs) by XML::SAX::parsers at line 114 | ||||
48 | 1 | 1µs | my $class = shift; | ||
49 | 1 | 800ns | my $dir = shift; | ||
50 | |||||
51 | # reset parsers | ||||
52 | 1 | 1µs | $known_parsers = []; | ||
53 | |||||
54 | # get directory from wherever XML::SAX is installed | ||||
55 | 1 | 2µs | if (!$dir) { | ||
56 | 1 | 2µs | $dir = $INC{'XML/SAX.pm'}; | ||
57 | 1 | 6µs | 1 | 149µs | $dir = dirname($dir); # spent 149µs making 1 call to File::Basename::dirname |
58 | } | ||||
59 | |||||
60 | 1 | 6µs | 1 | 21µs | my $fh = gensym(); # spent 21µs making 1 call to Symbol::gensym |
61 | 1 | 73µs | 2 | 141µs | if (!open($fh, File::Spec->catfile($dir, "SAX", PARSER_DETAILS))) { # spent 89µs making 1 call to File::Spec::Unix::catfile
# spent 52µ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 | 6µs | 1 | 327µs | $known_parsers = $class->_parse_ini_file($fh); # spent 327µs making 1 call to XML::SAX::_parse_ini_file |
67 | |||||
68 | 1 | 35µs | return $class; | ||
69 | } | ||||
70 | |||||
71 | # spent 327µs (200+127) within XML::SAX::_parse_ini_file which was called:
# once (200µs+127µs) by XML::SAX::load_parsers at line 66 | ||||
72 | 1 | 2µs | my $class = shift; | ||
73 | 1 | 800ns | my ($fh) = @_; | ||
74 | |||||
75 | 1 | 300ns | my @config; | ||
76 | |||||
77 | 1 | 700ns | my $lineno = 0; | ||
78 | 1 | 60µs | 13 | 24µs | while (defined(my $line = <$fh>)) { # spent 24µs making 13 calls to XML::SAX::CORE:readline, avg 2µs/call |
79 | 12 | 3µs | $lineno++; | ||
80 | 12 | 6µs | my $original = $line; | ||
81 | # strip whitespace | ||||
82 | 12 | 74µs | 12 | 46µs | $line =~ s/\s*$//m; # spent 46µs making 12 calls to XML::SAX::CORE:subst, avg 4µs/call |
83 | 12 | 31µs | 12 | 10µs | $line =~ s/^\s*//m; # spent 10µs making 12 calls to XML::SAX::CORE:subst, avg 792ns/call |
84 | # strip comments | ||||
85 | 12 | 27µs | 12 | 7µs | $line =~ s/[#;].*$//m; # spent 7µs making 12 calls to XML::SAX::CORE:subst, avg 625ns/call |
86 | # ignore blanks | ||||
87 | 12 | 37µs | 12 | 10µs | next if $line =~ /^$/m; # spent 10µs making 12 calls to XML::SAX::CORE:match, avg 858ns/call |
88 | |||||
89 | # heading | ||||
90 | 6 | 50µs | 9 | 29µs | if ($line =~ /^\[\s*(.*)\s*\]$/m) { # spent 29µs making 9 calls to XML::SAX::CORE:match, avg 3µs/call |
91 | 3 | 10µs | push @config, { Name => $1 }; | ||
92 | 3 | 4µs | next; | ||
93 | } | ||||
94 | |||||
95 | # instruction | ||||
96 | elsif ($line =~ /^(.*?)\s*?=\s*(.*)$/) { | ||||
97 | 3 | 2µs | unless(@config) { | ||
98 | push @config, { Name => '' }; | ||||
99 | } | ||||
100 | 3 | 16µ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 | 9µs | return \@config; | ||
110 | } | ||||
111 | |||||
112 | # spent 741µs (18+723) within XML::SAX::parsers which was called:
# once (18µs+723µs) by XML::SAX::ParserFactory::new at line 18 of XML/SAX/ParserFactory.pm | ||||
113 | 1 | 1µs | my $class = shift; | ||
114 | 1 | 4µs | 1 | 723µs | if (!$known_parsers) { # spent 723µs making 1 call to XML::SAX::load_parsers |
115 | $class->load_parsers(); | ||||
116 | } | ||||
117 | 1 | 7µ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 | ### 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 do_warn { | ||||
219 | my $class = shift; | ||||
220 | # Don't output warnings if running under Test::Harness | ||||
221 | warn(@_) unless $ENV{HARNESS_ACTIVE}; | ||||
222 | } | ||||
223 | |||||
224 | sub _is_vendor_supplied { | ||||
225 | 1; | ||||
226 | } | ||||
227 | |||||
228 | 1 | 6µs | 1; | ||
229 | __END__ | ||||
sub XML::SAX::CORE:match; # opcode | |||||
# spent 52µs within XML::SAX::CORE:open which was called:
# once (52µs+0s) by XML::SAX::load_parsers at line 61 | |||||
# spent 24µs within XML::SAX::CORE:readline which was called 13 times, avg 2µs/call:
# 13 times (24µs+0s) by XML::SAX::_parse_ini_file at line 78, avg 2µs/call | |||||
# spent 63µs within XML::SAX::CORE:subst which was called 36 times, avg 2µs/call:
# 12 times (46µs+0s) by XML::SAX::_parse_ini_file at line 82, avg 4µs/call
# 12 times (10µs+0s) by XML::SAX::_parse_ini_file at line 83, avg 792ns/call
# 12 times (7µs+0s) by XML::SAX::_parse_ini_file at line 85, avg 625ns/call |