Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Module/Implementation.pm |
Statements | Executed 141 statements in 1.05ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 748µs | 904µs | BEGIN@9 | Module::Implementation::
2 | 1 | 1 | 86µs | 95µs | _copy_symbols | Module::Implementation::
2 | 1 | 1 | 71µs | 6.98ms | _load_implementation | Module::Implementation::
1 | 1 | 1 | 43µs | 47µs | BEGIN@5 | Module::Implementation::
2 | 1 | 1 | 19µs | 24µs | _build_loader | Module::Implementation::
2 | 2 | 2 | 18µs | 7.09ms | __ANON__[:52] | Module::Implementation::
14 | 2 | 1 | 14µs | 14µs | CORE:subst (opcode) | Module::Implementation::
1 | 1 | 1 | 14µs | 72µs | BEGIN@8 | Module::Implementation::
2 | 2 | 2 | 9µs | 33µs | build_loader_sub | Module::Implementation::
2 | 1 | 1 | 8µs | 6.81ms | try {...} | Module::Implementation::
1 | 1 | 1 | 7µs | 13µs | BEGIN@128 | Module::Implementation::
1 | 1 | 1 | 6µs | 33µs | BEGIN@6 | Module::Implementation::
1 | 1 | 1 | 5µs | 17µs | BEGIN@129 | Module::Implementation::
1 | 1 | 1 | 2µs | 2µs | implementation_for | Module::Implementation::
0 | 0 | 0 | 0s | 0s | __ANON__[:78] | Module::Implementation::
0 | 0 | 0 | 0s | 0s | __ANON__[:82] | Module::Implementation::
0 | 0 | 0 | 0s | 0s | __ANON__[:95] | Module::Implementation::
0 | 0 | 0 | 0s | 0s | __ANON__[:98] | Module::Implementation::
0 | 0 | 0 | 0s | 0s | catch {...} | Module::Implementation::
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 | 30µs | 2 | 51µs | # spent 47µs (43+4) within Module::Implementation::BEGIN@5 which was called:
# once (43µs+4µs) by B::Hooks::EndOfScope::BEGIN@13 at line 5 # spent 47µs making 1 call to Module::Implementation::BEGIN@5
# spent 4µs making 1 call to strict::import |
6 | 2 | 52µs | 2 | 60µs | # spent 33µs (6+27) within Module::Implementation::BEGIN@6 which was called:
# once (6µs+27µs) by B::Hooks::EndOfScope::BEGIN@13 at line 6 # spent 33µs making 1 call to Module::Implementation::BEGIN@6
# spent 27µs making 1 call to warnings::import |
7 | |||||
8 | 3 | 70µs | 3 | 130µs | # spent 72µs (14+58) within Module::Implementation::BEGIN@8 which was called:
# once (14µs+58µs) by B::Hooks::EndOfScope::BEGIN@13 at line 8 # spent 72µs making 1 call to Module::Implementation::BEGIN@8
# spent 45µs making 1 call to UNIVERSAL::VERSION
# spent 13µs making 1 call to Module::Runtime::import |
9 | 2 | 533µs | 2 | 924µs | # spent 904µs (748+156) within Module::Implementation::BEGIN@9 which was called:
# once (748µs+156µs) by B::Hooks::EndOfScope::BEGIN@13 at line 9 # spent 904µs making 1 call to Module::Implementation::BEGIN@9
# spent 20µ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 | 0s | unless ( exists $Module::Implementation::{VERSION} | ||
15 | && ${ $Module::Implementation::{VERSION} } ) { | ||||
16 | |||||
17 | $Module::Implementation::{VERSION} = \42; | ||||
18 | } | ||||
19 | |||||
20 | 1 | 1µs | my %Implementation; | ||
21 | |||||
22 | # spent 33µs (9+24) within Module::Implementation::build_loader_sub which was called 2 times, avg 16µs/call:
# once (2µs+16µs) by Package::Stash::BEGIN@12 at line 16 of Package/Stash.pm
# once (7µs+8µ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 | 9µs | 2 | 24µs | return _build_loader( $caller, @_ ); # spent 24µs making 2 calls to Module::Implementation::_build_loader, avg 12µs/call |
26 | } | ||||
27 | |||||
28 | # spent 24µs (19+5) within Module::Implementation::_build_loader which was called 2 times, avg 12µs/call:
# 2 times (19µs+5µs) by Module::Implementation::build_loader_sub at line 25, avg 12µs/call | ||||
29 | 2 | 0s | my $package = shift; | ||
30 | 2 | 5µs | my %args = @_; | ||
31 | |||||
32 | 2 | 2µs | my @implementations = @{ $args{implementations} }; | ||
33 | 2 | 1µs | my @symbols = @{ $args{symbols} || [] }; | ||
34 | |||||
35 | 2 | 1µs | my $implementation; | ||
36 | 2 | 1µs | my $env_var = uc $package; | ||
37 | 2 | 8µs | 2 | 5µs | $env_var =~ s/::/_/g; # spent 5µs making 2 calls to Module::Implementation::CORE:subst, avg 2µs/call |
38 | 2 | 0s | $env_var .= '_IMPLEMENTATION'; | ||
39 | |||||
40 | # spent 7.09ms (18µs+7.07) within Module::Implementation::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Module/Implementation.pm:52] which was called 2 times, avg 3.54ms/call:
# once (9µs+5.37ms) by B::Hooks::EndOfScope::BEGIN@12 at line 14 of B/Hooks/EndOfScope.pm
# once (9µs+1.70ms) by Package::Stash::BEGIN@12 at line 16 of Package/Stash.pm | ||||
41 | my ( $implementation, $loaded ) = _load_implementation( | ||||
42 | $package, | ||||
43 | 2 | 6µs | 2 | 6.98ms | $ENV{$env_var}, # spent 6.98ms making 2 calls to Module::Implementation::_load_implementation, avg 3.49ms/call |
44 | \@implementations, | ||||
45 | ); | ||||
46 | |||||
47 | 2 | 3µs | $Implementation{$package} = $implementation; | ||
48 | |||||
49 | 2 | 5µs | 2 | 95µs | _copy_symbols( $loaded, $package, \@symbols ); # spent 95µs making 2 calls to Module::Implementation::_copy_symbols, avg 48µs/call |
50 | |||||
51 | 2 | 4µs | return $loaded; | ||
52 | 2 | 10µ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 | 2µs | return $Implementation{$package}; | ||
59 | } | ||||
60 | |||||
61 | # spent 6.98ms (71µs+6.90) within Module::Implementation::_load_implementation which was called 2 times, avg 3.49ms/call:
# 2 times (71µs+6.90ms) by Module::Implementation::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Module/Implementation.pm:52] at line 43, avg 3.49ms/call | ||||
62 | 2 | 0s | my $package = shift; | ||
63 | 2 | 2µs | my $env_value = shift; | ||
64 | 2 | 1µ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 | 1µs | my $try = "${package}::$possible"; | ||
90 | |||||
91 | 2 | 0s | my $ok; | ||
92 | # spent 6.81ms (8µs+6.80) within Module::Implementation::try {...} which was called 2 times, avg 3.41ms/call:
# 2 times (8µs+6.80ms) by Try::Tiny::try at line 102 of Try/Tiny.pm, avg 3.41ms/call | ||||
93 | 2 | 5µs | 2 | 6.80ms | require_module($try); # spent 6.80ms making 2 calls to Module::Runtime::require_module, avg 3.40ms/call |
94 | 2 | 5µs | $ok = 1; | ||
95 | } | ||||
96 | catch { | ||||
97 | $err .= $_ if defined $_; | ||||
98 | 2 | 51µs | 4 | 6.90ms | }; # spent 6.88ms making 2 calls to Try::Tiny::try, avg 3.44ms/call
# spent 20µs making 2 calls to Try::Tiny::catch, avg 10µs/call |
99 | |||||
100 | 2 | 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 95µs (86+9) within Module::Implementation::_copy_symbols which was called 2 times, avg 48µs/call:
# 2 times (86µs+9µs) by Module::Implementation::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Module/Implementation.pm:52] at line 49, avg 48µs/call | ||||
117 | 2 | 1µs | my $from_package = shift; | ||
118 | 2 | 1µs | my $to_package = shift; | ||
119 | 2 | 0s | my $symbols = shift; | ||
120 | |||||
121 | 2 | 6µs | for my $sym ( @{$symbols} ) { | ||
122 | 12 | 19µs | 12 | 9µs | my $type = $sym =~ s/^([\$\@\%\&\*])// ? $1 : '&'; # spent 9µs making 12 calls to Module::Implementation::CORE:subst, avg 750ns/call |
123 | |||||
124 | 12 | 4µs | my $from = "${from_package}::$sym"; | ||
125 | 12 | 2µs | my $to = "${to_package}::$sym"; | ||
126 | |||||
127 | { | ||||
128 | 14 | 29µs | 2 | 19µs | # spent 13µs (7+6) within Module::Implementation::BEGIN@128 which was called:
# once (7µs+6µs) by B::Hooks::EndOfScope::BEGIN@13 at line 128 # spent 13µs making 1 call to Module::Implementation::BEGIN@128
# spent 6µs making 1 call to strict::unimport |
129 | 2 | 99µs | 2 | 29µs | # spent 17µs (5+12) within Module::Implementation::BEGIN@129 which was called:
# once (5µs+12µs) by B::Hooks::EndOfScope::BEGIN@13 at line 129 # spent 17µs making 1 call to Module::Implementation::BEGIN@129
# spent 12µ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 | 58µ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 | 3µs | 1; | ||
145 | |||||
146 | # ABSTRACT: Loads one of several alternate underlying implementations for a module | ||||
147 | |||||
148 | __END__ | ||||
sub Module::Implementation::CORE:subst; # opcode |