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