| Filename | /usr/share/perl5/Module/Implementation.pm |
| Statements | Executed 233 statements in 2.86ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 2.14ms | 2.25ms | Module::Implementation::BEGIN@8 |
| 1 | 1 | 1 | 1.70ms | 3.15ms | Module::Implementation::BEGIN@9 |
| 4 | 1 | 1 | 95µs | 106µs | Module::Implementation::_copy_symbols |
| 4 | 1 | 1 | 65µs | 9.40ms | Module::Implementation::_load_implementation |
| 4 | 1 | 1 | 48µs | 57µs | Module::Implementation::_build_loader |
| 4 | 4 | 4 | 34µs | 9.54ms | Module::Implementation::__ANON__[:52] |
| 22 | 2 | 1 | 20µs | 20µs | Module::Implementation::CORE:subst (opcode) |
| 1 | 1 | 1 | 20µs | 33µs | Module::Implementation::BEGIN@5 |
| 4 | 1 | 1 | 17µs | 9.23ms | Module::Implementation::try {...} |
| 4 | 4 | 4 | 16µs | 73µs | Module::Implementation::build_loader_sub |
| 1 | 1 | 1 | 8µs | 19µs | Module::Implementation::BEGIN@128 |
| 1 | 1 | 1 | 7µs | 12µs | Module::Implementation::BEGIN@6 |
| 1 | 1 | 1 | 7µs | 23µs | Module::Implementation::BEGIN@129 |
| 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 | 400ns | $Module::Implementation::VERSION = '0.09'; | ||
| 4 | |||||
| 5 | 2 | 34µs | 2 | 47µs | # spent 33µs (20+14) within Module::Implementation::BEGIN@5 which was called:
# once (20µs+14µs) by Params::Validate::BEGIN@9 at line 5 # spent 33µs making 1 call to Module::Implementation::BEGIN@5
# spent 14µs making 1 call to strict::import |
| 6 | 2 | 28µs | 2 | 16µs | # spent 12µs (7+4) within Module::Implementation::BEGIN@6 which was called:
# once (7µs+4µs) by Params::Validate::BEGIN@9 at line 6 # spent 12µs making 1 call to Module::Implementation::BEGIN@6
# spent 4µs making 1 call to warnings::import |
| 7 | |||||
| 8 | 3 | 834µs | 3 | 2.28ms | # spent 2.25ms (2.14+113µs) within Module::Implementation::BEGIN@8 which was called:
# once (2.14ms+113µs) by Params::Validate::BEGIN@9 at line 8 # spent 2.25ms making 1 call to Module::Implementation::BEGIN@8
# spent 13µs making 1 call to Module::Runtime::import
# spent 12µs making 1 call to UNIVERSAL::VERSION |
| 9 | 2 | 1.53ms | 2 | 3.18ms | # spent 3.15ms (1.70+1.45) within Module::Implementation::BEGIN@9 which was called:
# once (1.70ms+1.45ms) by Params::Validate::BEGIN@9 at line 9 # spent 3.15ms making 1 call to Module::Implementation::BEGIN@9
# spent 30µ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 | 900ns | unless ( exists $Module::Implementation::{VERSION} | ||
| 15 | && ${ $Module::Implementation::{VERSION} } ) { | ||||
| 16 | |||||
| 17 | $Module::Implementation::{VERSION} = \42; | ||||
| 18 | } | ||||
| 19 | |||||
| 20 | 1 | 100ns | my %Implementation; | ||
| 21 | |||||
| 22 | # spent 73µs (16+57) within Module::Implementation::build_loader_sub which was called 4 times, avg 18µs/call:
# once (4µs+17µs) by Package::Stash::BEGIN@15 at line 19 of Package/Stash.pm
# once (6µs+15µs) by DateTime::TimeZone::OffsetOnly::BEGIN@9 at line 48 of Params/Validate.pm
# once (4µs+13µs) by B::Hooks::EndOfScope::BEGIN@20 at line 22 of B/Hooks/EndOfScope.pm
# once (4µs+12µs) by DateTime::TimeZone::Local::BEGIN@6 at line 22 of Class/Load.pm | ||||
| 23 | 4 | 2µs | my $caller = caller(); | ||
| 24 | |||||
| 25 | 4 | 14µs | 4 | 57µs | return _build_loader( $caller, @_ ); # spent 57µs making 4 calls to Module::Implementation::_build_loader, avg 14µs/call |
| 26 | } | ||||
| 27 | |||||
| 28 | # spent 57µs (48+9) within Module::Implementation::_build_loader which was called 4 times, avg 14µs/call:
# 4 times (48µs+9µs) by Module::Implementation::build_loader_sub at line 25, avg 14µs/call | ||||
| 29 | 4 | 1µs | my $package = shift; | ||
| 30 | 4 | 4µs | my %args = @_; | ||
| 31 | |||||
| 32 | 4 | 3µs | my @implementations = @{ $args{implementations} }; | ||
| 33 | 4 | 3µs | my @symbols = @{ $args{symbols} || [] }; | ||
| 34 | |||||
| 35 | 4 | 200ns | my $implementation; | ||
| 36 | 4 | 3µs | my $env_var = uc $package; | ||
| 37 | 4 | 21µs | 4 | 9µs | $env_var =~ s/::/_/g; # spent 9µs making 4 calls to Module::Implementation::CORE:subst, avg 2µs/call |
| 38 | 4 | 2µs | $env_var .= '_IMPLEMENTATION'; | ||
| 39 | |||||
| 40 | # spent 9.54ms (34µs+9.50) within Module::Implementation::__ANON__[/usr/share/perl5/Module/Implementation.pm:52] which was called 4 times, avg 2.38ms/call:
# once (8µs+4.92ms) by B::Hooks::EndOfScope::BEGIN@20 at line 22 of B/Hooks/EndOfScope.pm
# once (10µs+2.22ms) by DateTime::TimeZone::OffsetOnly::BEGIN@9 at line 63 of Params/Validate.pm
# once (8µs+1.28ms) by Package::Stash::BEGIN@15 at line 19 of Package/Stash.pm
# once (7µs+1.08ms) by DateTime::TimeZone::Local::BEGIN@6 at line 27 of Class/Load.pm | ||||
| 41 | 4 | 10µs | 4 | 9.40ms | my ( $implementation, $loaded ) = _load_implementation( # spent 9.40ms making 4 calls to Module::Implementation::_load_implementation, avg 2.35ms/call |
| 42 | $package, | ||||
| 43 | $ENV{$env_var}, | ||||
| 44 | \@implementations, | ||||
| 45 | ); | ||||
| 46 | |||||
| 47 | 4 | 2µs | $Implementation{$package} = $implementation; | ||
| 48 | |||||
| 49 | 4 | 7µs | 4 | 106µs | _copy_symbols( $loaded, $package, \@symbols ); # spent 106µs making 4 calls to Module::Implementation::_copy_symbols, avg 26µs/call |
| 50 | |||||
| 51 | 4 | 11µs | return $loaded; | ||
| 52 | 4 | 25µs | }; | ||
| 53 | } | ||||
| 54 | |||||
| 55 | # spent 2µs within Module::Implementation::implementation_for which was called:
# once (2µs+0s) by Package::Stash::BEGIN@15 at line 35 of Package/Stash.pm | ||||
| 56 | 1 | 400ns | my $package = shift; | ||
| 57 | |||||
| 58 | 1 | 3µs | return $Implementation{$package}; | ||
| 59 | } | ||||
| 60 | |||||
| 61 | # spent 9.40ms (65µs+9.33) within Module::Implementation::_load_implementation which was called 4 times, avg 2.35ms/call:
# 4 times (65µs+9.33ms) by Module::Implementation::__ANON__[/usr/share/perl5/Module/Implementation.pm:52] at line 41, avg 2.35ms/call | ||||
| 62 | 4 | 900ns | my $package = shift; | ||
| 63 | 4 | 5µs | my $env_value = shift; | ||
| 64 | 4 | 500ns | my $implementations = shift; | ||
| 65 | |||||
| 66 | 4 | 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 | 4 | 500ns | my $err; | ||
| 88 | 4 | 2µs | for my $possible ( @{$implementations} ) { | ||
| 89 | 4 | 3µs | my $try = "${package}::$possible"; | ||
| 90 | |||||
| 91 | 4 | 400ns | my $ok; | ||
| 92 | # spent 9.23ms (17µs+9.21) within Module::Implementation::try {...} which was called 4 times, avg 2.31ms/call:
# 4 times (17µs+9.21ms) by Try::Tiny::try at line 81 of Try/Tiny.pm, avg 2.31ms/call | ||||
| 93 | 4 | 7µs | 4 | 9.21ms | require_module($try); # spent 9.21ms making 4 calls to Module::Runtime::require_module, avg 2.30ms/call |
| 94 | 4 | 7µs | $ok = 1; | ||
| 95 | } | ||||
| 96 | catch { | ||||
| 97 | $err .= $_ if defined $_; | ||||
| 98 | 4 | 37µs | 8 | 9.33ms | }; # spent 9.32ms making 4 calls to Try::Tiny::try, avg 2.33ms/call
# spent 14µs making 4 calls to Try::Tiny::catch, avg 3µs/call |
| 99 | |||||
| 100 | 4 | 12µ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 (95+11) within Module::Implementation::_copy_symbols which was called 4 times, avg 26µs/call:
# 4 times (95µs+11µs) by Module::Implementation::__ANON__[/usr/share/perl5/Module/Implementation.pm:52] at line 49, avg 26µs/call | ||||
| 117 | 4 | 1µs | my $from_package = shift; | ||
| 118 | 4 | 700ns | my $to_package = shift; | ||
| 119 | 4 | 700ns | my $symbols = shift; | ||
| 120 | |||||
| 121 | 4 | 11µs | for my $sym ( @{$symbols} ) { | ||
| 122 | 18 | 37µs | 18 | 11µs | my $type = $sym =~ s/^([\$\@\%\&\*])// ? $1 : '&'; # spent 11µs making 18 calls to Module::Implementation::CORE:subst, avg 617ns/call |
| 123 | |||||
| 124 | 18 | 8µs | my $from = "${from_package}::$sym"; | ||
| 125 | 18 | 4µs | my $to = "${to_package}::$sym"; | ||
| 126 | |||||
| 127 | { | ||||
| 128 | 20 | 38µs | 2 | 30µs | # spent 19µs (8+11) within Module::Implementation::BEGIN@128 which was called:
# once (8µs+11µs) by Params::Validate::BEGIN@9 at line 128 # spent 19µs making 1 call to Module::Implementation::BEGIN@128
# spent 11µs making 1 call to strict::unimport |
| 129 | 2 | 107µs | 2 | 39µs | # spent 23µs (7+16) within Module::Implementation::BEGIN@129 which was called:
# once (7µs+16µs) by Params::Validate::BEGIN@9 at line 129 # spent 23µs making 1 call to Module::Implementation::BEGIN@129
# spent 16µ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 | 18 | 35µ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 |