| Filename | /usr/lib64/perl5/vendor_perl/5.16.0/XML/SAX/ParserFactory.pm |
| Statements | Executed 86 statements in 5.96ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 2 | 1 | 1 | 4.87ms | 313ms | XML::SAX::ParserFactory::parser |
| 1 | 1 | 1 | 3.17ms | 4.16ms | XML::SAX::ParserFactory::BEGIN@12 |
| 2 | 1 | 1 | 808µs | 1.97ms | XML::SAX::ParserFactory::_parser_class |
| 18 | 1 | 1 | 600µs | 600µs | XML::SAX::ParserFactory::CORE:open (opcode) |
| 2 | 1 | 1 | 149µs | 2.54ms | XML::SAX::ParserFactory::new |
| 1 | 1 | 1 | 84µs | 183µs | XML::SAX::ParserFactory::BEGIN@5 |
| 1 | 1 | 1 | 79µs | 240µs | XML::SAX::ParserFactory::BEGIN@10 |
| 1 | 1 | 1 | 57µs | 57µs | XML::SAX::ParserFactory::BEGIN@11 |
| 1 | 1 | 1 | 51µs | 190µs | XML::SAX::ParserFactory::BEGIN@6 |
| 2 | 1 | 1 | 10µs | 10µs | XML::SAX::ParserFactory::CORE:subst (opcode) |
| 0 | 0 | 0 | 0s | 0s | XML::SAX::ParserFactory::require_feature |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # $Id$ | ||||
| 2 | |||||
| 3 | package XML::SAX::ParserFactory; | ||||
| 4 | |||||
| 5 | 2 | 162µs | 2 | 282µs | # spent 183µs (84+99) within XML::SAX::ParserFactory::BEGIN@5 which was called:
# once (84µs+99µs) by XML::SAX::BEGIN@18 at line 5 # spent 183µs making 1 call to XML::SAX::ParserFactory::BEGIN@5
# spent 99µs making 1 call to strict::import |
| 6 | 2 | 198µs | 2 | 330µs | # spent 190µs (51+140) within XML::SAX::ParserFactory::BEGIN@6 which was called:
# once (51µs+140µs) by XML::SAX::BEGIN@18 at line 6 # spent 190µs making 1 call to XML::SAX::ParserFactory::BEGIN@6
# spent 140µs making 1 call to vars::import |
| 7 | |||||
| 8 | 1 | 4µs | $VERSION = '1.01'; | ||
| 9 | |||||
| 10 | 2 | 165µs | 2 | 400µs | # spent 240µs (79+160) within XML::SAX::ParserFactory::BEGIN@10 which was called:
# once (79µs+160µs) by XML::SAX::BEGIN@18 at line 10 # spent 240µs making 1 call to XML::SAX::ParserFactory::BEGIN@10
# spent 160µs making 1 call to Exporter::import |
| 11 | 2 | 163µs | 1 | 57µs | # spent 57µs within XML::SAX::ParserFactory::BEGIN@11 which was called:
# once (57µs+0s) by XML::SAX::BEGIN@18 at line 11 # spent 57µs making 1 call to XML::SAX::ParserFactory::BEGIN@11 |
| 12 | 2 | 3.29ms | 1 | 4.16ms | # spent 4.16ms (3.17+987µs) within XML::SAX::ParserFactory::BEGIN@12 which was called:
# once (3.17ms+987µs) by XML::SAX::BEGIN@18 at line 12 # spent 4.16ms making 1 call to XML::SAX::ParserFactory::BEGIN@12 |
| 13 | |||||
| 14 | # spent 2.54ms (149µs+2.39) within XML::SAX::ParserFactory::new which was called 2 times, avg 1.27ms/call:
# 2 times (149µs+2.39ms) by XML::SAX::ParserFactory::parser at line 25, avg 1.27ms/call | ||||
| 15 | 2 | 6µs | my $class = shift; | ||
| 16 | 2 | 9µs | my %params = @_; # TODO : Fix this in spec. | ||
| 17 | 2 | 52µs | my $self = bless \%params, $class; | ||
| 18 | 2 | 42µs | 2 | 2.39ms | $self->{KnownParsers} = XML::SAX->parsers(); # spent 2.39ms making 2 calls to XML::SAX::parsers, avg 1.19ms/call |
| 19 | 2 | 40µs | return $self; | ||
| 20 | } | ||||
| 21 | |||||
| 22 | # spent 313ms (4.87+308) within XML::SAX::ParserFactory::parser which was called 2 times, avg 157ms/call:
# 2 times (4.87ms+308ms) by XML::Simple::build_tree at line 379 of XML/Simple.pm, avg 157ms/call | ||||
| 23 | 2 | 8µs | my $self = shift; | ||
| 24 | 2 | 15µs | my @parser_params = @_; | ||
| 25 | 2 | 40µs | 2 | 2.54ms | if (!ref($self)) { # spent 2.54ms making 2 calls to XML::SAX::ParserFactory::new, avg 1.27ms/call |
| 26 | $self = $self->new(); | ||||
| 27 | } | ||||
| 28 | |||||
| 29 | 2 | 30µs | 2 | 1.97ms | my $parser_class = $self->_parser_class(); # spent 1.97ms making 2 calls to XML::SAX::ParserFactory::_parser_class, avg 986µs/call |
| 30 | |||||
| 31 | 2 | 5µs | my $version = ''; | ||
| 32 | 2 | 48µs | 2 | 10µs | if ($parser_class =~ s/\s*\(([\d\.]+)\)\s*$//) { # spent 10µs making 2 calls to XML::SAX::ParserFactory::CORE:subst, avg 5µs/call |
| 33 | $version = " $1"; | ||||
| 34 | } | ||||
| 35 | |||||
| 36 | 2 | 77µs | 2 | 22µs | if (!$parser_class->can('new')) { # spent 22µs making 2 calls to UNIVERSAL::can, avg 11µs/call |
| 37 | 1 | 133µs | eval "require $parser_class $version;"; # spent 423µs executing statements in string eval | ||
| 38 | 1 | 2µs | die $@ if $@; | ||
| 39 | } | ||||
| 40 | |||||
| 41 | 2 | 129µs | 2 | 693µs | return $parser_class->new(@parser_params); # spent 693µs making 2 calls to XML::SAX::Base::new, avg 346µ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 1.97ms (808µs+1.16) within XML::SAX::ParserFactory::_parser_class which was called 2 times, avg 986µs/call:
# 2 times (808µs+1.16ms) by XML::SAX::ParserFactory::parser at line 29, avg 986µs/call | ||||
| 52 | 2 | 7µs | my $self = shift; | ||
| 53 | |||||
| 54 | # First try ParserPackage | ||||
| 55 | 2 | 2µs | if ($XML::SAX::ParserPackage) { | ||
| 56 | return $XML::SAX::ParserPackage; | ||||
| 57 | } | ||||
| 58 | |||||
| 59 | # Now check if required/preferred is there | ||||
| 60 | 2 | 4µs | 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 | 13µs | for my $dir (@INC) { | ||
| 83 | 18 | 181µs | 18 | 563µs | my $fh = gensym(); # spent 563µs making 18 calls to Symbol::gensym, avg 31µs/call |
| 84 | 18 | 1.07ms | 18 | 600µs | if (open($fh, "$dir/SAX.ini")) { # spent 600µs making 18 calls to XML::SAX::ParserFactory::CORE:open, avg 33µ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 | 56µ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 | 12µs | 1; | ||
| 116 | __END__ | ||||
# spent 600µs within XML::SAX::ParserFactory::CORE:open which was called 18 times, avg 33µs/call:
# 18 times (600µs+0s) by XML::SAX::ParserFactory::_parser_class at line 84, avg 33µs/call | |||||
# spent 10µs within XML::SAX::ParserFactory::CORE:subst which was called 2 times, avg 5µs/call:
# 2 times (10µs+0s) by XML::SAX::ParserFactory::parser at line 32, avg 5µs/call |