Filename | /usr/local/share/perl/5.14.2/Module/Implementation.pm |
Statements | Executed 244 statements in 1.33ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.41ms | 1.53ms | BEGIN@12 | Module::Implementation::
1 | 1 | 1 | 769µs | 2.61ms | BEGIN@13 | Module::Implementation::
3 | 1 | 1 | 115µs | 127µs | _copy_symbols | Module::Implementation::
3 | 1 | 1 | 66µs | 1.69ms | _load_implementation | Module::Implementation::
3 | 1 | 1 | 56µs | 67µs | _build_loader | Module::Implementation::
3 | 3 | 3 | 33µs | 1.85ms | __ANON__[:47] | Module::Implementation::
20 | 2 | 1 | 22µs | 22µs | CORE:subst (opcode) | Module::Implementation::
3 | 3 | 3 | 17µs | 84µs | build_loader_sub | Module::Implementation::
1 | 1 | 1 | 8µs | 8µs | BEGIN@5 | Module::Implementation::
1 | 1 | 1 | 8µs | 18µs | BEGIN@123 | Module::Implementation::
1 | 1 | 1 | 7µs | 17µs | BEGIN@124 | Module::Implementation::
1 | 1 | 1 | 6µs | 9µs | BEGIN@9 | Module::Implementation::
1 | 1 | 1 | 6µs | 11µs | BEGIN@10 | Module::Implementation::
1 | 1 | 1 | 3µs | 3µ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 Params::Validate::BEGIN@12 at line 7 | ||||
6 | 1 | 4µ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 | 23µs | 2 | 12µs | # spent 9µs (6+3) within Module::Implementation::BEGIN@9 which was called:
# once (6µs+3µs) by Params::Validate::BEGIN@12 at line 9 # spent 9µs making 1 call to Module::Implementation::BEGIN@9
# spent 3µs making 1 call to strict::import |
10 | 2 | 26µs | 2 | 15µs | # spent 11µs (6+5) within Module::Implementation::BEGIN@10 which was called:
# once (6µs+5µs) by Params::Validate::BEGIN@12 at line 10 # spent 11µs making 1 call to Module::Implementation::BEGIN@10
# spent 4µs making 1 call to warnings::import |
11 | |||||
12 | 3 | 190µs | 3 | 1.56ms | # spent 1.53ms (1.41+121µs) within Module::Implementation::BEGIN@12 which was called:
# once (1.41ms+121µs) by Params::Validate::BEGIN@12 at line 12 # spent 1.53ms making 1 call to Module::Implementation::BEGIN@12
# spent 17µs making 1 call to UNIVERSAL::VERSION
# spent 14µs making 1 call to Module::Runtime::import |
13 | 2 | 594µs | 2 | 2.65ms | # spent 2.61ms (769µs+1.85) within Module::Implementation::BEGIN@13 which was called:
# once (769µs+1.85ms) by Params::Validate::BEGIN@12 at line 13 # spent 2.61ms making 1 call to Module::Implementation::BEGIN@13
# spent 34µs making 1 call to Exporter::import |
14 | |||||
15 | 1 | 200ns | my %Implementation; | ||
16 | |||||
17 | # spent 84µs (17+67) within Module::Implementation::build_loader_sub which was called 3 times, avg 28µs/call:
# once (7µs+28µs) by Package::Stash::BEGIN@17 at line 21 of Package/Stash.pm
# once (5µs+20µs) by DateTime::Duration::BEGIN@12 at line 51 of Params/Validate.pm
# once (5µs+18µs) by DateTime::TimeZone::Local::BEGIN@12 at line 19 of Class/Load.pm | ||||
18 | 3 | 2µs | my $caller = caller(); | ||
19 | |||||
20 | 3 | 15µs | 3 | 67µs | return _build_loader( $caller, @_ ); # spent 67µs making 3 calls to Module::Implementation::_build_loader, avg 22µs/call |
21 | } | ||||
22 | |||||
23 | # spent 67µs (56+11) within Module::Implementation::_build_loader which was called 3 times, avg 22µs/call:
# 3 times (56µs+11µs) by Module::Implementation::build_loader_sub at line 20, avg 22µs/call | ||||
24 | 3 | 2µs | my $package = shift; | ||
25 | 3 | 6µs | my %args = @_; | ||
26 | |||||
27 | 6 | 7µs | my @implementations = @{ $args{implementations} }; | ||
28 | 6 | 6µs | my @symbols = @{ $args{symbols} || [] }; | ||
29 | |||||
30 | 3 | 700ns | my $implementation; | ||
31 | 3 | 4µs | my $env_var = uc $package; | ||
32 | 3 | 23µs | 3 | 11µs | $env_var =~ s/::/_/g; # spent 11µs making 3 calls to Module::Implementation::CORE:subst, avg 4µs/call |
33 | 3 | 2µs | $env_var .= '_IMPLEMENTATION'; | ||
34 | |||||
35 | # spent 1.85ms (33µs+1.82) within Module::Implementation::__ANON__[/usr/local/share/perl/5.14.2/Module/Implementation.pm:47] which was called 3 times, avg 617µs/call:
# once (11µs+676µs) by DateTime::Duration::BEGIN@12 at line 66 of Params/Validate.pm
# once (13µs+641µs) by Package::Stash::BEGIN@17 at line 21 of Package/Stash.pm
# once (9µs+502µs) by DateTime::TimeZone::Local::BEGIN@12 at line 24 of Class/Load.pm | ||||
36 | 3 | 12µs | 3 | 1.69ms | my ( $implementation, $loaded ) = _load_implementation( # spent 1.69ms making 3 calls to Module::Implementation::_load_implementation, avg 564µs/call |
37 | $package, | ||||
38 | $ENV{$env_var}, | ||||
39 | \@implementations, | ||||
40 | ); | ||||
41 | |||||
42 | 3 | 3µs | $Implementation{$package} = $implementation; | ||
43 | |||||
44 | 3 | 7µs | 3 | 127µs | _copy_symbols( $loaded, $package, \@symbols ); # spent 127µs making 3 calls to Module::Implementation::_copy_symbols, avg 42µs/call |
45 | |||||
46 | 3 | 12µs | return $loaded; | ||
47 | 3 | 21µs | }; | ||
48 | } | ||||
49 | |||||
50 | # spent 3µs within Module::Implementation::implementation_for which was called:
# once (3µs+0s) by Package::Stash::BEGIN@17 at line 37 of Package/Stash.pm | ||||
51 | 1 | 600ns | my $package = shift; | ||
52 | |||||
53 | 1 | 4µs | return $Implementation{$package}; | ||
54 | } | ||||
55 | |||||
56 | # spent 1.69ms (66µs+1.63) within Module::Implementation::_load_implementation which was called 3 times, avg 564µs/call:
# 3 times (66µs+1.63ms) by Module::Implementation::__ANON__[/usr/local/share/perl/5.14.2/Module/Implementation.pm:47] at line 36, avg 564µs/call | ||||
57 | 3 | 2µs | my $package = shift; | ||
58 | 3 | 3µs | my $env_value = shift; | ||
59 | 3 | 800ns | my $implementations = shift; | ||
60 | |||||
61 | 3 | 1µs | 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 | 3 | 900ns | my $err; | ||
83 | 6 | 4µs | for my $possible ( @{$implementations} ) { | ||
84 | 3 | 3µs | my $try = "${package}::$possible"; | ||
85 | |||||
86 | 3 | 400ns | my $ok; | ||
87 | try { | ||||
88 | 3 | 7µs | 3 | 1.50ms | require_module($try); # spent 1.50ms making 3 calls to Module::Runtime::require_module, avg 501µs/call |
89 | 3 | 8µs | $ok = 1; | ||
90 | } | ||||
91 | catch { | ||||
92 | $err .= $_ if defined $_; | ||||
93 | 3 | 35µs | 6 | 1.63ms | }; # spent 1.60ms making 3 calls to Try::Tiny::try, avg 534µs/call
# spent 24µs making 3 calls to Try::Tiny::catch, avg 8µs/call |
94 | |||||
95 | 3 | 11µ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 127µs (115+11) within Module::Implementation::_copy_symbols which was called 3 times, avg 42µs/call:
# 3 times (115µs+11µs) by Module::Implementation::__ANON__[/usr/local/share/perl/5.14.2/Module/Implementation.pm:47] at line 44, avg 42µs/call | ||||
112 | 3 | 2µs | my $from_package = shift; | ||
113 | 3 | 700ns | my $to_package = shift; | ||
114 | 3 | 600ns | my $symbols = shift; | ||
115 | |||||
116 | 6 | 12µs | for my $sym ( @{$symbols} ) { | ||
117 | 17 | 39µs | 17 | 11µs | my $type = $sym =~ s/^([\$\@\%\&\*])// ? $1 : '&'; # spent 11µs making 17 calls to Module::Implementation::CORE:subst, avg 665ns/call |
118 | |||||
119 | 17 | 7µs | my $from = "${from_package}::$sym"; | ||
120 | 17 | 5µs | my $to = "${to_package}::$sym"; | ||
121 | |||||
122 | { | ||||
123 | 19 | 42µs | 2 | 29µs | # spent 18µs (8+10) within Module::Implementation::BEGIN@123 which was called:
# once (8µs+10µs) by Params::Validate::BEGIN@12 at line 123 # spent 18µs making 1 call to Module::Implementation::BEGIN@123
# spent 10µs making 1 call to strict::unimport |
124 | 2 | 100µs | 2 | 27µs | # spent 17µs (7+10) within Module::Implementation::BEGIN@124 which was called:
# once (7µs+10µs) by Params::Validate::BEGIN@12 at line 124 # spent 17µs making 1 call to Module::Implementation::BEGIN@124
# spent 10µs making 1 call to warnings::unimport |
125 | |||||
126 | # Copied from Exporter | ||||
127 | 34 | 8µs | *{$to} | ||
128 | = $type eq '&' ? \&{$from} | ||||
129 | : $type eq '$' ? \${$from} | ||||
130 | : $type eq '@' ? \@{$from} | ||||
131 | : $type eq '%' ? \%{$from} | ||||
132 | 17 | 42µ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 |