← Index
NYTProf Performance Profile   « line view »
For /home/ss5/perl5/perlbrew/perls/perl-5.22.0/bin/benchmarkanything-storage
  Run on Mon Jan 29 16:55:34 2018
Reported on Mon Jan 29 16:57:06 2018

Filename/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Class/Load.pm
StatementsExecuted 23 statements in 880µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111654µs752µsClass::Load::::BEGIN@9Class::Load::BEGIN@9
111605µs1.73msClass::Load::::BEGIN@11Class::Load::BEGIN@11
111467µs4.47msClass::Load::::BEGIN@10Class::Load::BEGIN@10
11110µs12µsMoose::::BEGIN@1 Moose::BEGIN@1
1116µs11µsClass::Load::::BEGIN@12Class::Load::BEGIN@12
1114µs9µsMoose::::BEGIN@2 Moose::BEGIN@2
1114µs28µsClass::Load::::BEGIN@13Class::Load::BEGIN@13
0000s0sClass::Load::::__ANON__[:149]Class::Load::__ANON__[:149]
0000s0sClass::Load::::__ANON__[:152]Class::Load::__ANON__[:152]
0000s0sClass::Load::::__ANON__[:177]Class::Load::__ANON__[:177]
0000s0sClass::Load::::__ANON__[:180]Class::Load::__ANON__[:180]
0000s0sClass::Load::::_croakClass::Load::_croak
0000s0sClass::Load::::_errorClass::Load::_error
0000s0sClass::Load::::_nonexistent_fail_reClass::Load::_nonexistent_fail_re
0000s0sClass::Load::::_or_listClass::Load::_or_list
0000s0sClass::Load::::_version_fail_reClass::Load::_version_fail_re
0000s0sClass::Load::::load_classClass::Load::load_class
0000s0sClass::Load::::load_first_existing_classClass::Load::load_first_existing_class
0000s0sClass::Load::::load_optional_classClass::Load::load_optional_class
0000s0sClass::Load::::try_load_classClass::Load::try_load_class
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1214µs214µs
# spent 12µs (10+2) within Moose::BEGIN@1 which was called: # once (10µs+2µs) by Moose::BEGIN@12 at line 1
use strict;
# spent 12µs making 1 call to Moose::BEGIN@1 # spent 2µs making 1 call to strict::import
2228µs214µs
# spent 9µs (4+5) within Moose::BEGIN@2 which was called: # once (4µs+5µs) by Moose::BEGIN@12 at line 2
use warnings;
# spent 9µs making 1 call to Moose::BEGIN@2 # spent 5µs making 1 call to warnings::import
3package Class::Load; # git description: v0.22-9-g29ebb54
4# ABSTRACT: A working (require "Class::Name") and more
5# KEYWORDS: class module load require use runtime
6
71300nsour $VERSION = '0.23';
8
9255µs2802µs
# spent 752µs (654+98) within Class::Load::BEGIN@9 which was called: # once (654µs+98µs) by Moose::BEGIN@12 at line 9
use base 'Exporter';
# spent 752µs making 1 call to Class::Load::BEGIN@9 # spent 50µs making 1 call to base::import
10263µs14.47ms
# spent 4.47ms (467µs+4.00) within Class::Load::BEGIN@10 which was called: # once (467µs+4.00ms) by Moose::BEGIN@12 at line 10
use Data::OptList ();
# spent 4.47ms making 1 call to Class::Load::BEGIN@10
113111µs21.74ms
# spent 1.73ms (605µs+1.13) within Class::Load::BEGIN@11 which was called: # once (605µs+1.13ms) by Moose::BEGIN@12 at line 11
use Module::Implementation 0.04;
# spent 1.73ms making 1 call to Class::Load::BEGIN@11 # spent 10µs making 1 call to UNIVERSAL::VERSION
12321µs216µs
# spent 11µs (6+5) within Class::Load::BEGIN@12 which was called: # once (6µs+5µs) by Moose::BEGIN@12 at line 12
use Module::Runtime 0.012 ();
# spent 11µs making 1 call to Class::Load::BEGIN@12 # spent 5µs making 1 call to UNIVERSAL::VERSION
132573µs251µs
# spent 28µs (4+24) within Class::Load::BEGIN@13 which was called: # once (4µs+24µs) by Moose::BEGIN@12 at line 13
use Try::Tiny;
# spent 28µs making 1 call to Class::Load::BEGIN@13 # spent 24µs making 1 call to Exporter::import
14
15{
1624µs119µs my $loader = Module::Implementation::build_loader_sub(
# spent 19µs making 1 call to Module::Implementation::build_loader_sub
17 implementations => [ 'XS', 'PP' ],
18 symbols => ['is_class_loaded'],
19 );
20
2113µs1473µs $loader->();
22}
23
2411µsour @EXPORT_OK = qw/load_class load_optional_class try_load_class is_class_loaded load_first_existing_class/;
2511µsour %EXPORT_TAGS = (
26 all => \@EXPORT_OK,
27);
28
29our $ERROR;
30
31sub load_class {
32 my $class = shift;
33 my $options = shift;
34
35 my ($res, $e) = try_load_class($class, $options);
36 return $class if $res;
37
38 _croak($e);
39}
40
41sub load_first_existing_class {
42 my $classes = Data::OptList::mkopt(\@_)
43 or return;
44
45 foreach my $class (@{$classes}) {
46 Module::Runtime::check_module_name($class->[0]);
47 }
48
49 for my $class (@{$classes}) {
50 my ($name, $options) = @{$class};
51
52 # We need to be careful not to pass an undef $options to this sub,
53 # since the XS version will blow up if that happens.
54 return $name if is_class_loaded($name, ($options ? $options : ()));
55
56 my ($res, $e) = try_load_class($name, $options);
57
58 return $name if $res;
59
60 my $file = Module::Runtime::module_notional_filename($name);
61
62 next if $e =~ /^Can't locate \Q$file\E in \@INC/;
63 next
64 if $options
65 && defined $options->{-version}
66 && $e =~ _version_fail_re($name, $options->{-version});
67
68 _croak("Couldn't load class ($name) because: $e");
69 }
70
71 my @list = map {
72 $_->[0]
73 . ( $_->[1] && defined $_->[1]{-version}
74 ? " (version >= $_->[1]{-version})"
75 : q{} )
76 } @{$classes};
77
78 my $err
79 .= q{Can't locate }
80 . _or_list(@list)
81 . " in \@INC (\@INC contains: @INC).";
82 _croak($err);
83}
84
85sub _version_fail_re {
86 my $name = shift;
87 my $vers = shift;
88
89 return qr/\Q$name\E version \Q$vers\E required--this is only version/;
90}
91
92sub _nonexistent_fail_re {
93 my $name = shift;
94
95 my $file = Module::Runtime::module_notional_filename($name);
96 return qr/Can't locate \Q$file\E in \@INC/;
97}
98
99sub _or_list {
100 return $_[0] if @_ == 1;
101
102 return join ' or ', @_ if @_ ==2;
103
104 my $last = pop;
105
106 my $list = join ', ', @_;
107 $list .= ', or ' . $last;
108
109 return $list;
110}
111
112sub load_optional_class {
113 my $class = shift;
114 my $options = shift;
115
116 Module::Runtime::check_module_name($class);
117
118 my ($res, $e) = try_load_class($class, $options);
119 return 1 if $res;
120
121 return 0
122 if $options
123 && defined $options->{-version}
124 && $e =~ _version_fail_re($class, $options->{-version});
125
126 return 0
127 if $e =~ _nonexistent_fail_re($class);
128
129 _croak($e);
130}
131
132sub try_load_class {
133 my $class = shift;
134 my $options = shift;
135
136 Module::Runtime::check_module_name($class);
137
138 local $@;
139 undef $ERROR;
140
141 if (is_class_loaded($class)) {
142 # We need to check this here rather than in is_class_loaded() because
143 # we want to return the error message for a failed version check, but
144 # is_class_loaded just returns true/false.
145 return 1 unless $options && defined $options->{-version};
146 return try {
147 $class->VERSION($options->{-version});
148 1;
149 }
150 catch {
151 _error($_);
152 };
153 }
154
155 my $file = Module::Runtime::module_notional_filename($class);
156 # This says "our diagnostics of the package
157 # say perl's INC status about the file being loaded are
158 # wrong", so we delete it from %INC, so when we call require(),
159 # perl will *actually* try reloading the file.
160 #
161 # If the file is already in %INC, it won't retry,
162 # And on 5.8, it won't fail either!
163 #
164 # The extra benefit of this trick, is it helps even on
165 # 5.10, as instead of dying with "Compilation failed",
166 # it will die with the actual error, and that's a win-win.
167 delete $INC{$file};
168 return try {
169 local $SIG{__DIE__} = 'DEFAULT';
170 if ($options && defined $options->{-version}) {
171 Module::Runtime::use_module($class, $options->{-version});
172 }
173 else {
174 Module::Runtime::require_module($class);
175 }
176 1;
177 }
178 catch {
179 _error($_);
180 };
181}
182
183sub _error {
184 my $e = shift;
185
186 $e =~ s/ at .+?Runtime\.pm line [0-9]+\.$//;
187 chomp $e;
188
189 $ERROR = $e;
190 return 0 unless wantarray;
191 return 0, $ERROR;
192}
193
194sub _croak {
195 require Carp;
196 local $Carp::CarpLevel = $Carp::CarpLevel + 2;
197 Carp::croak(shift);
198}
199
20014µs1;
201
202__END__