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