Filename | /usr/local/share/perl/5.14.2/Module/Implementation.pm |
Statements | Executed 244 statements in 2.78ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 2.98ms | 3.22ms | BEGIN@12 | Module::Implementation::
1 | 1 | 1 | 1.77ms | 5.73ms | BEGIN@13 | Module::Implementation::
3 | 1 | 1 | 174µs | 192µs | _copy_symbols | Module::Implementation::
3 | 1 | 1 | 101µs | 2.91ms | _load_implementation | Module::Implementation::
3 | 1 | 1 | 88µs | 108µs | _build_loader | Module::Implementation::
3 | 3 | 3 | 59µs | 3.16ms | __ANON__[:47] | Module::Implementation::
20 | 2 | 1 | 38µs | 38µs | CORE:subst (opcode) | Module::Implementation::
3 | 3 | 3 | 27µs | 135µs | build_loader_sub | Module::Implementation::
1 | 1 | 1 | 18µs | 44µs | BEGIN@123 | Module::Implementation::
1 | 1 | 1 | 18µs | 18µs | BEGIN@5 | Module::Implementation::
1 | 1 | 1 | 17µs | 40µs | BEGIN@124 | Module::Implementation::
1 | 1 | 1 | 15µs | 22µs | BEGIN@9 | Module::Implementation::
1 | 1 | 1 | 15µs | 25µ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 | 2µs | $Module::Implementation::VERSION = '0.07'; | ||
4 | } | ||||
5 | # spent 18µs within Module::Implementation::BEGIN@5 which was called:
# once (18µs+0s) by Params::Validate::BEGIN@12 at line 7 | ||||
6 | 1 | 10µs | $Module::Implementation::AUTHORITY = 'cpan:DROLSKY'; | ||
7 | 1 | 52µs | 1 | 18µs | } # spent 18µs making 1 call to Module::Implementation::BEGIN@5 |
8 | |||||
9 | 2 | 54µs | 2 | 29µs | # spent 22µs (15+7) within Module::Implementation::BEGIN@9 which was called:
# once (15µs+7µs) by Params::Validate::BEGIN@12 at line 9 # spent 22µs making 1 call to Module::Implementation::BEGIN@9
# spent 7µs making 1 call to strict::import |
10 | 2 | 59µs | 2 | 35µs | # spent 25µs (15+10) within Module::Implementation::BEGIN@10 which was called:
# once (15µs+10µs) by Params::Validate::BEGIN@12 at line 10 # spent 25µs making 1 call to Module::Implementation::BEGIN@10
# spent 10µs making 1 call to warnings::import |
11 | |||||
12 | 3 | 416µs | 3 | 3.29ms | # spent 3.22ms (2.98+246µs) within Module::Implementation::BEGIN@12 which was called:
# once (2.98ms+246µs) by Params::Validate::BEGIN@12 at line 12 # spent 3.22ms making 1 call to Module::Implementation::BEGIN@12
# spent 36µs making 1 call to UNIVERSAL::VERSION
# spent 34µs making 1 call to Module::Runtime::import |
13 | 2 | 1.36ms | 2 | 5.81ms | # spent 5.73ms (1.77+3.96) within Module::Implementation::BEGIN@13 which was called:
# once (1.77ms+3.96ms) by Params::Validate::BEGIN@12 at line 13 # spent 5.73ms making 1 call to Module::Implementation::BEGIN@13
# spent 77µs making 1 call to Exporter::import |
14 | |||||
15 | 1 | 400ns | my %Implementation; | ||
16 | |||||
17 | # spent 135µs (27+108) within Module::Implementation::build_loader_sub which was called 3 times, avg 45µs/call:
# once (12µs+44µs) by DateTime::Duration::BEGIN@12 at line 51 of Params/Validate.pm
# once (10µs+41µs) by DateTime::TimeZone::Local::BEGIN@12 at line 19 of Class/Load.pm
# once (5µs+23µs) by Package::Stash::BEGIN@17 at line 21 of Package/Stash.pm | ||||
18 | 6 | 29µs | my $caller = caller(); | ||
19 | |||||
20 | 3 | 108µs | return _build_loader( $caller, @_ ); # spent 108µs making 3 calls to Module::Implementation::_build_loader, avg 36µs/call | ||
21 | } | ||||
22 | |||||
23 | # spent 108µs (88+20) within Module::Implementation::_build_loader which was called 3 times, avg 36µs/call:
# 3 times (88µs+20µs) by Module::Implementation::build_loader_sub at line 20, avg 36µs/call | ||||
24 | 27 | 108µs | my $package = shift; | ||
25 | my %args = @_; | ||||
26 | |||||
27 | 3 | 3µs | my @implementations = @{ $args{implementations} }; | ||
28 | 3 | 3µs | my @symbols = @{ $args{symbols} || [] }; | ||
29 | |||||
30 | my $implementation; | ||||
31 | my $env_var = uc $package; | ||||
32 | 3 | 20µs | $env_var =~ s/::/_/g; # spent 20µs making 3 calls to Module::Implementation::CORE:subst, avg 7µs/call | ||
33 | $env_var .= '_IMPLEMENTATION'; | ||||
34 | |||||
35 | # spent 3.16ms (59µs+3.10) within Module::Implementation::__ANON__[/usr/local/share/perl/5.14.2/Module/Implementation.pm:47] which was called 3 times, avg 1.05ms/call:
# once (25µs+1.42ms) by DateTime::Duration::BEGIN@12 at line 66 of Params/Validate.pm
# once (21µs+1.12ms) by DateTime::TimeZone::Local::BEGIN@12 at line 24 of Class/Load.pm
# once (13µs+568µs) by Package::Stash::BEGIN@17 at line 21 of Package/Stash.pm | ||||
36 | 12 | 59µs | 3 | 2.91ms | my ( $implementation, $loaded ) = _load_implementation( # spent 2.91ms making 3 calls to Module::Implementation::_load_implementation, avg 971µs/call |
37 | $package, | ||||
38 | $ENV{$env_var}, | ||||
39 | \@implementations, | ||||
40 | ); | ||||
41 | |||||
42 | $Implementation{$package} = $implementation; | ||||
43 | |||||
44 | 3 | 192µs | _copy_symbols( $loaded, $package, \@symbols ); # spent 192µs making 3 calls to Module::Implementation::_copy_symbols, avg 64µs/call | ||
45 | |||||
46 | return $loaded; | ||||
47 | }; | ||||
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 | 2 | 4µs | my $package = shift; | ||
52 | |||||
53 | return $Implementation{$package}; | ||||
54 | } | ||||
55 | |||||
56 | # spent 2.91ms (101µs+2.81) within Module::Implementation::_load_implementation which was called 3 times, avg 971µs/call:
# 3 times (101µs+2.81ms) by Module::Implementation::__ANON__[/usr/local/share/perl/5.14.2/Module/Implementation.pm:47] at line 36, avg 971µs/call | ||||
57 | 12 | 10µs | my $package = shift; | ||
58 | my $env_value = shift; | ||||
59 | my $implementations = shift; | ||||
60 | |||||
61 | 6 | 5µ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 | my $err; | ||||
83 | 3 | 2µs | for my $possible ( @{$implementations} ) { | ||
84 | 12 | 77µs | my $try = "${package}::$possible"; | ||
85 | |||||
86 | my $ok; | ||||
87 | try { | ||||
88 | 6 | 21µs | 3 | 2.60ms | require_module($try); # spent 2.60ms making 3 calls to Module::Runtime::require_module, avg 866µs/call |
89 | $ok = 1; | ||||
90 | } | ||||
91 | catch { | ||||
92 | $err .= $_ if defined $_; | ||||
93 | 6 | 2.81ms | }; # spent 2.76ms making 3 calls to Try::Tiny::try, avg 919µs/call
# spent 54µs making 3 calls to Try::Tiny::catch, avg 18µs/call | ||
94 | |||||
95 | 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 192µs (174+18) within Module::Implementation::_copy_symbols which was called 3 times, avg 64µs/call:
# 3 times (174µs+18µs) by Module::Implementation::__ANON__[/usr/local/share/perl/5.14.2/Module/Implementation.pm:47] at line 44, avg 64µs/call | ||||
112 | 12 | 23µs | my $from_package = shift; | ||
113 | my $to_package = shift; | ||||
114 | my $symbols = shift; | ||||
115 | |||||
116 | 3 | 2µs | for my $sym ( @{$symbols} ) { | ||
117 | 68 | 96µs | 17 | 18µs | my $type = $sym =~ s/^([\$\@\%\&\*])// ? $1 : '&'; # spent 18µs making 17 calls to Module::Implementation::CORE:subst, avg 1µs/call |
118 | |||||
119 | my $from = "${from_package}::$sym"; | ||||
120 | my $to = "${to_package}::$sym"; | ||||
121 | |||||
122 | { | ||||
123 | 2 | 66µs | 2 | 69µs | # spent 44µs (18+25) within Module::Implementation::BEGIN@123 which was called:
# once (18µs+25µs) by Params::Validate::BEGIN@12 at line 123 # spent 44µs making 1 call to Module::Implementation::BEGIN@123
# spent 25µs making 1 call to strict::unimport |
124 | 2 | 228µs | 2 | 64µs | # spent 40µs (17+23) within Module::Implementation::BEGIN@124 which was called:
# once (17µs+23µs) by Params::Validate::BEGIN@12 at line 124 # spent 40µs making 1 call to Module::Implementation::BEGIN@124
# spent 23µ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 | 51 | 75µ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 | 6µs | 1; | ||
140 | |||||
141 | # ABSTRACT: Loads one of several alternate underlying implementations for a module | ||||
142 | |||||
143 | __END__ | ||||
sub Module::Implementation::CORE:subst; # opcode |