Filename | /usr/share/perl5/XML/SAX/ParserFactory.pm |
Statements | Executed 90 statements in 3.90ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
2 | 1 | 1 | 2.57ms | 34.0ms | parser | XML::SAX::ParserFactory::
20 | 1 | 1 | 2.52ms | 2.52ms | CORE:open (opcode) | XML::SAX::ParserFactory::
1 | 1 | 1 | 1.06ms | 1.18ms | BEGIN@12 | XML::SAX::ParserFactory::
2 | 1 | 1 | 113µs | 2.70ms | _parser_class | XML::SAX::ParserFactory::
2 | 1 | 1 | 17µs | 4.44ms | new | XML::SAX::ParserFactory::
1 | 1 | 1 | 11µs | 22µs | BEGIN@5 | XML::SAX::ParserFactory::
1 | 1 | 1 | 9µs | 24µs | BEGIN@6 | XML::SAX::ParserFactory::
1 | 1 | 1 | 7µs | 25µs | BEGIN@10 | XML::SAX::ParserFactory::
1 | 1 | 1 | 6µs | 6µs | BEGIN@11 | XML::SAX::ParserFactory::
2 | 1 | 1 | 2µs | 2µs | CORE:subst (opcode) | XML::SAX::ParserFactory::
0 | 0 | 0 | 0s | 0s | require_feature | XML::SAX::ParserFactory::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # $Id$ | ||||
2 | |||||
3 | package XML::SAX::ParserFactory; | ||||
4 | |||||
5 | 2 | 24µs | 2 | 34µs | # spent 22µs (11+11) within XML::SAX::ParserFactory::BEGIN@5 which was called:
# once (11µs+11µs) by XML::SAX::BEGIN@18 at line 5 # spent 22µs making 1 call to XML::SAX::ParserFactory::BEGIN@5
# spent 11µs making 1 call to strict::import |
6 | 2 | 32µs | 2 | 40µs | # spent 24µs (9+16) within XML::SAX::ParserFactory::BEGIN@6 which was called:
# once (9µs+16µs) by XML::SAX::BEGIN@18 at line 6 # spent 24µs making 1 call to XML::SAX::ParserFactory::BEGIN@6
# spent 16µs making 1 call to vars::import |
7 | |||||
8 | 1 | 300ns | $VERSION = '1.01'; | ||
9 | |||||
10 | 2 | 20µs | 2 | 44µs | # spent 25µs (7+19) within XML::SAX::ParserFactory::BEGIN@10 which was called:
# once (7µs+19µs) by XML::SAX::BEGIN@18 at line 10 # spent 25µs making 1 call to XML::SAX::ParserFactory::BEGIN@10
# spent 19µs making 1 call to Exporter::import |
11 | 2 | 20µs | 1 | 6µs | # spent 6µs within XML::SAX::ParserFactory::BEGIN@11 which was called:
# once (6µs+0s) by XML::SAX::BEGIN@18 at line 11 # spent 6µs making 1 call to XML::SAX::ParserFactory::BEGIN@11 |
12 | 2 | 1.06ms | 1 | 1.18ms | # spent 1.18ms (1.06+117µs) within XML::SAX::ParserFactory::BEGIN@12 which was called:
# once (1.06ms+117µs) by XML::SAX::BEGIN@18 at line 12 # spent 1.18ms making 1 call to XML::SAX::ParserFactory::BEGIN@12 |
13 | |||||
14 | # spent 4.44ms (17µs+4.42) within XML::SAX::ParserFactory::new which was called 2 times, avg 2.22ms/call:
# 2 times (17µs+4.42ms) by XML::SAX::ParserFactory::parser at line 25, avg 2.22ms/call | ||||
15 | 2 | 500ns | my $class = shift; | ||
16 | 2 | 1µs | my %params = @_; # TODO : Fix this in spec. | ||
17 | 2 | 2µs | my $self = bless \%params, $class; | ||
18 | 2 | 8µs | 2 | 4.42ms | $self->{KnownParsers} = XML::SAX->parsers(); # spent 4.42ms making 2 calls to XML::SAX::parsers, avg 2.21ms/call |
19 | 2 | 4µs | return $self; | ||
20 | } | ||||
21 | |||||
22 | # spent 34.0ms (2.57+31.5) within XML::SAX::ParserFactory::parser which was called 2 times, avg 17.0ms/call:
# 2 times (2.57ms+31.5ms) by XML::Simple::build_tree at line 379 of XML/Simple.pm, avg 17.0ms/call | ||||
23 | 2 | 600ns | my $self = shift; | ||
24 | 2 | 2µs | my @parser_params = @_; | ||
25 | 2 | 3µs | 2 | 4.44ms | if (!ref($self)) { # spent 4.44ms making 2 calls to XML::SAX::ParserFactory::new, avg 2.22ms/call |
26 | $self = $self->new(); | ||||
27 | } | ||||
28 | |||||
29 | 2 | 4µs | 2 | 2.70ms | my $parser_class = $self->_parser_class(); # spent 2.70ms making 2 calls to XML::SAX::ParserFactory::_parser_class, avg 1.35ms/call |
30 | |||||
31 | 2 | 700ns | my $version = ''; | ||
32 | 2 | 7µs | 2 | 2µs | if ($parser_class =~ s/\s*\(([\d\.]+)\)\s*$//) { # spent 2µs making 2 calls to XML::SAX::ParserFactory::CORE:subst, avg 1µs/call |
33 | $version = " $1"; | ||||
34 | } | ||||
35 | |||||
36 | 2 | 17µs | 2 | 7µs | if (!$parser_class->can('new')) { # spent 7µs making 2 calls to UNIVERSAL::can, avg 3µs/call |
37 | 1 | 36µs | eval "require $parser_class $version;"; # spent 1.02ms executing statements in string eval | ||
38 | 1 | 400ns | die $@ if $@; | ||
39 | } | ||||
40 | |||||
41 | 2 | 21µs | 2 | 92µs | return $parser_class->new(@parser_params); # spent 92µs making 2 calls to XML::SAX::Base::new, avg 46µs/call |
42 | } | ||||
43 | |||||
44 | sub require_feature { | ||||
45 | my $self = shift; | ||||
46 | my ($feature) = @_; | ||||
47 | $self->{RequiredFeatures}{$feature}++; | ||||
48 | return $self; | ||||
49 | } | ||||
50 | |||||
51 | # spent 2.70ms (113µs+2.59) within XML::SAX::ParserFactory::_parser_class which was called 2 times, avg 1.35ms/call:
# 2 times (113µs+2.59ms) by XML::SAX::ParserFactory::parser at line 29, avg 1.35ms/call | ||||
52 | 2 | 700ns | my $self = shift; | ||
53 | |||||
54 | # First try ParserPackage | ||||
55 | 2 | 600ns | if ($XML::SAX::ParserPackage) { | ||
56 | return $XML::SAX::ParserPackage; | ||||
57 | } | ||||
58 | |||||
59 | # Now check if required/preferred is there | ||||
60 | 2 | 700ns | if ($self->{RequiredFeatures}) { | ||
61 | my %required = %{$self->{RequiredFeatures}}; | ||||
62 | # note - we never go onto the next try (ParserDetails.ini), | ||||
63 | # because if we can't provide the requested feature | ||||
64 | # we need to throw an exception. | ||||
65 | PARSER: | ||||
66 | foreach my $parser (reverse @{$self->{KnownParsers}}) { | ||||
67 | foreach my $feature (keys %required) { | ||||
68 | if (!exists $parser->{Features}{$feature}) { | ||||
69 | next PARSER; | ||||
70 | } | ||||
71 | } | ||||
72 | # got here - all features must exist! | ||||
73 | return $parser->{Name}; | ||||
74 | } | ||||
75 | # TODO : should this be NotSupported() ? | ||||
76 | throw XML::SAX::Exception ( | ||||
77 | Message => "Unable to provide required features", | ||||
78 | ); | ||||
79 | } | ||||
80 | |||||
81 | # Next try SAX.ini | ||||
82 | 2 | 2µs | for my $dir (@INC) { | ||
83 | 20 | 19µs | 20 | 66µs | my $fh = gensym(); # spent 66µs making 20 calls to Symbol::gensym, avg 3µs/call |
84 | 20 | 2.60ms | 20 | 2.52ms | if (open($fh, "$dir/SAX.ini")) { # spent 2.52ms making 20 calls to XML::SAX::ParserFactory::CORE:open, avg 126µs/call |
85 | my $param_list = XML::SAX->_parse_ini_file($fh); | ||||
86 | my $params = $param_list->[0]->{Features}; | ||||
87 | if ($params->{ParserPackage}) { | ||||
88 | return $params->{ParserPackage}; | ||||
89 | } | ||||
90 | else { | ||||
91 | # we have required features (or nothing?) | ||||
92 | PARSER: | ||||
93 | foreach my $parser (reverse @{$self->{KnownParsers}}) { | ||||
94 | foreach my $feature (keys %$params) { | ||||
95 | if (!exists $parser->{Features}{$feature}) { | ||||
96 | next PARSER; | ||||
97 | } | ||||
98 | } | ||||
99 | return $parser->{Name}; | ||||
100 | } | ||||
101 | XML::SAX->do_warn("Unable to provide SAX.ini required features. Using fallback\n"); | ||||
102 | } | ||||
103 | last; # stop after first INI found | ||||
104 | } | ||||
105 | } | ||||
106 | |||||
107 | 2 | 10µs | if (@{$self->{KnownParsers}}) { | ||
108 | return $self->{KnownParsers}[-1]{Name}; | ||||
109 | } | ||||
110 | else { | ||||
111 | return "XML::SAX::PurePerl"; # backup plan! | ||||
112 | } | ||||
113 | } | ||||
114 | |||||
115 | 1 | 2µs | 1; | ||
116 | __END__ | ||||
# spent 2.52ms within XML::SAX::ParserFactory::CORE:open which was called 20 times, avg 126µs/call:
# 20 times (2.52ms+0s) by XML::SAX::ParserFactory::_parser_class at line 84, avg 126µs/call | |||||
# spent 2µs within XML::SAX::ParserFactory::CORE:subst which was called 2 times, avg 1µs/call:
# 2 times (2µs+0s) by XML::SAX::ParserFactory::parser at line 32, avg 1µs/call |