File | /usr/local/lib/perl5/5.8.8/Exporter/Heavy.pm |
Statements Executed | 1384 |
Statement Execution Time | 32.7ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
22 | 1 | 1 | 24.6ms | 28.5ms | heavy_export | Exporter::Heavy::
743 | 3 | 2 | 3.78ms | 3.78ms | CORE:subst (opcode) | Exporter::Heavy::
6 | 1 | 1 | 493µs | 493µs | _push_tags | Exporter::Heavy::
31 | 3 | 2 | 203µs | 203µs | CORE:match (opcode) | Exporter::Heavy::
6 | 1 | 1 | 201µs | 694µs | heavy_export_ok_tags | Exporter::Heavy::
1 | 1 | 1 | 63µs | 268µs | heavy_require_version | Exporter::Heavy::
0 | 0 | 0 | 0s | 0s | BEGIN | Exporter::Heavy::
0 | 0 | 0 | 0s | 0s | __ANON__[:53] | Exporter::Heavy::
0 | 0 | 0 | 0s | 0s | __ANON__[:59] | Exporter::Heavy::
0 | 0 | 0 | 0s | 0s | _rebuild_cache | Exporter::Heavy::
0 | 0 | 0 | 0s | 0s | heavy_export_tags | Exporter::Heavy::
0 | 0 | 0 | 0s | 0s | heavy_export_to_level | Exporter::Heavy::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Exporter::Heavy; | ||||
2 | |||||
3 | 3 | 92µs | 1 | 26µs | use strict; # spent 26µs making 1 call to strict::import |
4 | 3 | 2.96ms | 1 | 88µs | no strict 'refs'; # spent 88µs making 1 call to strict::unimport |
5 | |||||
6 | # On one line so MakeMaker will see it. | ||||
7 | 2 | 11µs | require Exporter; our $VERSION = $Exporter::VERSION; | ||
8 | 1 | 6µs | $Carp::Internal{"Exporter::Heavy"} = 1; | ||
9 | |||||
10 | =head1 NAME | ||||
11 | |||||
12 | Exporter::Heavy - Exporter guts | ||||
13 | |||||
14 | =head1 SYNOPSIS | ||||
15 | |||||
16 | (internal use only) | ||||
17 | |||||
18 | =head1 DESCRIPTION | ||||
19 | |||||
20 | No user-serviceable parts inside. | ||||
21 | |||||
22 | =cut | ||||
23 | |||||
24 | # | ||||
25 | # We go to a lot of trouble not to 'require Carp' at file scope, | ||||
26 | # because Carp requires Exporter, and something has to give. | ||||
27 | # | ||||
28 | |||||
29 | sub _rebuild_cache { | ||||
30 | my ($pkg, $exports, $cache) = @_; | ||||
31 | s/^&// foreach @$exports; | ||||
32 | @{$cache}{@$exports} = (1) x @$exports; | ||||
33 | my $ok = \@{"${pkg}::EXPORT_OK"}; | ||||
34 | if (@$ok) { | ||||
35 | s/^&// foreach @$ok; | ||||
36 | @{$cache}{@$ok} = (1) x @$ok; | ||||
37 | } | ||||
38 | } | ||||
39 | |||||
40 | # spent 28.5ms (24.6+3.98) within Exporter::Heavy::heavy_export which was called 22 times, avg 1.30ms/call:
# 22 times (24.6ms+3.98ms) by Exporter::import or FileHandle::import or IO::Socket::import at line 26 of Exporter.pm, avg 1.30ms/call | ||||
41 | |||||
42 | # First make import warnings look like they're coming from the "use". | ||||
43 | local $SIG{__WARN__} = sub { | ||||
44 | my $text = shift; | ||||
45 | if ($text =~ s/ at \S*Exporter\S*.pm line \d+.*\n//) { | ||||
46 | require Carp; | ||||
47 | local $Carp::CarpLevel = 1; # ignore package calling us too. | ||||
48 | Carp::carp($text); | ||||
49 | } | ||||
50 | else { | ||||
51 | warn $text; | ||||
52 | } | ||||
53 | 220 | 2.54ms | }; | ||
54 | local $SIG{__DIE__} = sub { | ||||
55 | require Carp; | ||||
56 | local $Carp::CarpLevel = 1; # ignore package calling us too. | ||||
57 | Carp::croak("$_[0]Illegal null symbol in \@${1}::EXPORT") | ||||
58 | if $_[0] =~ /^Unable to create sub named "(.*?)::"/; | ||||
59 | }; | ||||
60 | |||||
61 | my($pkg, $callpkg, @imports) = @_; | ||||
62 | my($type, $sym, $cache_is_current, $oops); | ||||
63 | my($exports, $export_cache) = (\@{"${pkg}::EXPORT"}, | ||||
64 | $Exporter::Cache{$pkg} ||= {}); | ||||
65 | |||||
66 | 66 | 1.26ms | if (@imports) { | ||
67 | if (!%$export_cache) { | ||||
68 | _rebuild_cache ($pkg, $exports, $export_cache); | ||||
69 | $cache_is_current = 1; | ||||
70 | } | ||||
71 | |||||
72 | 77 | 835µs | 16 | 103µs | if (grep m{^[/!:]}, @imports) { # spent 103µs making 16 calls to Exporter::Heavy::CORE:match, avg 6µs/call |
73 | my $tagsref = \%{"${pkg}::EXPORT_TAGS"}; | ||||
74 | my $tagdata; | ||||
75 | my %imports; | ||||
76 | my($remove, $spec, @names, @allexports); | ||||
77 | # negated first item implies starting with default set: | ||||
78 | unshift @imports, ':DEFAULT' if $imports[0] =~ m/^!/; # spent 78µs making 11 calls to Exporter::Heavy::CORE:match, avg 7µs/call | ||||
79 | foreach $spec (@imports){ | ||||
80 | 64 | 1.04ms | 16 | 74µs | $remove = $spec =~ s/^!//; # spent 74µs making 16 calls to Exporter::Heavy::CORE:subst, avg 5µs/call |
81 | |||||
82 | 16 | 298µs | 20 | 111µs | if ($spec =~ s/^://){ # spent 89µs making 16 calls to Exporter::Heavy::CORE:subst, avg 6µs/call
# spent 22µs making 4 calls to Exporter::Heavy::CORE:match, avg 6µs/call |
83 | if ($spec eq 'DEFAULT'){ | ||||
84 | @names = @$exports; | ||||
85 | } | ||||
86 | elsif ($tagdata = $tagsref->{$spec}) { | ||||
87 | @names = @$tagdata; | ||||
88 | } | ||||
89 | else { | ||||
90 | warn qq["$spec" is not defined in %${pkg}::EXPORT_TAGS]; | ||||
91 | ++$oops; | ||||
92 | next; | ||||
93 | } | ||||
94 | } | ||||
95 | elsif ($spec =~ m:^/(.*)/$:){ | ||||
96 | my $patn = $1; | ||||
97 | @allexports = keys %$export_cache unless @allexports; # only do keys once | ||||
98 | @names = grep(/$patn/, @allexports); # not anchored by default | ||||
99 | } | ||||
100 | else { | ||||
101 | @names = ($spec); # is a normal symbol name | ||||
102 | } | ||||
103 | |||||
104 | warn "Import ".($remove ? "del":"add").": @names " | ||||
105 | if $Exporter::Verbose; | ||||
106 | |||||
107 | 16 | 260µs | if ($remove) { | ||
108 | foreach $sym (@names) { delete $imports{$sym} } | ||||
109 | } | ||||
110 | else { | ||||
111 | @imports{@names} = (1) x @names; | ||||
112 | } | ||||
113 | } | ||||
114 | @imports = keys %imports; | ||||
115 | } | ||||
116 | |||||
117 | my @carp; | ||||
118 | foreach $sym (@imports) { | ||||
119 | 135 | 1.25ms | if (!$export_cache->{$sym}) { | ||
120 | if ($sym =~ m/^\d/) { | ||||
121 | $pkg->VERSION($sym); # inherit from UNIVERSAL | ||||
122 | # If the version number was the only thing specified | ||||
123 | # then we should act as if nothing was specified: | ||||
124 | if (@imports == 1) { | ||||
125 | @imports = @$exports; | ||||
126 | last; | ||||
127 | } | ||||
128 | # We need a way to emulate 'use Foo ()' but still | ||||
129 | # allow an easy version check: "use Foo 1.23, ''"; | ||||
130 | if (@imports == 2 and !$imports[1]) { | ||||
131 | @imports = (); | ||||
132 | last; | ||||
133 | } | ||||
134 | } elsif ($sym !~ s/^&// || !$export_cache->{$sym}) { | ||||
135 | # Last chance - see if they've updated EXPORT_OK since we | ||||
136 | # cached it. | ||||
137 | |||||
138 | unless ($cache_is_current) { | ||||
139 | %$export_cache = (); | ||||
140 | _rebuild_cache ($pkg, $exports, $export_cache); | ||||
141 | $cache_is_current = 1; | ||||
142 | } | ||||
143 | |||||
144 | if (!$export_cache->{$sym}) { | ||||
145 | # accumulate the non-exports | ||||
146 | push @carp, | ||||
147 | qq["$sym" is not exported by the $pkg module\n]; | ||||
148 | $oops++; | ||||
149 | } | ||||
150 | } | ||||
151 | } | ||||
152 | } | ||||
153 | if ($oops) { | ||||
154 | require Carp; | ||||
155 | Carp::croak("@{carp}Can't continue after import errors"); | ||||
156 | } | ||||
157 | } | ||||
158 | else { | ||||
159 | @imports = @$exports; | ||||
160 | } | ||||
161 | |||||
162 | my($fail, $fail_cache) = (\@{"${pkg}::EXPORT_FAIL"}, | ||||
163 | $Exporter::FailCache{$pkg} ||= {}); | ||||
164 | |||||
165 | if (@$fail) { | ||||
166 | if (!%$fail_cache) { | ||||
167 | # Build cache of symbols. Optimise the lookup by adding | ||||
168 | # barewords twice... both with and without a leading &. | ||||
169 | # (Technique could be applied to $export_cache at cost of memory) | ||||
170 | my @expanded = map { /^\w/ ? ($_, '&'.$_) : $_ } @$fail; | ||||
171 | warn "${pkg}::EXPORT_FAIL cached: @expanded" if $Exporter::Verbose; | ||||
172 | @{$fail_cache}{@expanded} = (1) x @expanded; | ||||
173 | } | ||||
174 | my @failed; | ||||
175 | foreach $sym (@imports) { push(@failed, $sym) if $fail_cache->{$sym} } | ||||
176 | if (@failed) { | ||||
177 | @failed = $pkg->export_fail(@failed); | ||||
178 | foreach $sym (@failed) { | ||||
179 | require Carp; | ||||
180 | Carp::carp(qq["$sym" is not implemented by the $pkg module ], | ||||
181 | "on this architecture"); | ||||
182 | } | ||||
183 | if (@failed) { | ||||
184 | require Carp; | ||||
185 | Carp::croak("Can't continue after import errors"); | ||||
186 | } | ||||
187 | } | ||||
188 | } | ||||
189 | |||||
190 | warn "Importing into $callpkg from $pkg: ", | ||||
191 | join(", ",sort @imports) if $Exporter::Verbose; | ||||
192 | |||||
193 | foreach $sym (@imports) { | ||||
194 | # shortcut for the common case of no type character | ||||
195 | 741 | 21.2ms | 711 | 3.61ms | (*{"${callpkg}::$sym"} = \&{"${pkg}::$sym"}, next) # spent 3.61ms making 711 calls to Exporter::Heavy::CORE:subst, avg 5µs/call |
196 | unless $sym =~ s/^(\W)//; | ||||
197 | $type = $1; | ||||
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 493µs within Exporter::Heavy::_push_tags which was called 6 times, avg 82µs/call:
# 6 times (493µs+0s) by Exporter::Heavy::heavy_export_ok_tags at line 245, avg 82µs/call | ||||
220 | 30 | 528µ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 | # spent 268µs (63+205) within Exporter::Heavy::heavy_require_version which was called
# once (63µs+205µs) by DBI::install_driver at line 92 of Exporter.pm | ||||
235 | 3 | 274µs | my($self, $wanted) = @_; | ||
236 | my $pkg = ref $self || $self; | ||||
237 | return ${pkg}->VERSION($wanted); # spent 205µs making 1 call to UNIVERSAL::VERSION | ||||
238 | } | ||||
239 | |||||
240 | sub heavy_export_tags { | ||||
241 | _push_tags((caller)[0], "EXPORT", \@_); | ||||
242 | } | ||||
243 | |||||
244 | # spent 694µs (201+493) within Exporter::Heavy::heavy_export_ok_tags which was called 6 times, avg 116µs/call:
# 6 times (201µs+493µs) by DBI::install_driver or Net::HTTP::Methods::zlib_ok or base::import at line 88 of Exporter.pm, avg 116µs/call | ||||
245 | 6 | 185µs | 6 | 493µs | _push_tags((caller)[0], "EXPORT_OK", \@_); # spent 493µs making 6 calls to Exporter::Heavy::_push_tags, avg 82µs/call |
246 | } | ||||
247 | |||||
248 | 1 | 15µs | 1; | ||
# spent 203µs within Exporter::Heavy::CORE:match which was called 31 times, avg 7µs/call:
# 16 times (103µs+0s) by Exporter::Heavy::heavy_export at line 72 of Exporter/Heavy.pm, avg 6µs/call
# 11 times (78µs+0s) by Exporter::Heavy::heavy_export at line 78 of Exporter/Heavy.pm, avg 7µs/call
# 4 times (22µs+0s) by Exporter::Heavy::heavy_export at line 82 of Exporter/Heavy.pm, avg 6µs/call | |||||
# spent 3.78ms within Exporter::Heavy::CORE:subst which was called 743 times, avg 5µs/call:
# 711 times (3.61ms+0s) by Exporter::Heavy::heavy_export at line 195 of Exporter/Heavy.pm, avg 5µs/call
# 16 times (89µs+0s) by Exporter::Heavy::heavy_export at line 82 of Exporter/Heavy.pm, avg 6µs/call
# 16 times (74µs+0s) by Exporter::Heavy::heavy_export at line 80 of Exporter/Heavy.pm, avg 5µs/call |