File | /opt/wise/lib/perl5/5.10.0/Exporter/Heavy.pm | Statements Executed | 4001 | Total Time | 0.017172 seconds |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine | |
---|---|---|---|---|---|---|
5 | 1 | 1 | 0.00015 | 0.00015 | Exporter::Heavy:: | _push_tags |
1 | 1 | 1 | 7.8e-5 | 7.8e-5 | Exporter::Heavy:: | _rebuild_cache |
0 | 0 | 0 | 0 | 0 | Exporter::Heavy:: | BEGIN |
0 | 0 | 0 | 0 | 0 | Exporter::Heavy:: | __ANON__[:54] |
0 | 0 | 0 | 0 | 0 | Exporter::Heavy:: | __ANON__[:60] |
0 | 0 | 0 | 0 | 0 | Exporter::Heavy:: | heavy_export |
0 | 0 | 0 | 0 | 0 | Exporter::Heavy:: | heavy_export_ok_tags |
0 | 0 | 0 | 0 | 0 | Exporter::Heavy:: | heavy_export_tags |
0 | 0 | 0 | 0 | 0 | Exporter::Heavy:: | heavy_export_to_level |
0 | 0 | 0 | 0 | 0 | Exporter::Heavy:: | heavy_require_version |
Line | Stmts. | Exclusive Time | Avg. | Code |
---|---|---|---|---|
1 | package Exporter::Heavy; | |||
2 | ||||
3 | 3 | 3.2e-5 | 1.1e-5 | use strict; # spent 11µs making 1 call to strict::import |
4 | 3 | 0.00116 | 0.00039 | no strict 'refs'; # spent 23µs making 1 call to strict::unimport |
5 | ||||
6 | # On one line so MakeMaker will see it. | |||
7 | 2 | 1.0e-5 | 5.0e-6 | require Exporter; our $VERSION = $Exporter::VERSION; |
8 | # Carp does this now for us, so we can finally live w/o Carp | |||
9 | #$Carp::Internal{"Exporter::Heavy"} = 1; | |||
10 | ||||
11 | =head1 NAME | |||
12 | ||||
13 | Exporter::Heavy - Exporter guts | |||
14 | ||||
15 | =head1 SYNOPSIS | |||
16 | ||||
17 | (internal use only) | |||
18 | ||||
19 | =head1 DESCRIPTION | |||
20 | ||||
21 | No user-serviceable parts inside. | |||
22 | ||||
23 | =cut | |||
24 | ||||
25 | # | |||
26 | # We go to a lot of trouble not to 'require Carp' at file scope, | |||
27 | # because Carp requires Exporter, and something has to give. | |||
28 | # | |||
29 | ||||
30 | # spent 78µs within Exporter::Heavy::_rebuild_cache which was called
# once (78µs+0) by Exporter::Heavy::heavy_export at line 69 | |||
31 | 1 | 4.0e-6 | 4.0e-6 | my ($pkg, $exports, $cache) = @_; |
32 | 2 | 3.0e-6 | 1.5e-6 | s/^&// foreach @$exports; |
33 | 1 | 3.0e-6 | 3.0e-6 | @{$cache}{@$exports} = (1) x @$exports; |
34 | 1 | 3.0e-6 | 3.0e-6 | my $ok = \@{"${pkg}::EXPORT_OK"}; |
35 | 1 | 3.0e-6 | 3.0e-6 | if (@$ok) { |
36 | 2 | 2.4e-5 | 1.2e-5 | s/^&// foreach @$ok; |
37 | 1 | 3.2e-5 | 3.2e-5 | @{$cache}{@$ok} = (1) x @$ok; |
38 | } | |||
39 | } | |||
40 | ||||
41 | sub heavy_export { | |||
42 | ||||
43 | # First make import warnings look like they're coming from the "use". | |||
44 | local $SIG{__WARN__} = sub { | |||
45 | my $text = shift; | |||
46 | if ($text =~ s/ at \S*Exporter\S*.pm line \d+.*\n//) { | |||
47 | require Carp; | |||
48 | local $Carp::CarpLevel = 1; # ignore package calling us too. | |||
49 | Carp::carp($text); | |||
50 | } | |||
51 | else { | |||
52 | warn $text; | |||
53 | } | |||
54 | 35 | 0.00029 | 8.1e-6 | }; |
55 | local $SIG{__DIE__} = sub { | |||
56 | require Carp; | |||
57 | local $Carp::CarpLevel = 1; # ignore package calling us too. | |||
58 | Carp::croak("$_[0]Illegal null symbol in \@${1}::EXPORT") | |||
59 | if $_[0] =~ /^Unable to create sub named "(.*?)::"/; | |||
60 | 35 | 0.00023 | 6.7e-6 | }; |
61 | ||||
62 | 35 | 0.00010 | 2.9e-6 | my($pkg, $callpkg, @imports) = @_; |
63 | 35 | 2.7e-5 | 7.7e-7 | my($type, $sym, $cache_is_current, $oops); |
64 | 35 | 0.00013 | 3.7e-6 | my($exports, $export_cache) = (\@{"${pkg}::EXPORT"}, |
65 | $Exporter::Cache{$pkg} ||= {}); | |||
66 | ||||
67 | 35 | 6.6e-5 | 1.9e-6 | if (@imports) { |
68 | 24 | 5.4e-5 | 2.3e-6 | if (!%$export_cache) { |
69 | 1 | 9.0e-6 | 9.0e-6 | _rebuild_cache ($pkg, $exports, $export_cache); # spent 78µs making 1 call to Exporter::Heavy::_rebuild_cache |
70 | 1 | 1.0e-6 | 1.0e-6 | $cache_is_current = 1; |
71 | } | |||
72 | ||||
73 | 24 | 0.00017 | 7.0e-6 | if (grep m{^[/!:]}, @imports) { |
74 | 21 | 5.4e-5 | 2.6e-6 | my $tagsref = \%{"${pkg}::EXPORT_TAGS"}; |
75 | 21 | 1.1e-5 | 5.2e-7 | my $tagdata; |
76 | 21 | 1.2e-5 | 5.7e-7 | my %imports; |
77 | 21 | 1.7e-5 | 8.1e-7 | my($remove, $spec, @names, @allexports); |
78 | # negated first item implies starting with default set: | |||
79 | 21 | 3.9e-5 | 1.9e-6 | unshift @imports, ':DEFAULT' if $imports[0] =~ m/^!/; |
80 | 21 | 3.4e-5 | 1.6e-6 | foreach $spec (@imports){ |
81 | 35 | 3.8e-5 | 1.1e-6 | $remove = $spec =~ s/^!//; |
82 | ||||
83 | 35 | 0.00017 | 4.9e-6 | if ($spec =~ s/^://){ |
84 | 26 | 0.00069 | 2.7e-5 | if ($spec eq 'DEFAULT'){ |
85 | @names = @$exports; | |||
86 | } | |||
87 | elsif ($tagdata = $tagsref->{$spec}) { | |||
88 | @names = @$tagdata; | |||
89 | } | |||
90 | else { | |||
91 | warn qq["$spec" is not defined in %${pkg}::EXPORT_TAGS]; | |||
92 | ++$oops; | |||
93 | next; | |||
94 | } | |||
95 | } | |||
96 | elsif ($spec =~ m:^/(.*)/$:){ | |||
97 | 1 | 4.0e-6 | 4.0e-6 | my $patn = $1; |
98 | 1 | 6.0e-6 | 6.0e-6 | @allexports = keys %$export_cache unless @allexports; # only do keys once |
99 | 1 | 1.6e-5 | 1.6e-5 | @names = grep(/$patn/, @allexports); # not anchored by default |
100 | } | |||
101 | else { | |||
102 | 8 | 1.1e-5 | 1.4e-6 | @names = ($spec); # is a normal symbol name |
103 | } | |||
104 | ||||
105 | 35 | 1.9e-5 | 5.4e-7 | warn "Import ".($remove ? "del":"add").": @names " |
106 | if $Exporter::Verbose; | |||
107 | ||||
108 | 35 | 9.8e-5 | 2.8e-6 | if ($remove) { |
109 | foreach $sym (@names) { delete $imports{$sym} } | |||
110 | } | |||
111 | else { | |||
112 | 35 | 0.00056 | 1.6e-5 | @imports{@names} = (1) x @names; |
113 | } | |||
114 | } | |||
115 | 21 | 0.00055 | 2.6e-5 | @imports = keys %imports; |
116 | } | |||
117 | ||||
118 | 24 | 1.6e-5 | 6.7e-7 | my @carp; |
119 | 24 | 3.3e-5 | 1.4e-6 | foreach $sym (@imports) { |
120 | 1363 | 0.00159 | 1.2e-6 | if (!$export_cache->{$sym}) { |
121 | if ($sym =~ m/^\d/) { | |||
122 | $pkg->VERSION($sym); # inherit from UNIVERSAL | |||
123 | # If the version number was the only thing specified | |||
124 | # then we should act as if nothing was specified: | |||
125 | if (@imports == 1) { | |||
126 | @imports = @$exports; | |||
127 | last; | |||
128 | } | |||
129 | # We need a way to emulate 'use Foo ()' but still | |||
130 | # allow an easy version check: "use Foo 1.23, ''"; | |||
131 | if (@imports == 2 and !$imports[1]) { | |||
132 | @imports = (); | |||
133 | last; | |||
134 | } | |||
135 | } elsif ($sym !~ s/^&// || !$export_cache->{$sym}) { | |||
136 | # Last chance - see if they've updated EXPORT_OK since we | |||
137 | # cached it. | |||
138 | ||||
139 | unless ($cache_is_current) { | |||
140 | %$export_cache = (); | |||
141 | _rebuild_cache ($pkg, $exports, $export_cache); | |||
142 | $cache_is_current = 1; | |||
143 | } | |||
144 | ||||
145 | if (!$export_cache->{$sym}) { | |||
146 | # accumulate the non-exports | |||
147 | push @carp, | |||
148 | qq["$sym" is not exported by the $pkg module\n]; | |||
149 | $oops++; | |||
150 | } | |||
151 | } | |||
152 | } | |||
153 | } | |||
154 | 24 | 1.8e-5 | 7.5e-7 | if ($oops) { |
155 | require Carp; | |||
156 | Carp::croak("@{carp}Can't continue after import errors"); | |||
157 | } | |||
158 | } | |||
159 | else { | |||
160 | 11 | 0.00016 | 1.5e-5 | @imports = @$exports; |
161 | } | |||
162 | ||||
163 | 35 | 0.00013 | 3.7e-6 | my($fail, $fail_cache) = (\@{"${pkg}::EXPORT_FAIL"}, |
164 | $Exporter::FailCache{$pkg} ||= {}); | |||
165 | ||||
166 | 35 | 3.4e-5 | 9.7e-7 | if (@$fail) { |
167 | 3 | 2.0e-6 | 6.7e-7 | if (!%$fail_cache) { |
168 | # Build cache of symbols. Optimise the lookup by adding | |||
169 | # barewords twice... both with and without a leading &. | |||
170 | # (Technique could be applied to $export_cache at cost of memory) | |||
171 | 4 | 1.3e-5 | 3.2e-6 | my @expanded = map { /^\w/ ? ($_, '&'.$_) : $_ } @$fail; |
172 | 2 | 2.0e-6 | 1.0e-6 | warn "${pkg}::EXPORT_FAIL cached: @expanded" if $Exporter::Verbose; |
173 | 2 | 7.0e-6 | 3.5e-6 | @{$fail_cache}{@expanded} = (1) x @expanded; |
174 | } | |||
175 | 3 | 3.0e-6 | 1.0e-6 | my @failed; |
176 | 15 | 3.2e-5 | 2.1e-6 | foreach $sym (@imports) { push(@failed, $sym) if $fail_cache->{$sym} } |
177 | 3 | 3.0e-6 | 1.0e-6 | if (@failed) { |
178 | @failed = $pkg->export_fail(@failed); | |||
179 | foreach $sym (@failed) { | |||
180 | require Carp; | |||
181 | Carp::carp(qq["$sym" is not implemented by the $pkg module ], | |||
182 | "on this architecture"); | |||
183 | } | |||
184 | if (@failed) { | |||
185 | require Carp; | |||
186 | Carp::croak("Can't continue after import errors"); | |||
187 | } | |||
188 | } | |||
189 | } | |||
190 | ||||
191 | 35 | 1.8e-5 | 5.1e-7 | warn "Importing into $callpkg from $pkg: ", |
192 | join(", ",sort @imports) if $Exporter::Verbose; | |||
193 | ||||
194 | 35 | 0.00125 | 3.6e-5 | foreach $sym (@imports) { |
195 | # shortcut for the common case of no type character | |||
196 | 1671 | 0.00832 | 5.0e-6 | (*{"${callpkg}::$sym"} = \&{"${pkg}::$sym"}, next) |
197 | unless $sym =~ s/^(\W)//; | |||
198 | 16 | 3.3e-5 | 2.1e-6 | $type = $1; |
199 | 3 | 0.00049 | 0.00016 | no warnings 'once'; # spent 22µs making 1 call to warnings::unimport |
200 | *{"${callpkg}::$sym"} = | |||
201 | $type eq '&' ? \&{"${pkg}::$sym"} : | |||
202 | $type eq '$' ? \${"${pkg}::$sym"} : | |||
203 | $type eq '@' ? \@{"${pkg}::$sym"} : | |||
204 | $type eq '%' ? \%{"${pkg}::$sym"} : | |||
205 | $type eq '*' ? *{"${pkg}::$sym"} : | |||
206 | 16 | 0.00012 | 7.5e-6 | do { require Carp; Carp::croak("Can't export symbol: $type$sym") }; |
207 | } | |||
208 | } | |||
209 | ||||
210 | sub heavy_export_to_level | |||
211 | { | |||
212 | 2 | 5.0e-6 | 2.5e-6 | my $pkg = shift; |
213 | 2 | 6.0e-6 | 3.0e-6 | my $level = shift; |
214 | 2 | 3.0e-6 | 1.5e-6 | (undef) = shift; # XXX redundant arg |
215 | 2 | 5.0e-6 | 2.5e-6 | my $callpkg = caller($level); |
216 | 2 | 1.6e-5 | 8.0e-6 | $pkg->export($callpkg, @_); # spent 44µs making 2 calls to Exporter::export, avg 22µs/call |
217 | } | |||
218 | ||||
219 | # Utility functions | |||
220 | ||||
221 | # spent 150µs within Exporter::Heavy::_push_tags which was called 5 times, avg 30µs/call:
# 5 times (150µs+0) by Exporter::Heavy::heavy_export_ok_tags at line 247, avg 30µs/call | |||
222 | 5 | 1.5e-5 | 3.0e-6 | my($pkg, $var, $syms) = @_; |
223 | 5 | 3.0e-6 | 6.0e-7 | my @nontag = (); |
224 | 5 | 1.3e-5 | 2.6e-6 | my $export_tags = \%{"${pkg}::EXPORT_TAGS"}; |
225 | push(@{"${pkg}::$var"}, | |||
226 | 5 | 7.6e-5 | 1.5e-5 | map { $export_tags->{$_} ? @{$export_tags->{$_}} |
227 | : scalar(push(@nontag,$_),$_) } | |||
228 | (@$syms) ? @$syms : keys %$export_tags); | |||
229 | 5 | 1.0e-5 | 2.0e-6 | if (@nontag and $^W) { |
230 | # This may change to a die one day | |||
231 | require Carp; | |||
232 | Carp::carp(join(", ", @nontag)." are not tags of $pkg"); | |||
233 | } | |||
234 | } | |||
235 | ||||
236 | sub heavy_require_version { | |||
237 | my($self, $wanted) = @_; | |||
238 | my $pkg = ref $self || $self; | |||
239 | return ${pkg}->VERSION($wanted); | |||
240 | } | |||
241 | ||||
242 | sub heavy_export_tags { | |||
243 | _push_tags((caller)[0], "EXPORT", \@_); | |||
244 | } | |||
245 | ||||
246 | sub heavy_export_ok_tags { | |||
247 | 5 | 5.5e-5 | 1.1e-5 | _push_tags((caller)[0], "EXPORT_OK", \@_); # spent 150µs making 5 calls to Exporter::Heavy::_push_tags, avg 30µs/call |
248 | } | |||
249 | ||||
250 | 1 | 4.0e-6 | 4.0e-6 | 1; |