| Filename | /usr/local/share/perl/5.18.2/Class/Load.pm |
| Statements | Executed 189 statements in 1.42ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 679µs | 4.42ms | Class::Load::BEGIN@11 |
| 1 | 1 | 1 | 540µs | 6.23ms | Class::Load::BEGIN@10 |
| 10 | 2 | 1 | 155µs | 50.1ms | Class::Load::try_load_class (recurses: max depth 1, inclusive time 62µs) |
| 9 | 3 | 1 | 77µs | 49.9ms | Class::Load::load_class (recurses: max depth 1, inclusive time 74µs) |
| 1 | 1 | 1 | 20µs | 284µs | Class::Load::load_optional_class |
| 1 | 1 | 1 | 12µs | 37µs | Class::Load::_nonexistent_fail_re |
| 1 | 1 | 1 | 10µs | 37µs | Class::Load::BEGIN@12 |
| 2 | 2 | 1 | 8µs | 8µs | Class::Load::CORE:regcomp (opcode) |
| 1 | 1 | 1 | 8µs | 12µs | Class::Load::_error |
| 1 | 1 | 1 | 7µs | 11µs | Class::Load::BEGIN@8 |
| 1 | 1 | 1 | 7µs | 60µs | Class::Load::BEGIN@9 |
| 1 | 1 | 1 | 6µs | 16µs | Class::Load::BEGIN@7 |
| 1 | 1 | 1 | 6µs | 6µs | Class::Load::BEGIN@2 |
| 1 | 1 | 1 | 6µs | 32µs | Class::Load::BEGIN@18 |
| 1 | 1 | 1 | 4µs | 4µs | Class::Load::CORE:subst (opcode) |
| 1 | 1 | 1 | 2µs | 2µs | Class::Load::CORE:qr (opcode) |
| 1 | 1 | 1 | 600ns | 600ns | Class::Load::CORE:match (opcode) |
| 0 | 0 | 0 | 0s | 0s | Class::Load::__ANON__[:154] |
| 0 | 0 | 0 | 0s | 0s | Class::Load::__ANON__[:157] |
| 0 | 0 | 0 | 0s | 0s | Class::Load::__ANON__[:182] |
| 0 | 0 | 0 | 0s | 0s | Class::Load::__ANON__[:185] |
| 0 | 0 | 0 | 0s | 0s | Class::Load::_croak |
| 0 | 0 | 0 | 0s | 0s | Class::Load::_or_list |
| 0 | 0 | 0 | 0s | 0s | Class::Load::_version_fail_re |
| 0 | 0 | 0 | 0s | 0s | Class::Load::load_first_existing_class |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Class::Load; | ||||
| 2 | # spent 6µs within Class::Load::BEGIN@2 which was called:
# once (6µs+0s) by App::Cmd::BEGIN@13 at line 4 | ||||
| 3 | 1 | 4µs | $Class::Load::AUTHORITY = 'cpan:SARTAK'; | ||
| 4 | 1 | 23µs | 1 | 6µs | } # spent 6µs making 1 call to Class::Load::BEGIN@2 |
| 5 | # git description: v0.20-8-gc4c6e08 | ||||
| 6 | 1 | 900ns | $Class::Load::VERSION = '0.21'; | ||
| 7 | 2 | 31µs | 2 | 26µs | # spent 16µs (6+10) within Class::Load::BEGIN@7 which was called:
# once (6µs+10µs) by App::Cmd::BEGIN@13 at line 7 # spent 16µs making 1 call to Class::Load::BEGIN@7
# spent 10µs making 1 call to strict::import |
| 8 | 2 | 22µs | 2 | 15µs | # spent 11µs (7+4) within Class::Load::BEGIN@8 which was called:
# once (7µs+4µs) by App::Cmd::BEGIN@13 at line 8 # spent 11µs making 1 call to Class::Load::BEGIN@8
# spent 4µs making 1 call to warnings::import |
| 9 | 2 | 23µs | 2 | 114µs | # spent 60µs (7+54) within Class::Load::BEGIN@9 which was called:
# once (7µs+54µs) by App::Cmd::BEGIN@13 at line 9 # spent 60µs making 1 call to Class::Load::BEGIN@9
# spent 54µs making 1 call to base::import |
| 10 | 2 | 81µs | 2 | 6.29ms | # spent 6.23ms (540µs+5.69) within Class::Load::BEGIN@10 which was called:
# once (540µs+5.69ms) by App::Cmd::BEGIN@13 at line 10 # spent 6.23ms making 1 call to Class::Load::BEGIN@10
# spent 61µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:270] |
| 11 | 3 | 122µs | 2 | 4.43ms | # spent 4.42ms (679µs+3.74) within Class::Load::BEGIN@11 which was called:
# once (679µs+3.74ms) by App::Cmd::BEGIN@13 at line 11 # spent 4.42ms making 1 call to Class::Load::BEGIN@11
# spent 12µs making 1 call to UNIVERSAL::VERSION |
| 12 | 1 | 3µs | 1 | 21µs | # spent 37µs (10+27) within Class::Load::BEGIN@12 which was called:
# once (10µs+27µs) by App::Cmd::BEGIN@13 at line 17 # spent 21µs making 1 call to Module::Runtime::import |
| 13 | check_module_name | ||||
| 14 | module_notional_filename | ||||
| 15 | require_module | ||||
| 16 | use_module | ||||
| 17 | 2 | 28µs | 2 | 43µs | ); # spent 37µs making 1 call to Class::Load::BEGIN@12
# spent 6µs making 1 call to UNIVERSAL::VERSION |
| 18 | 2 | 717µs | 2 | 58µs | # spent 32µs (6+26) within Class::Load::BEGIN@18 which was called:
# once (6µs+26µs) by App::Cmd::BEGIN@13 at line 18 # spent 32µs making 1 call to Class::Load::BEGIN@18
# spent 26µs making 1 call to Exporter::import |
| 19 | |||||
| 20 | { | ||||
| 21 | 2 | 3µs | 1 | 22µs | my $loader = Module::Implementation::build_loader_sub( # spent 22µs making 1 call to Module::Implementation::build_loader_sub |
| 22 | implementations => [ 'XS', 'PP' ], | ||||
| 23 | symbols => ['is_class_loaded'], | ||||
| 24 | ); | ||||
| 25 | |||||
| 26 | 1 | 3µs | 1 | 477µs | $loader->(); # spent 477µs making 1 call to Module::Implementation::__ANON__[Module/Implementation.pm:47] |
| 27 | } | ||||
| 28 | |||||
| 29 | 1 | 1µs | our @EXPORT_OK = qw/load_class load_optional_class try_load_class is_class_loaded load_first_existing_class/; | ||
| 30 | 1 | 900ns | our %EXPORT_TAGS = ( | ||
| 31 | all => \@EXPORT_OK, | ||||
| 32 | ); | ||||
| 33 | |||||
| 34 | 1 | 100ns | our $ERROR; | ||
| 35 | |||||
| 36 | # spent 49.9ms (77µs+49.8) within Class::Load::load_class which was called 9 times, avg 5.55ms/call:
# 3 times (39µs+47.4ms) by App::Cmd::_command at line 194 of App/Cmd.pm, avg 15.8ms/call
# 3 times (26µs+2.42ms) by App::Cmd::_load_default_plugin at line 287 of App/Cmd.pm, avg 815µs/call
# 3 times (12µs+-12µs) by App::Cmd::_setup_command at line 35 of App/Cmd.pm, avg 0s/call | ||||
| 37 | 9 | 4µs | my $class = shift; | ||
| 38 | 9 | 4µs | my $options = shift; | ||
| 39 | |||||
| 40 | 9 | 50µs | 9 | 49.9ms | my ($res, $e) = try_load_class($class, $options); # spent 49.9ms making 9 calls to Class::Load::try_load_class, avg 5.55ms/call, recursion: max depth 1, sum of overlapping time 62µs |
| 41 | 9 | 23µs | return $class if $res; | ||
| 42 | |||||
| 43 | _croak($e); | ||||
| 44 | } | ||||
| 45 | |||||
| 46 | sub load_first_existing_class { | ||||
| 47 | my $classes = Data::OptList::mkopt(\@_) | ||||
| 48 | or return; | ||||
| 49 | |||||
| 50 | foreach my $class (@{$classes}) { | ||||
| 51 | check_module_name($class->[0]); | ||||
| 52 | } | ||||
| 53 | |||||
| 54 | for my $class (@{$classes}) { | ||||
| 55 | my ($name, $options) = @{$class}; | ||||
| 56 | |||||
| 57 | # We need to be careful not to pass an undef $options to this sub, | ||||
| 58 | # since the XS version will blow up if that happens. | ||||
| 59 | return $name if is_class_loaded($name, ($options ? $options : ())); | ||||
| 60 | |||||
| 61 | my ($res, $e) = try_load_class($name, $options); | ||||
| 62 | |||||
| 63 | return $name if $res; | ||||
| 64 | |||||
| 65 | my $file = module_notional_filename($name); | ||||
| 66 | |||||
| 67 | next if $e =~ /^Can't locate \Q$file\E in \@INC/; | ||||
| 68 | next | ||||
| 69 | if $options | ||||
| 70 | && defined $options->{-version} | ||||
| 71 | && $e =~ _version_fail_re($name, $options->{-version}); | ||||
| 72 | |||||
| 73 | _croak("Couldn't load class ($name) because: $e"); | ||||
| 74 | } | ||||
| 75 | |||||
| 76 | my @list = map { | ||||
| 77 | $_->[0] | ||||
| 78 | . ( $_->[1] && defined $_->[1]{-version} | ||||
| 79 | ? " (version >= $_->[1]{-version})" | ||||
| 80 | : q{} ) | ||||
| 81 | } @{$classes}; | ||||
| 82 | |||||
| 83 | my $err | ||||
| 84 | .= q{Can't locate } | ||||
| 85 | . _or_list(@list) | ||||
| 86 | . " in \@INC (\@INC contains: @INC)."; | ||||
| 87 | _croak($err); | ||||
| 88 | } | ||||
| 89 | |||||
| 90 | sub _version_fail_re { | ||||
| 91 | my $name = shift; | ||||
| 92 | my $vers = shift; | ||||
| 93 | |||||
| 94 | return qr/\Q$name\E version \Q$vers\E required--this is only version/; | ||||
| 95 | } | ||||
| 96 | |||||
| 97 | # spent 37µs (12+25) within Class::Load::_nonexistent_fail_re which was called:
# once (12µs+25µs) by Class::Load::load_optional_class at line 131 | ||||
| 98 | 1 | 300ns | my $name = shift; | ||
| 99 | |||||
| 100 | 1 | 800ns | 1 | 15µs | my $file = module_notional_filename($name); # spent 15µs making 1 call to Module::Runtime::module_notional_filename |
| 101 | 1 | 19µs | 2 | 10µs | return qr/Can't locate \Q$file\E in \@INC/; # spent 7µs making 1 call to Class::Load::CORE:regcomp
# spent 2µs making 1 call to Class::Load::CORE:qr |
| 102 | } | ||||
| 103 | |||||
| 104 | sub _or_list { | ||||
| 105 | return $_[0] if @_ == 1; | ||||
| 106 | |||||
| 107 | return join ' or ', @_ if @_ ==2; | ||||
| 108 | |||||
| 109 | my $last = pop; | ||||
| 110 | |||||
| 111 | my $list = join ', ', @_; | ||||
| 112 | $list .= ', or ' . $last; | ||||
| 113 | |||||
| 114 | return $list; | ||||
| 115 | } | ||||
| 116 | |||||
| 117 | # spent 284µs (20+265) within Class::Load::load_optional_class which was called:
# once (20µs+265µs) by App::Cmd::Setup::_make_app_class at line 111 of App/Cmd/Setup.pm | ||||
| 118 | 1 | 500ns | my $class = shift; | ||
| 119 | 1 | 300ns | my $options = shift; | ||
| 120 | |||||
| 121 | 1 | 2µs | 1 | 18µs | check_module_name($class); # spent 18µs making 1 call to Module::Runtime::check_module_name |
| 122 | |||||
| 123 | 1 | 7µs | 1 | 208µs | my ($res, $e) = try_load_class($class, $options); # spent 208µs making 1 call to Class::Load::try_load_class |
| 124 | 1 | 200ns | return 1 if $res; | ||
| 125 | |||||
| 126 | 1 | 200ns | return 0 | ||
| 127 | if $options | ||||
| 128 | && defined $options->{-version} | ||||
| 129 | && $e =~ _version_fail_re($class, $options->{-version}); | ||||
| 130 | |||||
| 131 | 1 | 11µs | 3 | 39µs | return 0 # spent 37µs making 1 call to Class::Load::_nonexistent_fail_re
# spent 1µs making 1 call to Class::Load::CORE:regcomp
# spent 600ns making 1 call to Class::Load::CORE:match |
| 132 | if $e =~ _nonexistent_fail_re($class); | ||||
| 133 | |||||
| 134 | _croak($e); | ||||
| 135 | } | ||||
| 136 | |||||
| 137 | sub try_load_class { | ||||
| 138 | 10 | 2µs | my $class = shift; | ||
| 139 | 10 | 3µs | my $options = shift; | ||
| 140 | |||||
| 141 | 10 | 11µs | 10 | 131µs | check_module_name($class); # spent 131µs making 10 calls to Module::Runtime::check_module_name, avg 13µs/call |
| 142 | |||||
| 143 | 10 | 3µs | local $@; | ||
| 144 | 10 | 4µs | undef $ERROR; | ||
| 145 | |||||
| 146 | 10 | 49µs | 10 | 28µs | if (is_class_loaded($class)) { # spent 28µs making 10 calls to Class::Load::XS::is_class_loaded, avg 3µs/call |
| 147 | # We need to check this here rather than in is_class_loaded() because | ||||
| 148 | # we want to return the error message for a failed version check, but | ||||
| 149 | # is_class_loaded just returns true/false. | ||||
| 150 | 3 | 8µs | return 1 unless $options && defined $options->{-version}; | ||
| 151 | return try { | ||||
| 152 | $class->VERSION($options->{-version}); | ||||
| 153 | 1; | ||||
| 154 | } | ||||
| 155 | catch { | ||||
| 156 | _error($_); | ||||
| 157 | }; | ||||
| 158 | } | ||||
| 159 | |||||
| 160 | 7 | 11µs | 7 | 115µs | my $file = module_notional_filename($class); # spent 115µs making 7 calls to Module::Runtime::module_notional_filename, avg 16µs/call |
| 161 | # This says "our diagnostics of the package | ||||
| 162 | # say perl's INC status about the file being loaded are | ||||
| 163 | # wrong", so we delete it from %INC, so when we call require(), | ||||
| 164 | # perl will *actually* try reloading the file. | ||||
| 165 | # | ||||
| 166 | # If the file is already in %INC, it won't retry, | ||||
| 167 | # And on 5.8, it won't fail either! | ||||
| 168 | # | ||||
| 169 | # The extra benefit of this trick, is it helps even on | ||||
| 170 | # 5.10, as instead of dying with "Compilation failed", | ||||
| 171 | # it will die with the actual error, and that's a win-win. | ||||
| 172 | 7 | 7µs | delete $INC{$file}; | ||
| 173 | return try { | ||||
| 174 | 7 | 16µs | local $SIG{__DIE__} = 'DEFAULT'; | ||
| 175 | 7 | 7µs | if ($options && defined $options->{-version}) { | ||
| 176 | use_module($class, $options->{-version}); | ||||
| 177 | } | ||||
| 178 | else { | ||||
| 179 | 7 | 10µs | 7 | 49.4ms | require_module($class); # spent 49.4ms making 7 calls to Module::Runtime::require_module, avg 7.06ms/call |
| 180 | } | ||||
| 181 | 6 | 21µs | 1; | ||
| 182 | } | ||||
| 183 | catch { | ||||
| 184 | 1 | 4µs | 1 | 12µs | _error($_); # spent 12µs making 1 call to Class::Load::_error |
| 185 | 7 | 64µs | 14 | 49.7ms | }; # spent 49.7ms making 7 calls to Try::Tiny::try, avg 7.10ms/call
# spent 29µs making 7 calls to Try::Tiny::catch, avg 4µs/call |
| 186 | } | ||||
| 187 | |||||
| 188 | # spent 12µs (8+4) within Class::Load::_error which was called:
# once (8µs+4µs) by Class::Load::catch {...} at line 184 | ||||
| 189 | 1 | 500ns | my $e = shift; | ||
| 190 | |||||
| 191 | 1 | 8µs | 1 | 4µs | $e =~ s/ at .+?Runtime\.pm line [0-9]+\.$//; # spent 4µs making 1 call to Class::Load::CORE:subst |
| 192 | 1 | 700ns | chomp $e; | ||
| 193 | |||||
| 194 | 1 | 400ns | $ERROR = $e; | ||
| 195 | 1 | 300ns | return 0 unless wantarray; | ||
| 196 | 1 | 3µs | return 0, $ERROR; | ||
| 197 | } | ||||
| 198 | |||||
| 199 | sub _croak { | ||||
| 200 | require Carp; | ||||
| 201 | local $Carp::CarpLevel = $Carp::CarpLevel + 2; | ||||
| 202 | Carp::croak(shift); | ||||
| 203 | } | ||||
| 204 | |||||
| 205 | 1 | 5µs | 1; | ||
| 206 | |||||
| 207 | # ABSTRACT: a working (require "Class::Name") and more | ||||
| 208 | |||||
| 209 | __END__ | ||||
# spent 600ns within Class::Load::CORE:match which was called:
# once (600ns+0s) by Class::Load::load_optional_class at line 131 | |||||
# spent 2µs within Class::Load::CORE:qr which was called:
# once (2µs+0s) by Class::Load::_nonexistent_fail_re at line 101 | |||||
sub Class::Load::CORE:regcomp; # opcode | |||||
# spent 4µs within Class::Load::CORE:subst which was called:
# once (4µs+0s) by Class::Load::_error at line 191 |