Filename | /usr/share/perl5/XML/SAX/ParserFactory.pm |
Statements | Executed 542 statements in 4.02ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
28 | 2 | 2 | 3.03ms | 61.3ms | parser | XML::SAX::ParserFactory::
28 | 1 | 1 | 1.11ms | 1.84ms | _parser_class | XML::SAX::ParserFactory::
1 | 1 | 1 | 757µs | 1.06ms | BEGIN@12 | XML::SAX::ParserFactory::
30 | 1 | 1 | 445µs | 445µs | CORE:open (opcode) | XML::SAX::ParserFactory::
4 | 2 | 2 | 124µs | 808µs | new | XML::SAX::ParserFactory::
1 | 1 | 1 | 122µs | 122µs | BEGIN@11 | XML::SAX::ParserFactory::
28 | 1 | 1 | 45µs | 45µs | CORE:subst (opcode) | XML::SAX::ParserFactory::
1 | 1 | 1 | 16µs | 21µs | BEGIN@5 | XML::SAX::ParserFactory::
1 | 1 | 1 | 10µs | 67µs | BEGIN@10 | XML::SAX::ParserFactory::
1 | 1 | 1 | 8µs | 33µs | BEGIN@6 | XML::SAX::ParserFactory::
1 | 1 | 1 | 6µs | 6µs | require_feature | XML::SAX::ParserFactory::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # $Id: ParserFactory.pm,v 1.14 2008-08-04 04:51:29 grant Exp $ | ||||
2 | |||||
3 | package XML::SAX::ParserFactory; | ||||
4 | |||||
5 | 3 | 29µs | 2 | 25µs | # spent 21µs (16+4) within XML::SAX::ParserFactory::BEGIN@5 which was called:
# once (16µs+4µs) by XML::SAX::BEGIN@18 at line 5 # spent 21µs making 1 call to XML::SAX::ParserFactory::BEGIN@5
# spent 4µs making 1 call to strict::import |
6 | 3 | 37µs | 2 | 58µs | # spent 33µs (8+25) within XML::SAX::ParserFactory::BEGIN@6 which was called:
# once (8µs+25µs) by XML::SAX::BEGIN@18 at line 6 # spent 33µs making 1 call to XML::SAX::ParserFactory::BEGIN@6
# spent 25µs making 1 call to vars::import |
7 | |||||
8 | 1 | 900ns | $VERSION = '1.01'; | ||
9 | |||||
10 | 3 | 156µs | 2 | 124µs | # spent 67µs (10+57) within XML::SAX::ParserFactory::BEGIN@10 which was called:
# once (10µs+57µs) by XML::SAX::BEGIN@18 at line 10 # spent 67µs making 1 call to XML::SAX::ParserFactory::BEGIN@10
# spent 57µs making 1 call to Exporter::import |
11 | 3 | 40µs | 1 | 122µs | # spent 122µs within XML::SAX::ParserFactory::BEGIN@11 which was called:
# once (122µs+0s) by XML::SAX::BEGIN@18 at line 11 # spent 122µs making 1 call to XML::SAX::ParserFactory::BEGIN@11 |
12 | 3 | 634µs | 1 | 1.06ms | # spent 1.06ms (757µs+299µs) within XML::SAX::ParserFactory::BEGIN@12 which was called:
# once (757µs+299µs) by XML::SAX::BEGIN@18 at line 12 # spent 1.06ms making 1 call to XML::SAX::ParserFactory::BEGIN@12 |
13 | |||||
14 | # spent 808µs (124+684) within XML::SAX::ParserFactory::new which was called 4 times, avg 202µs/call:
# 3 times (98µs+679µs) by XML::SAX::ParserFactory::parser at line 25, avg 259µs/call
# once (26µs+5µs) by C4::Biblio::BEGIN@29 at line 19 of MARC/File/XML.pm | ||||
15 | 4 | 7µs | my $class = shift; | ||
16 | 4 | 9µs | my %params = @_; # TODO : Fix this in spec. | ||
17 | 4 | 43µs | my $self = bless \%params, $class; | ||
18 | 4 | 34µs | 4 | 684µs | $self->{KnownParsers} = XML::SAX->parsers(); # spent 684µs making 4 calls to XML::SAX::parsers, avg 171µs/call |
19 | 4 | 24µs | return $self; | ||
20 | } | ||||
21 | |||||
22 | # spent 61.3ms (3.03+58.2) within XML::SAX::ParserFactory::parser which was called 28 times, avg 2.19ms/call:
# 25 times (979µs+2.97ms) by MARC::File::XML::decode at line 439 of MARC/File/XML.pm, avg 158µs/call
# 3 times (2.05ms+55.3ms) by XML::Simple::build_tree at line 358 of XML/Simple.pm, avg 19.1ms/call | ||||
23 | 28 | 36µs | my $self = shift; | ||
24 | 28 | 104µs | my @parser_params = @_; | ||
25 | 28 | 57µs | 3 | 777µs | if (!ref($self)) { # spent 777µs making 3 calls to XML::SAX::ParserFactory::new, avg 259µs/call |
26 | $self = $self->new(); | ||||
27 | } | ||||
28 | |||||
29 | 28 | 146µs | 28 | 1.84ms | my $parser_class = $self->_parser_class(); # spent 1.84ms making 28 calls to XML::SAX::ParserFactory::_parser_class, avg 66µs/call |
30 | |||||
31 | 28 | 21µs | my $version = ''; | ||
32 | 28 | 163µs | 28 | 45µs | if ($parser_class =~ s/\s*\(([\d\.]+)\)\s*$//) { # spent 45µs making 28 calls to XML::SAX::ParserFactory::CORE:subst, avg 2µs/call |
33 | $version = " $1"; | ||||
34 | } | ||||
35 | |||||
36 | 28 | 476µs | 28 | 231µs | if (!$parser_class->can('new')) { # spent 231µs making 28 calls to UNIVERSAL::can, avg 8µs/call |
37 | 1 | 47µs | eval "require $parser_class $version;"; # spent 123µs executing statements in string eval | ||
38 | 1 | 700ns | die $@ if $@; | ||
39 | } | ||||
40 | |||||
41 | 28 | 347µs | 28 | 2.31ms | return $parser_class->new(@parser_params); # spent 2.31ms making 28 calls to XML::SAX::Base::new, avg 82µs/call |
42 | } | ||||
43 | |||||
44 | # spent 6µs within XML::SAX::ParserFactory::require_feature which was called:
# once (6µs+0s) by C4::Biblio::BEGIN@29 at line 20 of MARC/File/XML.pm | ||||
45 | 1 | 600ns | my $self = shift; | ||
46 | 1 | 1µs | my ($feature) = @_; | ||
47 | 1 | 2µs | $self->{RequiredFeatures}{$feature}++; | ||
48 | 1 | 10µs | return $self; | ||
49 | } | ||||
50 | |||||
51 | # spent 1.84ms (1.11+731µs) within XML::SAX::ParserFactory::_parser_class which was called 28 times, avg 66µs/call:
# 28 times (1.11ms+731µs) by XML::SAX::ParserFactory::parser at line 29, avg 66µs/call | ||||
52 | 28 | 34µs | my $self = shift; | ||
53 | |||||
54 | # First try ParserPackage | ||||
55 | 28 | 26µs | if ($XML::SAX::ParserPackage) { | ||
56 | return $XML::SAX::ParserPackage; | ||||
57 | } | ||||
58 | |||||
59 | # Now check if required/preferred is there | ||||
60 | 28 | 65µs | if ($self->{RequiredFeatures}) { | ||
61 | 25 | 152µs | 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 | 25 | 76µs | foreach my $parser (reverse @{$self->{KnownParsers}}) { | ||
67 | 25 | 79µs | foreach my $feature (keys %required) { | ||
68 | 25 | 116µs | if (!exists $parser->{Features}{$feature}) { | ||
69 | next PARSER; | ||||
70 | } | ||||
71 | } | ||||
72 | # got here - all features must exist! | ||||
73 | 25 | 220µs | 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 | 3 | 7µs | for my $dir (@INC) { | ||
83 | 30 | 92µs | 30 | 286µs | my $fh = gensym(); # spent 286µs making 30 calls to Symbol::gensym, avg 10µs/call |
84 | 30 | 700µs | 30 | 445µs | if (open($fh, "$dir/SAX.ini")) { # spent 445µs making 30 calls to XML::SAX::ParserFactory::CORE:open, avg 15µ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 | 3 | 26µ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 | 3µs | 1; | ||
116 | __END__ | ||||
# spent 445µs within XML::SAX::ParserFactory::CORE:open which was called 30 times, avg 15µs/call:
# 30 times (445µs+0s) by XML::SAX::ParserFactory::_parser_class at line 84, avg 15µs/call | |||||
# spent 45µs within XML::SAX::ParserFactory::CORE:subst which was called 28 times, avg 2µs/call:
# 28 times (45µs+0s) by XML::SAX::ParserFactory::parser at line 32, avg 2µs/call |