| Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Module/Implementation.pm |
| Statements | Executed 141 statements in 1.44ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 1.02ms | 1.24ms | Module::Implementation::BEGIN@9 |
| 2 | 1 | 1 | 94µs | 105µs | Module::Implementation::_copy_symbols |
| 2 | 1 | 1 | 48µs | 8.99ms | Module::Implementation::_load_implementation |
| 2 | 1 | 1 | 36µs | 45µs | Module::Implementation::_build_loader |
| 1 | 1 | 1 | 23µs | 26µs | Module::Implementation::BEGIN@5 |
| 2 | 2 | 2 | 23µs | 9.12ms | Module::Implementation::__ANON__[:52] |
| 14 | 2 | 1 | 20µs | 20µs | Module::Implementation::CORE:subst (opcode) |
| 1 | 1 | 1 | 16µs | 36µs | Module::Implementation::BEGIN@8 |
| 2 | 1 | 1 | 12µs | 8.86ms | Module::Implementation::try {...} |
| 1 | 1 | 1 | 11µs | 19µs | Module::Implementation::BEGIN@128 |
| 2 | 2 | 2 | 8µs | 53µs | Module::Implementation::build_loader_sub |
| 1 | 1 | 1 | 7µs | 26µs | Module::Implementation::BEGIN@129 |
| 1 | 1 | 1 | 5µs | 24µs | Module::Implementation::BEGIN@6 |
| 1 | 1 | 1 | 2µs | 2µs | Module::Implementation::implementation_for |
| 0 | 0 | 0 | 0s | 0s | Module::Implementation::__ANON__[:78] |
| 0 | 0 | 0 | 0s | 0s | Module::Implementation::__ANON__[:82] |
| 0 | 0 | 0 | 0s | 0s | Module::Implementation::__ANON__[:95] |
| 0 | 0 | 0 | 0s | 0s | Module::Implementation::__ANON__[:98] |
| 0 | 0 | 0 | 0s | 0s | Module::Implementation::catch {...} |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Module::Implementation; | ||||
| 2 | # git description: v0.08-2-gd599347 | ||||
| 3 | 1 | 1µs | $Module::Implementation::VERSION = '0.09'; | ||
| 4 | |||||
| 5 | 2 | 25µs | 2 | 29µs | # spent 26µs (23+3) within Module::Implementation::BEGIN@5 which was called:
# once (23µs+3µs) by B::Hooks::EndOfScope::BEGIN@13 at line 5 # spent 26µs making 1 call to Module::Implementation::BEGIN@5
# spent 3µs making 1 call to strict::import |
| 6 | 2 | 24µs | 2 | 43µs | # spent 24µs (5+19) within Module::Implementation::BEGIN@6 which was called:
# once (5µs+19µs) by B::Hooks::EndOfScope::BEGIN@13 at line 6 # spent 24µs making 1 call to Module::Implementation::BEGIN@6
# spent 19µs making 1 call to warnings::import |
| 7 | |||||
| 8 | 3 | 31µs | 3 | 56µs | # spent 36µs (16+20) within Module::Implementation::BEGIN@8 which was called:
# once (16µs+20µs) by B::Hooks::EndOfScope::BEGIN@13 at line 8 # spent 36µs making 1 call to Module::Implementation::BEGIN@8
# spent 14µs making 1 call to Module::Runtime::import
# spent 6µs making 1 call to UNIVERSAL::VERSION |
| 9 | 2 | 938µs | 2 | 1.29ms | # spent 1.24ms (1.02+216µs) within Module::Implementation::BEGIN@9 which was called:
# once (1.02ms+216µs) by B::Hooks::EndOfScope::BEGIN@13 at line 9 # spent 1.24ms making 1 call to Module::Implementation::BEGIN@9
# spent 54µs making 1 call to Exporter::import |
| 10 | |||||
| 11 | # This is needed for the benefit of Test::CleanNamespaces, which in turn loads | ||||
| 12 | # Package::Stash, which in turn loads this module and expects a minimum | ||||
| 13 | # version. | ||||
| 14 | 1 | 1µs | unless ( exists $Module::Implementation::{VERSION} | ||
| 15 | && ${ $Module::Implementation::{VERSION} } ) { | ||||
| 16 | |||||
| 17 | $Module::Implementation::{VERSION} = \42; | ||||
| 18 | } | ||||
| 19 | |||||
| 20 | 1 | 0s | my %Implementation; | ||
| 21 | |||||
| 22 | # spent 53µs (8+45) within Module::Implementation::build_loader_sub which was called 2 times, avg 26µs/call:
# once (4µs+26µs) by Package::Stash::BEGIN@12 at line 16 of Package/Stash.pm
# once (4µs+19µs) by B::Hooks::EndOfScope::BEGIN@12 at line 14 of B/Hooks/EndOfScope.pm | ||||
| 23 | 2 | 2µs | my $caller = caller(); | ||
| 24 | |||||
| 25 | 2 | 11µs | 2 | 45µs | return _build_loader( $caller, @_ ); # spent 45µs making 2 calls to Module::Implementation::_build_loader, avg 22µs/call |
| 26 | } | ||||
| 27 | |||||
| 28 | # spent 45µs (36+9) within Module::Implementation::_build_loader which was called 2 times, avg 22µs/call:
# 2 times (36µs+9µs) by Module::Implementation::build_loader_sub at line 25, avg 22µs/call | ||||
| 29 | 2 | 1µs | my $package = shift; | ||
| 30 | 2 | 7µs | my %args = @_; | ||
| 31 | |||||
| 32 | 2 | 4µs | my @implementations = @{ $args{implementations} }; | ||
| 33 | 2 | 2µs | my @symbols = @{ $args{symbols} || [] }; | ||
| 34 | |||||
| 35 | 2 | 0s | my $implementation; | ||
| 36 | 2 | 3µs | my $env_var = uc $package; | ||
| 37 | 2 | 16µs | 2 | 9µs | $env_var =~ s/::/_/g; # spent 9µs making 2 calls to Module::Implementation::CORE:subst, avg 4µs/call |
| 38 | 2 | 2µs | $env_var .= '_IMPLEMENTATION'; | ||
| 39 | |||||
| 40 | # spent 9.12ms (23µs+9.10) within Module::Implementation::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Module/Implementation.pm:52] which was called 2 times, avg 4.56ms/call:
# once (15µs+7.31ms) by B::Hooks::EndOfScope::BEGIN@12 at line 14 of B/Hooks/EndOfScope.pm
# once (8µs+1.79ms) by Package::Stash::BEGIN@12 at line 16 of Package/Stash.pm | ||||
| 41 | my ( $implementation, $loaded ) = _load_implementation( | ||||
| 42 | $package, | ||||
| 43 | 2 | 7µs | 2 | 8.99ms | $ENV{$env_var}, # spent 8.99ms making 2 calls to Module::Implementation::_load_implementation, avg 4.50ms/call |
| 44 | \@implementations, | ||||
| 45 | ); | ||||
| 46 | |||||
| 47 | 2 | 2µs | $Implementation{$package} = $implementation; | ||
| 48 | |||||
| 49 | 2 | 38µs | 2 | 105µs | _copy_symbols( $loaded, $package, \@symbols ); # spent 105µs making 2 calls to Module::Implementation::_copy_symbols, avg 52µs/call |
| 50 | |||||
| 51 | 2 | 7µs | return $loaded; | ||
| 52 | 2 | 11µs | }; | ||
| 53 | } | ||||
| 54 | |||||
| 55 | # spent 2µs within Module::Implementation::implementation_for which was called:
# once (2µs+0s) by Package::Stash::BEGIN@12 at line 32 of Package/Stash.pm | ||||
| 56 | 1 | 0s | my $package = shift; | ||
| 57 | |||||
| 58 | 1 | 3µs | return $Implementation{$package}; | ||
| 59 | } | ||||
| 60 | |||||
| 61 | # spent 8.99ms (48µs+8.95) within Module::Implementation::_load_implementation which was called 2 times, avg 4.50ms/call:
# 2 times (48µs+8.95ms) by Module::Implementation::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Module/Implementation.pm:52] at line 43, avg 4.50ms/call | ||||
| 62 | 2 | 0s | my $package = shift; | ||
| 63 | 2 | 2µs | my $env_value = shift; | ||
| 64 | 2 | 2µs | my $implementations = shift; | ||
| 65 | |||||
| 66 | 2 | 1µs | if ($env_value) { | ||
| 67 | die "$env_value is not a valid implementation for $package" | ||||
| 68 | unless grep { $_ eq $env_value } @{$implementations}; | ||||
| 69 | |||||
| 70 | my $requested = "${package}::$env_value"; | ||||
| 71 | |||||
| 72 | # Values from the %ENV hash are tainted. We know it's safe to untaint | ||||
| 73 | # this value because the value was one of our known implementations. | ||||
| 74 | ($requested) = $requested =~ /^(.+)$/; | ||||
| 75 | |||||
| 76 | try { | ||||
| 77 | require_module($requested); | ||||
| 78 | } | ||||
| 79 | catch { | ||||
| 80 | require Carp; | ||||
| 81 | Carp::croak("Could not load $requested: $_"); | ||||
| 82 | }; | ||||
| 83 | |||||
| 84 | return ( $env_value, $requested ); | ||||
| 85 | } | ||||
| 86 | else { | ||||
| 87 | 2 | 0s | my $err; | ||
| 88 | 2 | 2µs | for my $possible ( @{$implementations} ) { | ||
| 89 | 2 | 2µs | my $try = "${package}::$possible"; | ||
| 90 | |||||
| 91 | 2 | 1µs | my $ok; | ||
| 92 | # spent 8.86ms (12µs+8.85) within Module::Implementation::try {...} which was called 2 times, avg 4.43ms/call:
# 2 times (12µs+8.85ms) by Try::Tiny::try at line 102 of Try/Tiny.pm, avg 4.43ms/call | ||||
| 93 | 2 | 8µs | 2 | 8.85ms | require_module($try); # spent 8.85ms making 2 calls to Module::Runtime::require_module, avg 4.42ms/call |
| 94 | 2 | 8µs | $ok = 1; | ||
| 95 | } | ||||
| 96 | catch { | ||||
| 97 | $err .= $_ if defined $_; | ||||
| 98 | 2 | 28µs | 4 | 8.95ms | }; # spent 8.91ms making 2 calls to Try::Tiny::try, avg 4.46ms/call
# spent 34µs making 2 calls to Try::Tiny::catch, avg 17µs/call |
| 99 | |||||
| 100 | 2 | 8µs | return ( $possible, $try ) if $ok; | ||
| 101 | } | ||||
| 102 | |||||
| 103 | require Carp; | ||||
| 104 | if ( defined $err && length $err ) { | ||||
| 105 | Carp::croak( | ||||
| 106 | "Could not find a suitable $package implementation: $err"); | ||||
| 107 | } | ||||
| 108 | else { | ||||
| 109 | Carp::croak( | ||||
| 110 | 'Module::Runtime failed to load a module but did not throw a real error. This should never happen. Something is very broken' | ||||
| 111 | ); | ||||
| 112 | } | ||||
| 113 | } | ||||
| 114 | } | ||||
| 115 | |||||
| 116 | # spent 105µs (94+11) within Module::Implementation::_copy_symbols which was called 2 times, avg 52µs/call:
# 2 times (94µs+11µs) by Module::Implementation::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Module/Implementation.pm:52] at line 49, avg 52µs/call | ||||
| 117 | 2 | 1µs | my $from_package = shift; | ||
| 118 | 2 | 0s | my $to_package = shift; | ||
| 119 | 2 | 1µs | my $symbols = shift; | ||
| 120 | |||||
| 121 | 2 | 10µs | for my $sym ( @{$symbols} ) { | ||
| 122 | 12 | 25µs | 12 | 11µs | my $type = $sym =~ s/^([\$\@\%\&\*])// ? $1 : '&'; # spent 11µs making 12 calls to Module::Implementation::CORE:subst, avg 917ns/call |
| 123 | |||||
| 124 | 12 | 6µs | my $from = "${from_package}::$sym"; | ||
| 125 | 12 | 3µs | my $to = "${to_package}::$sym"; | ||
| 126 | |||||
| 127 | { | ||||
| 128 | 14 | 42µs | 2 | 27µs | # spent 19µs (11+8) within Module::Implementation::BEGIN@128 which was called:
# once (11µs+8µs) by B::Hooks::EndOfScope::BEGIN@13 at line 128 # spent 19µs making 1 call to Module::Implementation::BEGIN@128
# spent 8µs making 1 call to strict::unimport |
| 129 | 2 | 123µs | 2 | 45µs | # spent 26µs (7+19) within Module::Implementation::BEGIN@129 which was called:
# once (7µs+19µs) by B::Hooks::EndOfScope::BEGIN@13 at line 129 # spent 26µs making 1 call to Module::Implementation::BEGIN@129
# spent 19µs making 1 call to warnings::unimport |
| 130 | |||||
| 131 | # Copied from Exporter | ||||
| 132 | *{$to} | ||||
| 133 | = $type eq '&' ? \&{$from} | ||||
| 134 | : $type eq '$' ? \${$from} | ||||
| 135 | : $type eq '@' ? \@{$from} | ||||
| 136 | : $type eq '%' ? \%{$from} | ||||
| 137 | 12 | 25µs | : $type eq '*' ? *{$from} | ||
| 138 | : die | ||||
| 139 | "Can't copy symbol from $from_package to $to_package: $type$sym"; | ||||
| 140 | } | ||||
| 141 | } | ||||
| 142 | } | ||||
| 143 | |||||
| 144 | 1 | 4µs | 1; | ||
| 145 | |||||
| 146 | # ABSTRACT: Loads one of several alternate underlying implementations for a module | ||||
| 147 | |||||
| 148 | __END__ | ||||
sub Module::Implementation::CORE:subst; # opcode |