| Filename | /usr/local/share/perl/5.18.2/Module/Implementation.pm |
| Statements | Executed 141 statements in 1.55ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 1.07ms | 3.65ms | Module::Implementation::BEGIN@9 |
| 2 | 1 | 1 | 97µs | 106µs | Module::Implementation::_copy_symbols |
| 2 | 1 | 1 | 54µs | 4.26ms | Module::Implementation::_load_implementation |
| 2 | 1 | 1 | 42µs | 51µs | Module::Implementation::_build_loader |
| 2 | 2 | 2 | 29µs | 4.39ms | Module::Implementation::__ANON__[:52] |
| 14 | 2 | 1 | 18µs | 18µs | Module::Implementation::CORE:subst (opcode) |
| 1 | 1 | 1 | 18µs | 34µs | Module::Implementation::BEGIN@5 |
| 1 | 1 | 1 | 17µs | 48µs | Module::Implementation::BEGIN@8 |
| 2 | 2 | 2 | 12µs | 63µs | Module::Implementation::build_loader_sub |
| 2 | 1 | 1 | 12µs | 4.10ms | Module::Implementation::try {...} |
| 1 | 1 | 1 | 11µs | 25µs | Module::Implementation::BEGIN@129 |
| 1 | 1 | 1 | 10µs | 27µs | Module::Implementation::BEGIN@128 |
| 1 | 1 | 1 | 9µs | 14µs | Module::Implementation::BEGIN@6 |
| 1 | 1 | 1 | 3µs | 3µ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 | 700ns | $Module::Implementation::VERSION = '0.09'; | ||
| 4 | |||||
| 5 | 2 | 31µs | 2 | 51µs | # spent 34µs (18+17) within Module::Implementation::BEGIN@5 which was called:
# once (18µs+17µs) by B::Hooks::EndOfScope::BEGIN@16 at line 5 # spent 34µs making 1 call to Module::Implementation::BEGIN@5
# spent 17µs making 1 call to strict::import |
| 6 | 2 | 34µs | 2 | 19µs | # spent 14µs (9+5) within Module::Implementation::BEGIN@6 which was called:
# once (9µs+5µs) by B::Hooks::EndOfScope::BEGIN@16 at line 6 # spent 14µs making 1 call to Module::Implementation::BEGIN@6
# spent 5µs making 1 call to warnings::import |
| 7 | |||||
| 8 | 3 | 55µs | 3 | 78µs | # spent 48µs (17+30) within Module::Implementation::BEGIN@8 which was called:
# once (17µs+30µs) by B::Hooks::EndOfScope::BEGIN@16 at line 8 # spent 48µs making 1 call to Module::Implementation::BEGIN@8
# spent 16µs making 1 call to Module::Runtime::import
# spent 14µs making 1 call to UNIVERSAL::VERSION |
| 9 | 2 | 990µs | 2 | 3.70ms | # spent 3.65ms (1.07+2.58) within Module::Implementation::BEGIN@9 which was called:
# once (1.07ms+2.58ms) by B::Hooks::EndOfScope::BEGIN@16 at line 9 # spent 3.65ms making 1 call to Module::Implementation::BEGIN@9
# spent 45µ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 | 2µs | unless ( exists $Module::Implementation::{VERSION} | ||
| 15 | && ${ $Module::Implementation::{VERSION} } ) { | ||||
| 16 | |||||
| 17 | $Module::Implementation::{VERSION} = \42; | ||||
| 18 | } | ||||
| 19 | |||||
| 20 | 1 | 300ns | my %Implementation; | ||
| 21 | |||||
| 22 | # spent 63µs (12+51) within Module::Implementation::build_loader_sub which was called 2 times, avg 32µs/call:
# once (7µs+30µs) by B::Hooks::EndOfScope::BEGIN@15 at line 17 of B/Hooks/EndOfScope.pm
# once (5µs+22µs) by Package::Stash::BEGIN@15 at line 19 of Package/Stash.pm | ||||
| 23 | 2 | 2µs | my $caller = caller(); | ||
| 24 | |||||
| 25 | 2 | 11µs | 2 | 51µs | return _build_loader( $caller, @_ ); # spent 51µs making 2 calls to Module::Implementation::_build_loader, avg 26µs/call |
| 26 | } | ||||
| 27 | |||||
| 28 | # spent 51µs (42+9) within Module::Implementation::_build_loader which was called 2 times, avg 26µs/call:
# 2 times (42µs+9µs) by Module::Implementation::build_loader_sub at line 25, avg 26µs/call | ||||
| 29 | 2 | 1µs | my $package = shift; | ||
| 30 | 2 | 4µs | my %args = @_; | ||
| 31 | |||||
| 32 | 2 | 3µs | my @implementations = @{ $args{implementations} }; | ||
| 33 | 2 | 3µs | my @symbols = @{ $args{symbols} || [] }; | ||
| 34 | |||||
| 35 | 2 | 400ns | my $implementation; | ||
| 36 | 2 | 6µs | my $env_var = uc $package; | ||
| 37 | 2 | 20µs | 2 | 9µs | $env_var =~ s/::/_/g; # spent 9µs making 2 calls to Module::Implementation::CORE:subst, avg 5µs/call |
| 38 | 2 | 1µs | $env_var .= '_IMPLEMENTATION'; | ||
| 39 | |||||
| 40 | # spent 4.39ms (29µs+4.36) within Module::Implementation::__ANON__[/usr/local/share/perl/5.18.2/Module/Implementation.pm:52] which was called 2 times, avg 2.20ms/call:
# once (17µs+3.55ms) by B::Hooks::EndOfScope::BEGIN@15 at line 17 of B/Hooks/EndOfScope.pm
# once (12µs+809µs) by Package::Stash::BEGIN@15 at line 19 of Package/Stash.pm | ||||
| 41 | 2 | 10µs | 2 | 4.26ms | my ( $implementation, $loaded ) = _load_implementation( # spent 4.26ms making 2 calls to Module::Implementation::_load_implementation, avg 2.13ms/call |
| 42 | $package, | ||||
| 43 | $ENV{$env_var}, | ||||
| 44 | \@implementations, | ||||
| 45 | ); | ||||
| 46 | |||||
| 47 | 2 | 2µs | $Implementation{$package} = $implementation; | ||
| 48 | |||||
| 49 | 2 | 5µs | 2 | 106µs | _copy_symbols( $loaded, $package, \@symbols ); # spent 106µs making 2 calls to Module::Implementation::_copy_symbols, avg 53µs/call |
| 50 | |||||
| 51 | 2 | 7µs | return $loaded; | ||
| 52 | 2 | 16µs | }; | ||
| 53 | } | ||||
| 54 | |||||
| 55 | # spent 3µs within Module::Implementation::implementation_for which was called:
# once (3µs+0s) by Package::Stash::BEGIN@15 at line 35 of Package/Stash.pm | ||||
| 56 | 1 | 400ns | my $package = shift; | ||
| 57 | |||||
| 58 | 1 | 4µs | return $Implementation{$package}; | ||
| 59 | } | ||||
| 60 | |||||
| 61 | # spent 4.26ms (54µs+4.20) within Module::Implementation::_load_implementation which was called 2 times, avg 2.13ms/call:
# 2 times (54µs+4.20ms) by Module::Implementation::__ANON__[/usr/local/share/perl/5.18.2/Module/Implementation.pm:52] at line 41, avg 2.13ms/call | ||||
| 62 | 2 | 900ns | my $package = shift; | ||
| 63 | 2 | 2µs | my $env_value = shift; | ||
| 64 | 2 | 400ns | my $implementations = shift; | ||
| 65 | |||||
| 66 | 2 | 900ns | 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 | 500ns | my $err; | ||
| 88 | 2 | 2µs | for my $possible ( @{$implementations} ) { | ||
| 89 | 2 | 2µs | my $try = "${package}::$possible"; | ||
| 90 | |||||
| 91 | 2 | 300ns | my $ok; | ||
| 92 | # spent 4.10ms (12µs+4.09) within Module::Implementation::try {...} which was called 2 times, avg 2.05ms/call:
# 2 times (12µs+4.09ms) by Try::Tiny::try at line 81 of Try/Tiny.pm, avg 2.05ms/call | ||||
| 93 | 2 | 5µs | 2 | 4.09ms | require_module($try); # spent 4.09ms making 2 calls to Module::Runtime::require_module, avg 2.04ms/call |
| 94 | 2 | 6µs | $ok = 1; | ||
| 95 | } | ||||
| 96 | catch { | ||||
| 97 | $err .= $_ if defined $_; | ||||
| 98 | 2 | 31µs | 4 | 4.20ms | }; # spent 4.19ms making 2 calls to Try::Tiny::try, avg 2.10ms/call
# spent 12µs making 2 calls to Try::Tiny::catch, avg 6µs/call |
| 99 | |||||
| 100 | 2 | 11µ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 106µs (97+9) within Module::Implementation::_copy_symbols which was called 2 times, avg 53µs/call:
# 2 times (97µs+9µs) by Module::Implementation::__ANON__[/usr/local/share/perl/5.18.2/Module/Implementation.pm:52] at line 49, avg 53µs/call | ||||
| 117 | 2 | 1µs | my $from_package = shift; | ||
| 118 | 2 | 500ns | my $to_package = shift; | ||
| 119 | 2 | 500ns | my $symbols = shift; | ||
| 120 | |||||
| 121 | 2 | 9µs | for my $sym ( @{$symbols} ) { | ||
| 122 | 12 | 38µs | 12 | 9µs | my $type = $sym =~ s/^([\$\@\%\&\*])// ? $1 : '&'; # spent 9µs making 12 calls to Module::Implementation::CORE:subst, avg 758ns/call |
| 123 | |||||
| 124 | 12 | 6µs | my $from = "${from_package}::$sym"; | ||
| 125 | 12 | 5µs | my $to = "${to_package}::$sym"; | ||
| 126 | |||||
| 127 | { | ||||
| 128 | 14 | 47µs | 2 | 44µs | # spent 27µs (10+17) within Module::Implementation::BEGIN@128 which was called:
# once (10µs+17µs) by B::Hooks::EndOfScope::BEGIN@16 at line 128 # spent 27µs making 1 call to Module::Implementation::BEGIN@128
# spent 17µs making 1 call to strict::unimport |
| 129 | 2 | 132µs | 2 | 39µs | # spent 25µs (11+14) within Module::Implementation::BEGIN@129 which was called:
# once (11µs+14µs) by B::Hooks::EndOfScope::BEGIN@16 at line 129 # spent 25µs making 1 call to Module::Implementation::BEGIN@129
# spent 14µ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 | 38µ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 | 5µs | 1; | ||
| 145 | |||||
| 146 | # ABSTRACT: Loads one of several alternate underlying implementations for a module | ||||
| 147 | |||||
| 148 | __END__ | ||||
sub Module::Implementation::CORE:subst; # opcode |