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