Filename | /usr/share/perl5/XML/SAX/ParserFactory.pm |
Statements | Executed 85030 statements in 296ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
5000 | 1 | 1 | 172ms | 797ms | parser | XML::SAX::ParserFactory::
5000 | 1 | 1 | 113ms | 113ms | _parser_class | XML::SAX::ParserFactory::
5000 | 1 | 1 | 9.82ms | 9.82ms | CORE:subst (opcode) | XML::SAX::ParserFactory::
1 | 1 | 1 | 1.08ms | 3.24ms | BEGIN@12 | XML::SAX::ParserFactory::
1 | 1 | 1 | 29µs | 1.27ms | new | XML::SAX::ParserFactory::
1 | 1 | 1 | 24µs | 31µs | BEGIN@5 | XML::SAX::ParserFactory::
1 | 1 | 1 | 17µs | 17µs | require_feature | XML::SAX::ParserFactory::
1 | 1 | 1 | 17µs | 60µs | BEGIN@6 | XML::SAX::ParserFactory::
1 | 1 | 1 | 16µs | 71µs | BEGIN@10 | XML::SAX::ParserFactory::
1 | 1 | 1 | 15µs | 43µs | BEGIN@37 | XML::SAX::ParserFactory::
1 | 1 | 1 | 13µs | 13µs | BEGIN@11 | XML::SAX::ParserFactory::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # $Id: ParserFactory.pm,v 1.13 2002/11/19 18:25:47 matt Exp $ | ||||
2 | |||||
3 | package XML::SAX::ParserFactory; | ||||
4 | |||||
5 | 3 | 99µs | 2 | 38µs | # spent 31µs (24+7) within XML::SAX::ParserFactory::BEGIN@5 which was called:
# once (24µs+7µs) by XML::SAX::BEGIN@18 at line 5 # spent 31µs making 1 call to XML::SAX::ParserFactory::BEGIN@5
# spent 7µs making 1 call to strict::import |
6 | 3 | 56µs | 2 | 103µs | # spent 60µs (17+43) within XML::SAX::ParserFactory::BEGIN@6 which was called:
# once (17µs+43µs) by XML::SAX::BEGIN@18 at line 6 # spent 60µs making 1 call to XML::SAX::ParserFactory::BEGIN@6
# spent 43µs making 1 call to vars::import |
7 | |||||
8 | 1 | 2µs | $VERSION = '1.01'; | ||
9 | |||||
10 | 3 | 39µs | 2 | 126µs | # spent 71µs (16+55) within XML::SAX::ParserFactory::BEGIN@10 which was called:
# once (16µs+55µs) by XML::SAX::BEGIN@18 at line 10 # spent 71µs making 1 call to XML::SAX::ParserFactory::BEGIN@10
# spent 55µs making 1 call to Exporter::import |
11 | 3 | 41µs | 1 | 13µs | # spent 13µs within XML::SAX::ParserFactory::BEGIN@11 which was called:
# once (13µs+0s) by XML::SAX::BEGIN@18 at line 11 # spent 13µs making 1 call to XML::SAX::ParserFactory::BEGIN@11 |
12 | 3 | 367µs | 1 | 3.24ms | # spent 3.24ms (1.08+2.16) within XML::SAX::ParserFactory::BEGIN@12 which was called:
# once (1.08ms+2.16ms) by XML::SAX::BEGIN@18 at line 12 # spent 3.24ms making 1 call to XML::SAX::ParserFactory::BEGIN@12 |
13 | |||||
14 | # spent 1.27ms (29µs+1.24) within XML::SAX::ParserFactory::new which was called:
# once (29µs+1.24ms) by main::BEGIN@3 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 | 11µs | my $self = bless \%params, $class; | ||
18 | 1 | 8µs | 1 | 1.24ms | $self->{KnownParsers} = XML::SAX->parsers(); # spent 1.24ms making 1 call to XML::SAX::parsers |
19 | 1 | 6µs | return $self; | ||
20 | } | ||||
21 | |||||
22 | # spent 797ms (172+624) within XML::SAX::ParserFactory::parser which was called 5000 times, avg 159µs/call:
# 5000 times (172ms+624ms) by MARC::File::XML::decode at line 439 of MARC/File/XML.pm, avg 159µs/call | ||||
23 | 5000 | 7.39ms | my $self = shift; | ||
24 | 5000 | 15.7ms | my @parser_params = @_; | ||
25 | 5000 | 6.72ms | if (!ref($self)) { | ||
26 | $self = $self->new(); | ||||
27 | } | ||||
28 | |||||
29 | 5000 | 26.5ms | 5000 | 113ms | my $parser_class = $self->_parser_class(); # spent 113ms making 5000 calls to XML::SAX::ParserFactory::_parser_class, avg 23µs/call |
30 | |||||
31 | 5000 | 6.67ms | my $version = ''; | ||
32 | 5000 | 31.2ms | 5000 | 9.82ms | if ($parser_class =~ s/\s*\(([\d\.]+)\)\s*$//) { # spent 9.82ms making 5000 calls to XML::SAX::ParserFactory::CORE:subst, avg 2µs/call |
33 | $version = " $1"; | ||||
34 | } | ||||
35 | |||||
36 | { | ||||
37 | 5003 | 10.9ms | 2 | 71µs | # spent 43µs (15+28) within XML::SAX::ParserFactory::BEGIN@37 which was called:
# once (15µs+28µs) by XML::SAX::BEGIN@18 at line 37 # spent 43µs making 1 call to XML::SAX::ParserFactory::BEGIN@37
# spent 28µs making 1 call to strict::unimport |
38 | 5000 | 19.0ms | if (!keys %{"${parser_class}::"}) { | ||
39 | 1 | 52µs | eval "use $parser_class $version;"; # spent 157µs executing statements in string eval # includes 2.74ms spent executing 1 call to 1 sub defined therein. | ||
40 | } | ||||
41 | } | ||||
42 | |||||
43 | 5000 | 48.4ms | 5000 | 486ms | return $parser_class->new(@parser_params); # spent 486ms making 5000 calls to XML::SAX::Base::new, avg 97µs/call |
44 | } | ||||
45 | |||||
46 | # spent 17µs within XML::SAX::ParserFactory::require_feature which was called:
# once (17µs+0s) by main::BEGIN@3 at line 20 of MARC/File/XML.pm | ||||
47 | 1 | 1µs | my $self = shift; | ||
48 | 1 | 8µs | my ($feature) = @_; | ||
49 | 1 | 4µs | $self->{RequiredFeatures}{$feature}++; | ||
50 | 1 | 6µs | return $self; | ||
51 | } | ||||
52 | |||||
53 | # spent 113ms within XML::SAX::ParserFactory::_parser_class which was called 5000 times, avg 23µs/call:
# 5000 times (113ms+0s) by XML::SAX::ParserFactory::parser at line 29, avg 23µs/call | ||||
54 | 5000 | 6.58ms | my $self = shift; | ||
55 | |||||
56 | # First try ParserPackage | ||||
57 | 5000 | 5.81ms | if ($XML::SAX::ParserPackage) { | ||
58 | return $XML::SAX::ParserPackage; | ||||
59 | } | ||||
60 | |||||
61 | # Now check if required/preferred is there | ||||
62 | 5000 | 9.84ms | if ($self->{RequiredFeatures}) { | ||
63 | 5000 | 17.1ms | my %required = %{$self->{RequiredFeatures}}; | ||
64 | # note - we never go onto the next try (ParserDetails.ini), | ||||
65 | # because if we can't provide the requested feature | ||||
66 | # we need to throw an exception. | ||||
67 | PARSER: | ||||
68 | 5000 | 11.8ms | foreach my $parser (reverse @{$self->{KnownParsers}}) { | ||
69 | 5000 | 17.3ms | foreach my $feature (keys %required) { | ||
70 | 5000 | 20.3ms | if (!exists $parser->{Features}{$feature}) { | ||
71 | next PARSER; | ||||
72 | } | ||||
73 | } | ||||
74 | # got here - all features must exist! | ||||
75 | 5000 | 33.6ms | return $parser->{Name}; | ||
76 | } | ||||
77 | # TODO : should this be NotSupported() ? | ||||
78 | throw XML::SAX::Exception ( | ||||
79 | Message => "Unable to provide required features", | ||||
80 | ); | ||||
81 | } | ||||
82 | |||||
83 | # Next try SAX.ini | ||||
84 | for my $dir (@INC) { | ||||
85 | my $fh = gensym(); | ||||
86 | if (open($fh, "$dir/SAX.ini")) { | ||||
87 | my $param_list = XML::SAX->_parse_ini_file($fh); | ||||
88 | my $params = $param_list->[0]->{Features}; | ||||
89 | if ($params->{ParserPackage}) { | ||||
90 | return $params->{ParserPackage}; | ||||
91 | } | ||||
92 | else { | ||||
93 | # we have required features (or nothing?) | ||||
94 | PARSER: | ||||
95 | foreach my $parser (reverse @{$self->{KnownParsers}}) { | ||||
96 | foreach my $feature (keys %$params) { | ||||
97 | if (!exists $parser->{Features}{$feature}) { | ||||
98 | next PARSER; | ||||
99 | } | ||||
100 | } | ||||
101 | return $parser->{Name}; | ||||
102 | } | ||||
103 | XML::SAX->do_warn("Unable to provide SAX.ini required features. Using fallback\n"); | ||||
104 | } | ||||
105 | last; # stop after first INI found | ||||
106 | } | ||||
107 | } | ||||
108 | |||||
109 | if (@{$self->{KnownParsers}}) { | ||||
110 | return $self->{KnownParsers}[-1]{Name}; | ||||
111 | } | ||||
112 | else { | ||||
113 | return "XML::SAX::PurePerl"; # backup plan! | ||||
114 | } | ||||
115 | } | ||||
116 | |||||
117 | 1 | 5µs | 1; | ||
118 | __END__ | ||||
# spent 9.82ms within XML::SAX::ParserFactory::CORE:subst which was called 5000 times, avg 2µs/call:
# 5000 times (9.82ms+0s) by XML::SAX::ParserFactory::parser at line 32, avg 2µs/call |