← Index
NYTProf Performance Profile   « line view »
For svc/members/upsert
  Run on Tue Jan 13 11:50:22 2015
Reported on Tue Jan 13 12:09:47 2015

Filename/usr/share/perl5/Class/Load.pm
StatementsExecuted 26 statements in 2.51ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.86ms10.5msClass::Load::::BEGIN@19 Class::Load::BEGIN@19
1111.28ms6.59msClass::Load::::BEGIN@10 Class::Load::BEGIN@10
11114µs26µsDateTime::TimeZone::Local::::BEGIN@1DateTime::TimeZone::Local::BEGIN@1
11110µs18µsClass::Load::::BEGIN@11 Class::Load::BEGIN@11
11110µs39µsClass::Load::::BEGIN@12 Class::Load::BEGIN@12
1117µs71µsClass::Load::::BEGIN@9 Class::Load::BEGIN@9
1117µs11µsDateTime::TimeZone::Local::::BEGIN@2DateTime::TimeZone::Local::BEGIN@2
1117µs33µsClass::Load::::BEGIN@18 Class::Load::BEGIN@18
0000s0sClass::Load::::__ANON__[:155] Class::Load::__ANON__[:155]
0000s0sClass::Load::::__ANON__[:158] Class::Load::__ANON__[:158]
0000s0sClass::Load::::__ANON__[:183] Class::Load::__ANON__[:183]
0000s0sClass::Load::::__ANON__[:186] Class::Load::__ANON__[:186]
0000s0sClass::Load::::_croak Class::Load::_croak
0000s0sClass::Load::::_error Class::Load::_error
0000s0sClass::Load::::_nonexistent_fail_re Class::Load::_nonexistent_fail_re
0000s0sClass::Load::::_or_list Class::Load::_or_list
0000s0sClass::Load::::_version_fail_re Class::Load::_version_fail_re
0000s0sClass::Load::::load_class Class::Load::load_class
0000s0sClass::Load::::load_first_existing_class Class::Load::load_first_existing_class
0000s0sClass::Load::::load_optional_class Class::Load::load_optional_class
0000s0sClass::Load::::try_load_class Class::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
1223µs238µs
# spent 26µs (14+12) within DateTime::TimeZone::Local::BEGIN@1 which was called: # once (14µs+12µs) by DateTime::TimeZone::Local::BEGIN@6 at line 1
use strict;
# spent 26µs making 1 call to DateTime::TimeZone::Local::BEGIN@1 # spent 12µs making 1 call to strict::import
2246µs215µs
# spent 11µs (7+4) within DateTime::TimeZone::Local::BEGIN@2 which was called: # once (7µs+4µs) by DateTime::TimeZone::Local::BEGIN@6 at line 2
use warnings;
# spent 11µs making 1 call to DateTime::TimeZone::Local::BEGIN@2 # spent 4µs making 1 call to warnings::import
3package Class::Load;
4# git description: v0.21-14-g8465ff7
51300ns$Class::Load::VERSION = '0.22';
6# ABSTRACT: A working (require "Class::Name") and more
7# KEYWORDS: class module load require use runtime
8
9234µs2134µs
# spent 71µs (7+63) within Class::Load::BEGIN@9 which was called: # once (7µs+63µs) by DateTime::TimeZone::Local::BEGIN@6 at line 9
use base 'Exporter';
# spent 71µs making 1 call to Class::Load::BEGIN@9 # spent 63µs making 1 call to base::import
102751µs26.65ms
# spent 6.59ms (1.28+5.31) within Class::Load::BEGIN@10 which was called: # once (1.28ms+5.31ms) by DateTime::TimeZone::Local::BEGIN@6 at line 10
use Data::OptList 'mkopt';
# spent 6.59ms making 1 call to Class::Load::BEGIN@10 # spent 58µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:270]
11344µs226µs
# spent 18µs (10+8) within Class::Load::BEGIN@11 which was called: # once (10µs+8µs) by DateTime::TimeZone::Local::BEGIN@6 at line 11
use Module::Implementation 0.04;
# spent 18µs making 1 call to Class::Load::BEGIN@11 # spent 8µs making 1 call to UNIVERSAL::VERSION
1213µs122µs
# spent 39µs (10+30) within Class::Load::BEGIN@12 which was called: # once (10µs+30µs) by DateTime::TimeZone::Local::BEGIN@6 at line 17
use Module::Runtime 0.012 qw(
# spent 22µs making 1 call to Module::Runtime::import
13 check_module_name
14 module_notional_filename
15 require_module
16 use_module
17232µs246µs);
# spent 39µs making 1 call to Class::Load::BEGIN@12 # spent 7µs making 1 call to UNIVERSAL::VERSION
18221µs259µs
# spent 33µs (7+26) within Class::Load::BEGIN@18 which was called: # once (7µs+26µs) by DateTime::TimeZone::Local::BEGIN@6 at line 18
use Try::Tiny;
# spent 33µs making 1 call to Class::Load::BEGIN@18 # spent 26µs making 1 call to Exporter::import
1921.53ms210.7ms
# spent 10.5ms (1.86+8.63) within Class::Load::BEGIN@19 which was called: # once (1.86ms+8.63ms) by DateTime::TimeZone::Local::BEGIN@6 at line 19
use namespace::clean;
# spent 10.5ms making 1 call to Class::Load::BEGIN@19 # spent 226µs making 1 call to namespace::clean::import
20
21{
2223µs116µs my $loader = Module::Implementation::build_loader_sub(
# spent 16µs making 1 call to Module::Implementation::build_loader_sub
23 implementations => [ 'XS', 'PP' ],
24 symbols => ['is_class_loaded'],
25 );
26
2713µs11.09ms $loader->();
28}
29
301900nsour @EXPORT_OK = qw/load_class load_optional_class try_load_class is_class_loaded load_first_existing_class/;
3111µsour %EXPORT_TAGS = (
32 all => \@EXPORT_OK,
33);
34
351100nsour $ERROR;
36
37sub load_class {
38 my $class = shift;
39 my $options = shift;
40
41 my ($res, $e) = try_load_class($class, $options);
42 return $class if $res;
43
44 _croak($e);
45}
46
47sub load_first_existing_class {
48 my $classes = Data::OptList::mkopt(\@_)
49 or return;
50
51 foreach my $class (@{$classes}) {
52 check_module_name($class->[0]);
53 }
54
55 for my $class (@{$classes}) {
56 my ($name, $options) = @{$class};
57
58 # We need to be careful not to pass an undef $options to this sub,
59 # since the XS version will blow up if that happens.
60 return $name if is_class_loaded($name, ($options ? $options : ()));
61
62 my ($res, $e) = try_load_class($name, $options);
63
64 return $name if $res;
65
66 my $file = module_notional_filename($name);
67
68 next if $e =~ /^Can't locate \Q$file\E in \@INC/;
69 next
70 if $options
71 && defined $options->{-version}
72 && $e =~ _version_fail_re($name, $options->{-version});
73
74 _croak("Couldn't load class ($name) because: $e");
75 }
76
77 my @list = map {
78 $_->[0]
79 . ( $_->[1] && defined $_->[1]{-version}
80 ? " (version >= $_->[1]{-version})"
81 : q{} )
82 } @{$classes};
83
84 my $err
85 .= q{Can't locate }
86 . _or_list(@list)
87 . " in \@INC (\@INC contains: @INC).";
88 _croak($err);
89}
90
91sub _version_fail_re {
92 my $name = shift;
93 my $vers = shift;
94
95 return qr/\Q$name\E version \Q$vers\E required--this is only version/;
96}
97
98sub _nonexistent_fail_re {
99 my $name = shift;
100
101 my $file = module_notional_filename($name);
102 return qr/Can't locate \Q$file\E in \@INC/;
103}
104
105sub _or_list {
106 return $_[0] if @_ == 1;
107
108 return join ' or ', @_ if @_ ==2;
109
110 my $last = pop;
111
112 my $list = join ', ', @_;
113 $list .= ', or ' . $last;
114
115 return $list;
116}
117
118sub load_optional_class {
119 my $class = shift;
120 my $options = shift;
121
122 check_module_name($class);
123
124 my ($res, $e) = try_load_class($class, $options);
125 return 1 if $res;
126
127 return 0
128 if $options
129 && defined $options->{-version}
130 && $e =~ _version_fail_re($class, $options->{-version});
131
132 return 0
133 if $e =~ _nonexistent_fail_re($class);
134
135 _croak($e);
136}
137
138sub try_load_class {
139 my $class = shift;
140 my $options = shift;
141
142 check_module_name($class);
143
144 local $@;
145 undef $ERROR;
146
147 if (is_class_loaded($class)) {
148 # We need to check this here rather than in is_class_loaded() because
149 # we want to return the error message for a failed version check, but
150 # is_class_loaded just returns true/false.
151 return 1 unless $options && defined $options->{-version};
152 return try {
153 $class->VERSION($options->{-version});
154 1;
155 }
156 catch {
157 _error($_);
158 };
159 }
160
161 my $file = module_notional_filename($class);
162 # This says "our diagnostics of the package
163 # say perl's INC status about the file being loaded are
164 # wrong", so we delete it from %INC, so when we call require(),
165 # perl will *actually* try reloading the file.
166 #
167 # If the file is already in %INC, it won't retry,
168 # And on 5.8, it won't fail either!
169 #
170 # The extra benefit of this trick, is it helps even on
171 # 5.10, as instead of dying with "Compilation failed",
172 # it will die with the actual error, and that's a win-win.
173 delete $INC{$file};
174 return try {
175 local $SIG{__DIE__} = 'DEFAULT';
176 if ($options && defined $options->{-version}) {
177 use_module($class, $options->{-version});
178 }
179 else {
180 require_module($class);
181 }
182 1;
183 }
184 catch {
185 _error($_);
186 };
187}
188
189sub _error {
190 my $e = shift;
191
192 $e =~ s/ at .+?Runtime\.pm line [0-9]+\.$//;
193 chomp $e;
194
195 $ERROR = $e;
196 return 0 unless wantarray;
197 return 0, $ERROR;
198}
199
200sub _croak {
201 require Carp;
202 local $Carp::CarpLevel = $Carp::CarpLevel + 2;
203 Carp::croak(shift);
204}
205
20614µs1;
207
208113µs1246µs__END__