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