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