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