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