Filename | /usr/share/perl/5.10/Exporter/Heavy.pm |
Statements | Executed 7755 statements in 43.6ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
113 | 1 | 1 | 36.3ms | 40.9ms | heavy_export | Exporter::Heavy::
3744 | 6 | 1 | 4.08ms | 4.08ms | CORE:subst (opcode) | Exporter::Heavy::
4 | 1 | 1 | 456µs | 518µs | _rebuild_cache | Exporter::Heavy::
13 | 1 | 1 | 254µs | 3.60ms | heavy_export_to_level | Exporter::Heavy::
5 | 1 | 1 | 141µs | 141µs | _push_tags | Exporter::Heavy::
83 | 4 | 1 | 115µs | 115µs | CORE:match (opcode) | Exporter::Heavy::
5 | 1 | 1 | 47µs | 188µs | heavy_export_ok_tags | Exporter::Heavy::
1 | 1 | 1 | 34µs | 41µs | BEGIN@3 | Exporter::Heavy::
1 | 1 | 1 | 30µs | 90µs | BEGIN@186 | Exporter::Heavy::
1 | 1 | 1 | 8µs | 22µs | BEGIN@4 | Exporter::Heavy::
0 | 0 | 0 | 0s | 0s | __ANON__[:41] | Exporter::Heavy::
0 | 0 | 0 | 0s | 0s | __ANON__[:47] | Exporter::Heavy::
0 | 0 | 0 | 0s | 0s | heavy_export_tags | Exporter::Heavy::
0 | 0 | 0 | 0s | 0s | heavy_require_version | Exporter::Heavy::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Exporter::Heavy; | ||||
2 | |||||
3 | 3 | 46µs | 2 | 48µs | # spent 41µs (34+7) within Exporter::Heavy::BEGIN@3 which was called:
# once (34µs+7µs) by Exporter::as_heavy at line 3 # spent 41µs making 1 call to Exporter::Heavy::BEGIN@3
# spent 7µs making 1 call to strict::import |
4 | 3 | 1.14ms | 2 | 36µs | # spent 22µs (8+14) within Exporter::Heavy::BEGIN@4 which was called:
# once (8µs+14µs) by Exporter::as_heavy at line 4 # spent 22µs making 1 call to Exporter::Heavy::BEGIN@4
# spent 14µs making 1 call to strict::unimport |
5 | |||||
6 | # On one line so MakeMaker will see it. | ||||
7 | 2 | 2µs | require Exporter; our $VERSION = $Exporter::VERSION; | ||
8 | |||||
9 | # Carp 1.05+ does this now for us, but we may be running with an old Carp | ||||
10 | 1 | 2µs | $Carp::Internal{'Exporter::Heavy'}++; | ||
11 | |||||
12 | # | ||||
13 | # We go to a lot of trouble not to 'require Carp' at file scope, | ||||
14 | # because Carp requires Exporter, and something has to give. | ||||
15 | # | ||||
16 | |||||
17 | # spent 518µs (456+62) within Exporter::Heavy::_rebuild_cache which was called 4 times, avg 130µs/call:
# 4 times (456µs+62µs) by Exporter::Heavy::heavy_export at line 56, avg 130µs/call | ||||
18 | 4 | 10µs | my ($pkg, $exports, $cache) = @_; | ||
19 | 8 | 302µs | 94 | 52µs | s/^&// foreach @$exports; # spent 52µs making 94 calls to Exporter::Heavy::CORE:subst, avg 559ns/call |
20 | 4 | 89µs | @{$cache}{@$exports} = (1) x @$exports; | ||
21 | 4 | 17µs | my $ok = \@{"${pkg}::EXPORT_OK"}; | ||
22 | 4 | 20µs | if (@$ok) { | ||
23 | 6 | 66µs | 27 | 10µs | s/^&// foreach @$ok; # spent 10µs making 27 calls to Exporter::Heavy::CORE:subst, avg 359ns/call |
24 | 3 | 17µs | @{$cache}{@$ok} = (1) x @$ok; | ||
25 | } | ||||
26 | } | ||||
27 | |||||
28 | # spent 40.9ms (36.3+4.65) within Exporter::Heavy::heavy_export which was called 113 times, avg 362µs/call:
# 113 times (36.3ms+4.65ms) by Exporter::Heavy::heavy_export_to_level or Exporter::import or FileHandle::import or IO::Socket::import or LWP::Simple::import at line 28 of Exporter.pm, avg 362µs/call | ||||
29 | |||||
30 | # First make import warnings look like they're coming from the "use". | ||||
31 | local $SIG{__WARN__} = sub { | ||||
32 | my $text = shift; | ||||
33 | if ($text =~ s/ at \S*Exporter\S*.pm line \d+.*\n//) { | ||||
34 | require Carp; | ||||
35 | local $Carp::CarpLevel = 1; # ignore package calling us too. | ||||
36 | Carp::carp($text); | ||||
37 | } | ||||
38 | else { | ||||
39 | warn $text; | ||||
40 | } | ||||
41 | 113 | 1.22ms | }; | ||
42 | local $SIG{__DIE__} = sub { | ||||
43 | require Carp; | ||||
44 | local $Carp::CarpLevel = 1; # ignore package calling us too. | ||||
45 | Carp::croak("$_[0]Illegal null symbol in \@${1}::EXPORT") | ||||
46 | if $_[0] =~ /^Unable to create sub named "(.*?)::"/; | ||||
47 | 113 | 839µs | }; | ||
48 | |||||
49 | 113 | 252µs | my($pkg, $callpkg, @imports) = @_; | ||
50 | 113 | 91µs | my($type, $sym, $cache_is_current, $oops); | ||
51 | 113 | 517µs | my($exports, $export_cache) = (\@{"${pkg}::EXPORT"}, | ||
52 | $Exporter::Cache{$pkg} ||= {}); | ||||
53 | |||||
54 | 113 | 265µs | if (@imports) { | ||
55 | 33 | 78µs | if (!%$export_cache) { | ||
56 | 4 | 15µs | 4 | 518µs | _rebuild_cache ($pkg, $exports, $export_cache); # spent 518µs making 4 calls to Exporter::Heavy::_rebuild_cache, avg 130µs/call |
57 | 4 | 4µs | $cache_is_current = 1; | ||
58 | } | ||||
59 | |||||
60 | 33 | 308µs | 45 | 77µs | if (grep m{^[/!:]}, @imports) { # spent 77µs making 45 calls to Exporter::Heavy::CORE:match, avg 2µs/call |
61 | 28 | 79µs | my $tagsref = \%{"${pkg}::EXPORT_TAGS"}; | ||
62 | 28 | 8µs | my $tagdata; | ||
63 | 28 | 9µs | my %imports; | ||
64 | 28 | 23µs | my($remove, $spec, @names, @allexports); | ||
65 | # negated first item implies starting with default set: | ||||
66 | 28 | 103µs | 28 | 26µs | unshift @imports, ':DEFAULT' if $imports[0] =~ m/^!/; # spent 26µs making 28 calls to Exporter::Heavy::CORE:match, avg 946ns/call |
67 | 28 | 47µs | foreach $spec (@imports){ | ||
68 | 37 | 132µs | 37 | 22µs | $remove = $spec =~ s/^!//; # spent 22µs making 37 calls to Exporter::Heavy::CORE:subst, avg 608ns/call |
69 | |||||
70 | 37 | 250µs | 43 | 114µs | if ($spec =~ s/^://){ # spent 108µs making 37 calls to Exporter::Heavy::CORE:subst, avg 3µs/call
# spent 6µs making 6 calls to Exporter::Heavy::CORE:match, avg 1µs/call |
71 | 31 | 276µs | if ($spec eq 'DEFAULT'){ | ||
72 | @names = @$exports; | ||||
73 | } | ||||
74 | elsif ($tagdata = $tagsref->{$spec}) { | ||||
75 | @names = @$tagdata; | ||||
76 | } | ||||
77 | else { | ||||
78 | warn qq["$spec" is not defined in %${pkg}::EXPORT_TAGS]; | ||||
79 | ++$oops; | ||||
80 | next; | ||||
81 | } | ||||
82 | } | ||||
83 | elsif ($spec =~ m:^/(.*)/$:){ | ||||
84 | my $patn = $1; | ||||
85 | @allexports = keys %$export_cache unless @allexports; # only do keys once | ||||
86 | @names = grep(/$patn/, @allexports); # not anchored by default | ||||
87 | } | ||||
88 | else { | ||||
89 | 6 | 11µs | @names = ($spec); # is a normal symbol name | ||
90 | } | ||||
91 | |||||
92 | 37 | 16µs | warn "Import ".($remove ? "del":"add").": @names " | ||
93 | if $Exporter::Verbose; | ||||
94 | |||||
95 | 37 | 78µs | if ($remove) { | ||
96 | foreach $sym (@names) { delete $imports{$sym} } | ||||
97 | } | ||||
98 | else { | ||||
99 | 37 | 273µs | @imports{@names} = (1) x @names; | ||
100 | } | ||||
101 | } | ||||
102 | 28 | 320µs | @imports = keys %imports; | ||
103 | } | ||||
104 | |||||
105 | 33 | 18µs | my @carp; | ||
106 | 33 | 47µs | foreach $sym (@imports) { | ||
107 | 448 | 333µs | if (!$export_cache->{$sym}) { | ||
108 | 4 | 64µs | 8 | 10µs | if ($sym =~ m/^\d/) { # spent 5µs making 4 calls to Exporter::Heavy::CORE:subst, avg 1µs/call
# spent 5µs making 4 calls to Exporter::Heavy::CORE:match, avg 1µs/call |
109 | $pkg->VERSION($sym); # inherit from UNIVERSAL | ||||
110 | # If the version number was the only thing specified | ||||
111 | # then we should act as if nothing was specified: | ||||
112 | if (@imports == 1) { | ||||
113 | @imports = @$exports; | ||||
114 | last; | ||||
115 | } | ||||
116 | # We need a way to emulate 'use Foo ()' but still | ||||
117 | # allow an easy version check: "use Foo 1.23, ''"; | ||||
118 | if (@imports == 2 and !$imports[1]) { | ||||
119 | @imports = (); | ||||
120 | last; | ||||
121 | } | ||||
122 | } elsif ($sym !~ s/^&// || !$export_cache->{$sym}) { | ||||
123 | # Last chance - see if they've updated EXPORT_OK since we | ||||
124 | # cached it. | ||||
125 | |||||
126 | unless ($cache_is_current) { | ||||
127 | %$export_cache = (); | ||||
128 | _rebuild_cache ($pkg, $exports, $export_cache); | ||||
129 | $cache_is_current = 1; | ||||
130 | } | ||||
131 | |||||
132 | if (!$export_cache->{$sym}) { | ||||
133 | # accumulate the non-exports | ||||
134 | push @carp, | ||||
135 | qq["$sym" is not exported by the $pkg module\n]; | ||||
136 | $oops++; | ||||
137 | } | ||||
138 | } | ||||
139 | } | ||||
140 | } | ||||
141 | 33 | 22µs | if ($oops) { | ||
142 | require Carp; | ||||
143 | Carp::croak("@{carp}Can't continue after import errors"); | ||||
144 | } | ||||
145 | } | ||||
146 | else { | ||||
147 | 80 | 1.25ms | @imports = @$exports; | ||
148 | } | ||||
149 | |||||
150 | 113 | 486µs | my($fail, $fail_cache) = (\@{"${pkg}::EXPORT_FAIL"}, | ||
151 | $Exporter::FailCache{$pkg} ||= {}); | ||||
152 | |||||
153 | 113 | 73µs | if (@$fail) { | ||
154 | if (!%$fail_cache) { | ||||
155 | # Build cache of symbols. Optimise the lookup by adding | ||||
156 | # barewords twice... both with and without a leading &. | ||||
157 | # (Technique could be applied to $export_cache at cost of memory) | ||||
158 | my @expanded = map { /^\w/ ? ($_, '&'.$_) : $_ } @$fail; | ||||
159 | warn "${pkg}::EXPORT_FAIL cached: @expanded" if $Exporter::Verbose; | ||||
160 | @{$fail_cache}{@expanded} = (1) x @expanded; | ||||
161 | } | ||||
162 | my @failed; | ||||
163 | foreach $sym (@imports) { push(@failed, $sym) if $fail_cache->{$sym} } | ||||
164 | if (@failed) { | ||||
165 | @failed = $pkg->export_fail(@failed); | ||||
166 | foreach $sym (@failed) { | ||||
167 | require Carp; | ||||
168 | Carp::carp(qq["$sym" is not implemented by the $pkg module ], | ||||
169 | "on this architecture"); | ||||
170 | } | ||||
171 | if (@failed) { | ||||
172 | require Carp; | ||||
173 | Carp::croak("Can't continue after import errors"); | ||||
174 | } | ||||
175 | } | ||||
176 | } | ||||
177 | |||||
178 | 113 | 55µs | warn "Importing into $callpkg from $pkg: ", | ||
179 | join(", ",sort @imports) if $Exporter::Verbose; | ||||
180 | |||||
181 | 113 | 2.94ms | foreach $sym (@imports) { | ||
182 | # shortcut for the common case of no type character | ||||
183 | 3545 | 22.3ms | 3545 | 3.88ms | (*{"${callpkg}::$sym"} = \&{"${pkg}::$sym"}, next) # spent 3.88ms making 3545 calls to Exporter::Heavy::CORE:subst, avg 1µs/call |
184 | unless $sym =~ s/^(\W)//; | ||||
185 | 908 | 1.30ms | $type = $1; | ||
186 | 3 | 705µs | 2 | 149µs | # spent 90µs (30+60) within Exporter::Heavy::BEGIN@186 which was called:
# once (30µs+60µs) by Exporter::as_heavy at line 186 # spent 90µs making 1 call to Exporter::Heavy::BEGIN@186
# spent 60µs making 1 call to warnings::unimport |
187 | *{"${callpkg}::$sym"} = | ||||
188 | $type eq '&' ? \&{"${pkg}::$sym"} : | ||||
189 | $type eq '$' ? \${"${pkg}::$sym"} : | ||||
190 | $type eq '@' ? \@{"${pkg}::$sym"} : | ||||
191 | $type eq '%' ? \%{"${pkg}::$sym"} : | ||||
192 | $type eq '*' ? *{"${pkg}::$sym"} : | ||||
193 | 908 | 6.61ms | do { require Carp; Carp::croak("Can't export symbol: $type$sym") }; | ||
194 | } | ||||
195 | } | ||||
196 | |||||
197 | sub heavy_export_to_level | ||||
198 | # spent 3.60ms (254µs+3.35) within Exporter::Heavy::heavy_export_to_level which was called 13 times, avg 277µs/call:
# 13 times (254µs+3.35ms) by JSON::import or Memoize::Memcached::import or XML::LibXML::import at line 82 of Exporter.pm, avg 277µs/call | ||||
199 | 13 | 21µs | my $pkg = shift; | ||
200 | 13 | 11µs | my $level = shift; | ||
201 | 13 | 23µs | (undef) = shift; # XXX redundant arg | ||
202 | 13 | 19µs | my $callpkg = caller($level); | ||
203 | 13 | 120µs | 13 | 271µs | $pkg->export($callpkg, @_); # spent 271µs making 13 calls to Exporter::export, avg 21µs/call |
204 | } | ||||
205 | |||||
206 | # Utility functions | ||||
207 | |||||
208 | # spent 141µs within Exporter::Heavy::_push_tags which was called 5 times, avg 28µs/call:
# 5 times (141µs+0s) by Exporter::Heavy::heavy_export_ok_tags at line 234, avg 28µs/call | ||||
209 | 5 | 12µs | my($pkg, $var, $syms) = @_; | ||
210 | 5 | 5µs | my @nontag = (); | ||
211 | 5 | 19µs | my $export_tags = \%{"${pkg}::EXPORT_TAGS"}; | ||
212 | push(@{"${pkg}::$var"}, | ||||
213 | 5 | 86µs | map { $export_tags->{$_} ? @{$export_tags->{$_}} | ||
214 | : scalar(push(@nontag,$_),$_) } | ||||
215 | (@$syms) ? @$syms : keys %$export_tags); | ||||
216 | 5 | 29µs | if (@nontag and $^W) { | ||
217 | # This may change to a die one day | ||||
218 | require Carp; | ||||
219 | Carp::carp(join(", ", @nontag)." are not tags of $pkg"); | ||||
220 | } | ||||
221 | } | ||||
222 | |||||
223 | sub heavy_require_version { | ||||
224 | my($self, $wanted) = @_; | ||||
225 | my $pkg = ref $self || $self; | ||||
226 | return ${pkg}->VERSION($wanted); | ||||
227 | } | ||||
228 | |||||
229 | sub heavy_export_tags { | ||||
230 | _push_tags((caller)[0], "EXPORT", \@_); | ||||
231 | } | ||||
232 | |||||
233 | # spent 188µs (47+141) within Exporter::Heavy::heavy_export_ok_tags which was called 5 times, avg 38µs/call:
# 5 times (47µs+141µs) by Compress::Zlib::BEGIN@13 or Compress::Zlib::BEGIN@14 or DBI::BEGIN@160 or IO::Compress::Gzip::BEGIN@11 or IO::Uncompress::Gunzip::BEGIN@12 at line 90 of Exporter.pm, avg 38µs/call | ||||
234 | 5 | 58µs | 5 | 141µs | _push_tags((caller)[0], "EXPORT_OK", \@_); # spent 141µs making 5 calls to Exporter::Heavy::_push_tags, avg 28µs/call |
235 | } | ||||
236 | |||||
237 | 1 | 6µs | 1; | ||
# spent 115µs within Exporter::Heavy::CORE:match which was called 83 times, avg 1µs/call:
# 45 times (77µs+0s) by Exporter::Heavy::heavy_export at line 60, avg 2µs/call
# 28 times (26µs+0s) by Exporter::Heavy::heavy_export at line 66, avg 946ns/call
# 6 times (6µs+0s) by Exporter::Heavy::heavy_export at line 70, avg 1µs/call
# 4 times (5µs+0s) by Exporter::Heavy::heavy_export at line 108, avg 1µs/call | |||||
# spent 4.08ms within Exporter::Heavy::CORE:subst which was called 3744 times, avg 1µs/call:
# 3545 times (3.88ms+0s) by Exporter::Heavy::heavy_export at line 183, avg 1µs/call
# 94 times (52µs+0s) by Exporter::Heavy::_rebuild_cache at line 19, avg 559ns/call
# 37 times (108µs+0s) by Exporter::Heavy::heavy_export at line 70, avg 3µs/call
# 37 times (22µs+0s) by Exporter::Heavy::heavy_export at line 68, avg 608ns/call
# 27 times (10µs+0s) by Exporter::Heavy::_rebuild_cache at line 23, avg 359ns/call
# 4 times (5µs+0s) by Exporter::Heavy::heavy_export at line 108, avg 1µs/call |