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