Filename | /usr/share/perl5/XML/SAX/ParserFactory.pm |
Statements | Executed 428 statements in 2.73ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
25 | 1 | 1 | 2.42ms | 12.1ms | parser | XML::SAX::ParserFactory::
25 | 1 | 1 | 674µs | 674µs | _parser_class | XML::SAX::ParserFactory::
25 | 1 | 1 | 48µs | 48µs | CORE:subst (opcode) | XML::SAX::ParserFactory::
1 | 1 | 1 | 29µs | 771µs | new | XML::SAX::ParserFactory::
1 | 1 | 1 | 21µs | 26µs | BEGIN@5 | XML::SAX::ParserFactory::
1 | 1 | 1 | 20µs | 22µs | BEGIN@12 | XML::SAX::ParserFactory::
1 | 1 | 1 | 15µs | 17µs | BEGIN@11 | XML::SAX::ParserFactory::
1 | 1 | 1 | 10µs | 10µs | require_feature | XML::SAX::ParserFactory::
1 | 1 | 1 | 10µs | 76µs | BEGIN@10 | XML::SAX::ParserFactory::
1 | 1 | 1 | 9µs | 37µs | BEGIN@6 | 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 | 30µs | 2 | 30µs | # spent 26µs (21+4) within XML::SAX::ParserFactory::BEGIN@5 which was called:
# once (21µs+4µs) by XML::SAX::BEGIN@18 at line 5 # spent 26µs making 1 call to XML::SAX::ParserFactory::BEGIN@5
# spent 4µs making 1 call to strict::import |
6 | 3 | 42µs | 2 | 65µs | # spent 37µs (9+28) within XML::SAX::ParserFactory::BEGIN@6 which was called:
# once (9µs+28µs) by XML::SAX::BEGIN@18 at line 6 # spent 37µs making 1 call to XML::SAX::ParserFactory::BEGIN@6
# spent 28µs making 1 call to vars::import |
7 | |||||
8 | 1 | 700ns | $VERSION = '1.01'; | ||
9 | |||||
10 | 3 | 37µs | 2 | 142µs | # spent 76µs (10+66) within XML::SAX::ParserFactory::BEGIN@10 which was called:
# once (10µs+66µs) by XML::SAX::BEGIN@18 at line 10 # spent 76µs making 1 call to XML::SAX::ParserFactory::BEGIN@10
# spent 66µs making 1 call to Exporter::import |
11 | 3 | 31µs | 2 | 19µs | # spent 17µs (15+2) within XML::SAX::ParserFactory::BEGIN@11 which was called:
# once (15µs+2µs) by XML::SAX::BEGIN@18 at line 11 # spent 17µs making 1 call to XML::SAX::ParserFactory::BEGIN@11
# spent 2µs making 1 call to UNIVERSAL::import |
12 | 3 | 588µs | 2 | 23µs | # spent 22µs (20+1) within XML::SAX::ParserFactory::BEGIN@12 which was called:
# once (20µs+1µs) by XML::SAX::BEGIN@18 at line 12 # spent 22µs making 1 call to XML::SAX::ParserFactory::BEGIN@12
# spent 2µs making 1 call to UNIVERSAL::import |
13 | |||||
14 | # spent 771µs (29+741) within XML::SAX::ParserFactory::new which was called:
# once (29µs+741µs) by C4::Biblio::BEGIN@29 at line 19 of MARC/File/XML.pm | ||||
15 | 1 | 2µs | my $class = shift; | ||
16 | 1 | 2µs | my %params = @_; # TODO : Fix this in spec. | ||
17 | 1 | 12µs | my $self = bless \%params, $class; | ||
18 | 1 | 6µs | 1 | 741µs | $self->{KnownParsers} = XML::SAX->parsers(); # spent 741µs making 1 call to XML::SAX::parsers |
19 | 1 | 5µs | return $self; | ||
20 | } | ||||
21 | |||||
22 | # spent 12.1ms (2.42+9.68) within XML::SAX::ParserFactory::parser which was called 25 times, avg 484µs/call:
# 25 times (2.42ms+9.68ms) by MARC::File::XML::decode at line 439 of MARC/File/XML.pm, avg 484µs/call | ||||
23 | 25 | 20µs | my $self = shift; | ||
24 | 25 | 84µs | my @parser_params = @_; | ||
25 | 25 | 31µs | if (!ref($self)) { | ||
26 | $self = $self->new(); | ||||
27 | } | ||||
28 | |||||
29 | 25 | 125µs | 25 | 674µs | my $parser_class = $self->_parser_class(); # spent 674µs making 25 calls to XML::SAX::ParserFactory::_parser_class, avg 27µs/call |
30 | |||||
31 | 25 | 25µs | my $version = ''; | ||
32 | 25 | 169µs | 25 | 48µs | if ($parser_class =~ s/\s*\(([\d\.]+)\)\s*$//) { # spent 48µs making 25 calls to XML::SAX::ParserFactory::CORE:subst, avg 2µs/call |
33 | $version = " $1"; | ||||
34 | } | ||||
35 | |||||
36 | 25 | 449µs | 25 | 230µs | if (!$parser_class->can('new')) { # spent 230µs making 25 calls to UNIVERSAL::can, avg 9µs/call |
37 | 1 | 52µs | eval "require $parser_class $version;"; # spent 169µs executing statements in string eval | ||
38 | 1 | 700ns | die $@ if $@; | ||
39 | } | ||||
40 | |||||
41 | 25 | 257µs | 25 | 2.00ms | return $parser_class->new(@parser_params); # spent 2.00ms making 25 calls to XML::SAX::Base::new, avg 80µs/call |
42 | } | ||||
43 | |||||
44 | # spent 10µs within XML::SAX::ParserFactory::require_feature which was called:
# once (10µs+0s) by C4::Biblio::BEGIN@29 at line 20 of MARC/File/XML.pm | ||||
45 | 1 | 1µs | my $self = shift; | ||
46 | 1 | 2µs | my ($feature) = @_; | ||
47 | 1 | 3µs | $self->{RequiredFeatures}{$feature}++; | ||
48 | 1 | 13µs | return $self; | ||
49 | } | ||||
50 | |||||
51 | # spent 674µs within XML::SAX::ParserFactory::_parser_class which was called 25 times, avg 27µs/call:
# 25 times (674µs+0s) by XML::SAX::ParserFactory::parser at line 29, avg 27µs/call | ||||
52 | 25 | 25µs | my $self = shift; | ||
53 | |||||
54 | # First try ParserPackage | ||||
55 | 25 | 27µs | if ($XML::SAX::ParserPackage) { | ||
56 | return $XML::SAX::ParserPackage; | ||||
57 | } | ||||
58 | |||||
59 | # Now check if required/preferred is there | ||||
60 | 25 | 48µs | if ($self->{RequiredFeatures}) { | ||
61 | 25 | 153µ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 | 69µs | foreach my $feature (keys %required) { | ||
68 | 25 | 101µs | if (!exists $parser->{Features}{$feature}) { | ||
69 | next PARSER; | ||||
70 | } | ||||
71 | } | ||||
72 | # got here - all features must exist! | ||||
73 | 25 | 242µ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 | for my $dir (@INC) { | ||||
83 | my $fh = gensym(); | ||||
84 | if (open($fh, "$dir/SAX.ini")) { | ||||
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 | 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 48µs within XML::SAX::ParserFactory::CORE:subst which was called 25 times, avg 2µs/call:
# 25 times (48µs+0s) by XML::SAX::ParserFactory::parser at line 32, avg 2µs/call |