| Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Module/Implementation.pm |
| Statements | Executed 177 statements in 830µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 600µs | 1.01ms | Module::Implementation::BEGIN@9 |
| 3 | 1 | 1 | 61µs | 64µs | Module::Implementation::_copy_symbols |
| 3 | 1 | 1 | 48µs | 2.01ms | Module::Implementation::_load_implementation |
| 3 | 1 | 1 | 39µs | 44µs | Module::Implementation::_build_loader |
| 3 | 3 | 3 | 27µs | 2.11ms | Module::Implementation::__ANON__[:52] |
| 3 | 3 | 3 | 15µs | 59µs | Module::Implementation::build_loader_sub |
| 3 | 1 | 1 | 12µs | 1.86ms | Module::Implementation::try {...} |
| 1 | 1 | 1 | 11µs | 13µs | Module::Implementation::BEGIN@5 |
| 1 | 1 | 1 | 10µs | 32µs | Module::Implementation::BEGIN@8 |
| 16 | 2 | 1 | 9µs | 9µs | Module::Implementation::CORE:subst (opcode) |
| 1 | 1 | 1 | 7µs | 25µs | Module::Implementation::BEGIN@129 |
| 1 | 1 | 1 | 6µs | 22µs | Module::Implementation::BEGIN@128 |
| 1 | 1 | 1 | 6µs | 14µ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 | 400ns | $Module::Implementation::VERSION = '0.09'; | ||
| 4 | |||||
| 5 | 2 | 51µs | 2 | 16µs | # spent 13µs (11+3) within Module::Implementation::BEGIN@5 which was called:
# once (11µs+3µs) by Class::Load::BEGIN@11 at line 5 # spent 13µs making 1 call to Module::Implementation::BEGIN@5
# spent 3µs making 1 call to strict::import |
| 6 | 2 | 18µs | 2 | 23µs | # spent 14µs (6+8) within Module::Implementation::BEGIN@6 which was called:
# once (6µs+8µs) by Class::Load::BEGIN@11 at line 6 # spent 14µs making 1 call to Module::Implementation::BEGIN@6
# spent 8µs making 1 call to warnings::import |
| 7 | |||||
| 8 | 3 | 28µs | 3 | 55µs | # spent 32µs (10+22) within Module::Implementation::BEGIN@8 which was called:
# once (10µs+22µs) by Class::Load::BEGIN@11 at line 8 # spent 32µs making 1 call to Module::Implementation::BEGIN@8
# spent 16µs making 1 call to Module::Runtime::import
# spent 6µs making 1 call to UNIVERSAL::VERSION |
| 9 | 2 | 426µs | 2 | 1.04ms | # spent 1.01ms (600µs+410µs) within Module::Implementation::BEGIN@9 which was called:
# once (600µs+410µs) by Class::Load::BEGIN@11 at line 9 # spent 1.01ms making 1 call to Module::Implementation::BEGIN@9
# spent 28µ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 | 500ns | 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 59µs (15+44) within Module::Implementation::build_loader_sub which was called 3 times, avg 20µs/call:
# once (6µs+14µs) by Package::Stash::BEGIN@15 at line 19 of Package/Stash.pm
# once (4µs+15µs) by B::Hooks::EndOfScope::BEGIN@15 at line 17 of B/Hooks/EndOfScope.pm
# once (4µs+15µs) by Moose::BEGIN@12 at line 16 of Class/Load.pm | ||||
| 23 | 3 | 2µs | my $caller = caller(); | ||
| 24 | |||||
| 25 | 3 | 12µs | 3 | 44µs | return _build_loader( $caller, @_ ); # spent 44µs making 3 calls to Module::Implementation::_build_loader, avg 15µs/call |
| 26 | } | ||||
| 27 | |||||
| 28 | # spent 44µs (39+5) within Module::Implementation::_build_loader which was called 3 times, avg 15µs/call:
# 3 times (39µs+5µs) by Module::Implementation::build_loader_sub at line 25, avg 15µs/call | ||||
| 29 | 3 | 1µs | my $package = shift; | ||
| 30 | 3 | 5µs | my %args = @_; | ||
| 31 | |||||
| 32 | 3 | 4µs | my @implementations = @{ $args{implementations} }; | ||
| 33 | 3 | 2µs | my @symbols = @{ $args{symbols} || [] }; | ||
| 34 | |||||
| 35 | 3 | 500ns | my $implementation; | ||
| 36 | 3 | 3µs | my $env_var = uc $package; | ||
| 37 | 3 | 16µs | 3 | 5µs | $env_var =~ s/::/_/g; # spent 5µs making 3 calls to Module::Implementation::CORE:subst, avg 2µs/call |
| 38 | 3 | 2µs | $env_var .= '_IMPLEMENTATION'; | ||
| 39 | |||||
| 40 | # spent 2.11ms (27µs+2.08) within Module::Implementation::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Module/Implementation.pm:52] which was called 3 times, avg 702µs/call:
# once (10µs+1.16ms) by B::Hooks::EndOfScope::BEGIN@15 at line 17 of B/Hooks/EndOfScope.pm
# once (10µs+464µs) by Moose::BEGIN@12 at line 21 of Class/Load.pm
# once (8µs+452µs) by Package::Stash::BEGIN@15 at line 19 of Package/Stash.pm | ||||
| 41 | my ( $implementation, $loaded ) = _load_implementation( | ||||
| 42 | $package, | ||||
| 43 | 3 | 10µs | 3 | 2.01ms | $ENV{$env_var}, # spent 2.01ms making 3 calls to Module::Implementation::_load_implementation, avg 671µs/call |
| 44 | \@implementations, | ||||
| 45 | ); | ||||
| 46 | |||||
| 47 | 3 | 2µs | $Implementation{$package} = $implementation; | ||
| 48 | |||||
| 49 | 3 | 5µs | 3 | 64µs | _copy_symbols( $loaded, $package, \@symbols ); # spent 64µs making 3 calls to Module::Implementation::_copy_symbols, avg 21µs/call |
| 50 | |||||
| 51 | 3 | 6µs | return $loaded; | ||
| 52 | 3 | 14µ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 | 300ns | my $package = shift; | ||
| 57 | |||||
| 58 | 1 | 3µs | return $Implementation{$package}; | ||
| 59 | } | ||||
| 60 | |||||
| 61 | # spent 2.01ms (48µs+1.97) within Module::Implementation::_load_implementation which was called 3 times, avg 671µs/call:
# 3 times (48µs+1.97ms) by Module::Implementation::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Module/Implementation.pm:52] at line 43, avg 671µs/call | ||||
| 62 | 3 | 1µs | my $package = shift; | ||
| 63 | 3 | 2µs | my $env_value = shift; | ||
| 64 | 3 | 700ns | my $implementations = shift; | ||
| 65 | |||||
| 66 | 3 | 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 | 3 | 500ns | my $err; | ||
| 88 | 3 | 3µs | for my $possible ( @{$implementations} ) { | ||
| 89 | 3 | 2µs | my $try = "${package}::$possible"; | ||
| 90 | |||||
| 91 | 3 | 100ns | my $ok; | ||
| 92 | # spent 1.86ms (12µs+1.85) within Module::Implementation::try {...} which was called 3 times, avg 620µs/call:
# 3 times (12µs+1.85ms) by Try::Tiny::try at line 92 of Try/Tiny.pm, avg 620µs/call | ||||
| 93 | 3 | 7µs | 3 | 1.85ms | require_module($try); # spent 1.85ms making 3 calls to Module::Runtime::require_module, avg 616µs/call |
| 94 | 3 | 6µs | $ok = 1; | ||
| 95 | } | ||||
| 96 | catch { | ||||
| 97 | $err .= $_ if defined $_; | ||||
| 98 | 3 | 28µs | 6 | 1.97ms | }; # spent 1.91ms making 3 calls to Try::Tiny::try, avg 638µs/call
# spent 51µs making 3 calls to Try::Tiny::catch, avg 17µs/call |
| 99 | |||||
| 100 | 3 | 10µ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 64µs (61+4) within Module::Implementation::_copy_symbols which was called 3 times, avg 21µs/call:
# 3 times (61µs+4µs) by Module::Implementation::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Module/Implementation.pm:52] at line 49, avg 21µs/call | ||||
| 117 | 3 | 1µs | my $from_package = shift; | ||
| 118 | 3 | 1µs | my $to_package = shift; | ||
| 119 | 3 | 500ns | my $symbols = shift; | ||
| 120 | |||||
| 121 | 3 | 9µs | for my $sym ( @{$symbols} ) { | ||
| 122 | 13 | 19µs | 13 | 4µs | my $type = $sym =~ s/^([\$\@\%\&\*])// ? $1 : '&'; # spent 4µs making 13 calls to Module::Implementation::CORE:subst, avg 285ns/call |
| 123 | |||||
| 124 | 13 | 5µs | my $from = "${from_package}::$sym"; | ||
| 125 | 13 | 3µs | my $to = "${to_package}::$sym"; | ||
| 126 | |||||
| 127 | { | ||||
| 128 | 15 | 26µs | 2 | 38µs | # spent 22µs (6+16) within Module::Implementation::BEGIN@128 which was called:
# once (6µs+16µs) by Class::Load::BEGIN@11 at line 128 # spent 22µs making 1 call to Module::Implementation::BEGIN@128
# spent 16µs making 1 call to strict::unimport |
| 129 | 2 | 67µs | 2 | 42µs | # spent 25µs (7+18) within Module::Implementation::BEGIN@129 which was called:
# once (7µs+18µs) by Class::Load::BEGIN@11 at line 129 # spent 25µs making 1 call to Module::Implementation::BEGIN@129
# spent 18µ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 | 13 | 22µ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 |