← Index
NYTProf Performance Profile   « line view »
For starman worker -M FindBin --max-requests 50 --workers 2 --user=kohadev-koha --group kohadev-koha --pid /var/run/koha/kohadev/plack.pid --daemonize --access-log /var/log/koha/kohadev/plack.log --error-log /var/log/koha/kohadev/plack-error.log -E deployment --socket /var/run/koha/kohadev/plack.sock /etc/koha/sites/kohadev/plack.psgi
  Run on Fri Jan 8 13:01:18 2016
Reported on Fri Jan 8 13:01:34 2016

Filename/usr/share/perl5/Class/C3/Componentised.pm
StatementsExecuted 3669 statements in 140ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
55086242ms1.25sClass::C3::Componentised::::ensure_class_loadedClass::C3::Componentised::ensure_class_loaded (recurses: max depth 3, inclusive time 109ms)
1112.57ms2.84msClass::C3::Componentised::::BEGIN@48Class::C3::Componentised::BEGIN@48
1611397µs397µsClass::C3::Componentised::::__ANON__[:199]Class::C3::Componentised::__ANON__[:199]
421128µs69.1msClass::C3::Componentised::::_load_componentsClass::C3::Componentised::_load_components (recurses: max depth 2, inclusive time 37.4ms)
333105µs69.1msClass::C3::Componentised::::load_componentsClass::C3::Componentised::load_components (recurses: max depth 1, inclusive time 24.2ms)
11124µs43µsClass::C3::Componentised::::BEGIN@133Class::C3::Componentised::BEGIN@133
11124µs34µsClass::C3::Componentised::::BEGIN@40Class::C3::Componentised::BEGIN@40
11123µs13.3msClass::C3::Componentised::::load_own_componentsClass::C3::Componentised::load_own_components
11116µs26µsClass::C3::Componentised::::BEGIN@198Class::C3::Componentised::BEGIN@198
11112µs1.61msClass::C3::Componentised::::load_optional_classClass::C3::Componentised::load_optional_class
11111µs18µsClass::C3::Componentised::::BEGIN@41Class::C3::Componentised::BEGIN@41
1119µs9µsClass::C3::Componentised::::BEGIN@50Class::C3::Componentised::BEGIN@50
1117µs7µsClass::C3::Componentised::::BEGIN@51Class::C3::Componentised::BEGIN@51
0000s0sClass::C3::Componentised::::__ANON__[:204]Class::C3::Componentised::__ANON__[:204]
0000s0sClass::C3::Componentised::::ensure_class_foundClass::C3::Componentised::ensure_class_found
0000s0sClass::C3::Componentised::::inject_baseClass::C3::Componentised::inject_base
0000s0sClass::C3::Componentised::::load_optional_componentsClass::C3::Componentised::load_optional_components
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Class::C3::Componentised;
2
3=head1 NAME
4
5Class::C3::Componentised - load mix-ins or components to your C3-based class
6
7=head1 DESCRIPTION
8
9Load mix-ins or components to your C3-based class.
10
11=head1 SYNOPSIS
12
13 package MyModule;
14
15 use strict;
16 use warnings;
17
18 use base 'Class::C3::Componentised';
19
20 sub component_base_class { "MyModule::Component" }
21
22 package main;
23
24 MyModule->load_components( qw/Foo Bar/ );
25 # Will load MyModule::Component::Foo and MyModule::Component::Bar
26
27=head1 DESCRIPTION
28
29This will inject base classes to your module using the L<Class::C3> method
30resolution order.
31
32Please note: these are not plugins that can take precedence over methods
33declared in MyModule. If you want something like that, consider
34L<MooseX::Object::Pluggable>.
35
36=head1 METHODS
37
38=cut
39
40252µs244µs
# spent 34µs (24+10) within Class::C3::Componentised::BEGIN@40 which was called: # once (24µs+10µs) by base::import at line 40
use strict;
# spent 34µs making 1 call to Class::C3::Componentised::BEGIN@40 # spent 10µs making 1 call to strict::import
41250µs224µs
# spent 18µs (11+6) within Class::C3::Componentised::BEGIN@41 which was called: # once (11µs+6µs) by base::import at line 41
use warnings;
# spent 18µs making 1 call to Class::C3::Componentised::BEGIN@41 # spent 6µs making 1 call to warnings::import
42
43# This will prime the Class::C3 namespace (either by loading it proper on 5.8
44# or by installing compat shims on 5.10+). A user might have a reasonable
45# expectation that using Class::C3::<something> will give him access to
46# Class::C3 itself, and this module has been providing this historically.
47# Therefore leaving it in indefinitely.
482245µs12.84ms
# spent 2.84ms (2.57+266µs) within Class::C3::Componentised::BEGIN@48 which was called: # once (2.57ms+266µs) by base::import at line 48
use MRO::Compat;
# spent 2.84ms making 1 call to Class::C3::Componentised::BEGIN@48
49
50235µs19µs
# spent 9µs within Class::C3::Componentised::BEGIN@50 which was called: # once (9µs+0s) by base::import at line 50
use Carp ();
# spent 9µs making 1 call to Class::C3::Componentised::BEGIN@50
512617µs17µs
# spent 7µs within Class::C3::Componentised::BEGIN@51 which was called: # once (7µs+0s) by base::import at line 51
use List::Util ();
# spent 7µs making 1 call to Class::C3::Componentised::BEGIN@51
52
5311µsour $VERSION = '1.001000';
54
55119µs15µs$VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
# spent 5µs making 1 call to Class::C3::Componentised::CORE:match
56
57115µs18µsmy $invalid_class = qr/(?: \b:\b | \:{3,} | \:\:$ )/x;
# spent 8µs making 1 call to Class::C3::Componentised::CORE:qr
58
59=head2 load_components( @comps )
60
61Loads the given components into the current module. If a module begins with a
62C<+> character, it is taken to be a fully qualified class name, otherwise
63C<< $class->component_base_class >> is prepended to it.
64
65Calling this will call C<Class::C3::reinitialize>.
66
67=cut
68
69
# spent 69.1ms (105µs+69.0) within Class::C3::Componentised::load_components which was called 3 times, avg 23.0ms/call: # once (47µs+69.1ms) by base::import at line 8 of DBIx/Class/Core.pm # once (24µs+-24µs) by DBIx::Class::ResultSourceProxy::Table::BEGIN@8 at line 9 of DBIx/Class/ResultSource/Table.pm # once (34µs+-34µs) by Class::C3::Componentised::ensure_class_loaded at line 9 of DBIx/Class/Relationship/Helpers.pm
sub load_components {
7032µs my $class = shift;
711141µs2211µs $class->_load_components( map {
# spent 9µs making 11 calls to DBIx::Class::component_base_class, avg 791ns/call # spent 2µs making 11 calls to Class::C3::Componentised::CORE:match, avg 227ns/call
721125µs114µs /^\+(.*)$/
# spent 4µs making 11 calls to Class::C3::Componentised::CORE:match, avg 400ns/call
73 ? $1
74 : join ('::', $class->component_base_class, $_)
75335µs369.1ms } grep { $_ !~ /^#/ } @_
# spent 93.2ms making 3 calls to Class::C3::Componentised::_load_components, avg 31.1ms/call, recursion: max depth 2, sum of overlapping time 24.1ms
76 );
77}
78
79=head2 load_own_components( @comps )
80
81Similar to L<load_components>, but assumes every class is C<"$class::$comp">.
82
83=cut
84
85
# spent 13.3ms (23µs+13.3) within Class::C3::Componentised::load_own_components which was called: # once (23µs+13.3ms) by Class::C3::Componentised::ensure_class_loaded at line 8 of DBIx/Class/Relationship.pm
sub load_own_components {
861700ns my $class = shift;
87623µs61µs $class->_load_components( map { "${class}::$_" } grep { $_ !~ /^#/ } @_ );
# spent 1µs making 5 calls to Class::C3::Componentised::CORE:match, avg 280ns/call # spent 13.3ms making 1 call to Class::C3::Componentised::_load_components, recursion: max depth 1, sum of overlapping time 13.3ms
88}
89
90
# spent 69.1ms (128µs+68.9) within Class::C3::Componentised::_load_components which was called 4 times, avg 17.3ms/call: # 3 times (91µs+69.0ms) by Class::C3::Componentised::load_components at line 75, avg 23.0ms/call # once (36µs+-36µs) by Class::C3::Componentised::load_own_components at line 87
sub _load_components {
9142µs my $class = shift;
9242µs return unless @_;
93
94458µs160s $class->ensure_class_loaded($_) for @_;
# spent 103ms making 16 calls to Class::C3::Componentised::ensure_class_loaded, avg 6.41ms/call, recursion: max depth 3, sum of overlapping time 103ms
95430µs43.74ms $class->inject_base($class => @_);
# spent 3.74ms making 4 calls to DBIx::Class::Componentised::inject_base, avg 935µs/call
96421µs48µs Class::C3::reinitialize();
# spent 8µs making 4 calls to MRO::Compat::__ANON__[MRO/Compat.pm:41], avg 2µs/call
97}
98
99=head2 load_optional_components
100
101As L<load_components>, but will silently ignore any components that cannot be
102found.
103
104=cut
105
106sub load_optional_components {
107 my $class = shift;
108 $class->_load_components( grep
109 { $class->load_optional_class( $_ ) }
110 ( map
111 { /^\+(.*)$/
112 ? $1
113 : join ('::', $class->component_base_class, $_)
114 }
115 grep { $_ !~ /^#/ } @_
116 )
117 );
118}
119
120=head2 ensure_class_loaded
121
122Given a class name, tests to see if it is already loaded or otherwise
123defined. If it is not yet loaded, the package is require'd, and an exception
124is thrown if the class is still not loaded.
125
126 BUG: For some reason, packages with syntax errors are added to %INC on
127 require
128=cut
129
130
# spent 1.25s (242ms+1.01) within Class::C3::Componentised::ensure_class_loaded which was called 550 times, avg 2.27ms/call: # 176 times (1.59ms+7.46ms) by DBIx::Class::AccessorGroup::get_component_class at line 19 of DBIx/Class/AccessorGroup.pm, avg 51µs/call # 174 times (208ms+972ms) by DBIx::Class::Schema::load_namespaces at line 239 of DBIx/Class/Schema.pm, avg 6.78ms/call # 174 times (990µs+-990µs) by DBIx::Class::ResultSourceProxy::Table::table at line 87 of DBIx/Class/ResultSourceProxy/Table.pm, avg 0s/call # 16 times (16.8ms+-16.8ms) by Class::C3::Componentised::_load_components at line 94, avg 0s/call # 6 times (45µs+0s) by DBIx::Class::ResultSet::result_class at line 1558 of DBIx/Class/ResultSet.pm, avg 7µs/call # 2 times (1.34ms+-1.34ms) by DBIx::Class::Relationship::BelongsTo::belongs_to at line 43 of DBIx/Class/Relationship/BelongsTo.pm, avg 0s/call # once (11.9ms+48.3ms) by Try::Tiny::try at line 807 of DBIx/Class/Schema.pm # once (1.28ms+318µs) by Class::C3::Componentised::load_optional_class at line 227
sub ensure_class_loaded {
131550282µs my ($class, $f_class) = @_;
132
1332487µs263µs
# spent 43µs (24+20) within Class::C3::Componentised::BEGIN@133 which was called: # once (24µs+20µs) by base::import at line 133
no strict 'refs';
# spent 43µs making 1 call to Class::C3::Componentised::BEGIN@133 # spent 20µs making 1 call to strict::unimport
134
135 # ripped from Class::Inspector for speed
136 # note that the order is important (faster items are first)
1375501.66ms return if ${"${f_class}::VERSION"};
138
1395501.90ms return if @{"${f_class}::ISA"};
140
141192775µs my $file = (join ('/', split ('::', $f_class) ) ) . '.pm';
142192210µs return if $INC{$file};
143
144192467µs for ( keys %{"${f_class}::"} ) {
145387573µs return if ( *{"${f_class}::$_"}{CODE} );
146 }
147
148 # require always returns true on success
149 # ill-behaved modules might very well obliterate $_
150576131ms eval { local $_; require($file) } or do {
151
152 $@ = "Invalid class name '$f_class'" if $f_class =~ $invalid_class;
153
154 if ($class->can('throw_exception')) {
155 $class->throw_exception($@);
156 } else {
157 Carp::croak $@;
158 }
159 };
160
161192666µs return;
162}
163
164=head2 ensure_class_found
165
166Returns true if the specified class is installed or already loaded, false
167otherwise.
168
169Note that the underlying mechanism (Class::Inspector->installed()) used by this
170sub will not, at the time of writing, correctly function when @INC includes
171coderefs. Since PAR relies upon coderefs in @INC, this function should be
172avoided in modules that are likely to be included within a PAR.
173
174=cut
175
176sub ensure_class_found {
177 #my ($class, $f_class) = @_;
178 require Class::Inspector;
179 return Class::Inspector->loaded($_[1]) ||
180 Class::Inspector->installed($_[1]);
181}
182
183
184=head2 inject_base
185
186Does the actual magic of adjusting @ISA on the target module.
187
188=cut
189
190sub inject_base {
19142µs my $class = shift;
1924600ns my $target = shift;
193
194423µs411µs mro::set_mro($target, 'c3');
# spent 11µs making 4 calls to mro::set_mro, avg 3µs/call
195
19646µs for my $comp (reverse @_) {
197166µs my $apply = do {
1982500µs237µs
# spent 26µs (16+11) within Class::C3::Componentised::BEGIN@198 which was called: # once (16µs+11µs) by base::import at line 198
no strict 'refs';
# spent 26µs making 1 call to Class::C3::Componentised::BEGIN@198 # spent 11µs making 1 call to strict::unimport
19932446µs
# spent 397µs within Class::C3::Componentised::__ANON__[/usr/share/perl5/Class/C3/Componentised.pm:199] which was called 16 times, avg 25µs/call: # 16 times (397µs+0s) by DBIx::Class::Componentised::inject_base at line 208, avg 25µs/call
sub { unshift ( @{"${target}::ISA"}, $comp ) };
200 };
20116198µs1636µs unless ($target eq $comp || $target->isa($comp)) {
# spent 36µs making 16 calls to UNIVERSAL::isa, avg 2µs/call
202162µs our %APPLICATOR_FOR;
2031697µs3263µs if (my $apply_class
# spent 39µs making 16 calls to List::Util::first, avg 2µs/call # spent 24µs making 16 calls to mro::get_linear_isa, avg 1µs/call
2048345µs = List::Util::first { $APPLICATOR_FOR{$_} } @{mro::get_linear_isa($comp)}
205 ) {
206 $APPLICATOR_FOR{$apply_class}->_apply_component_to_class($comp,$target,$apply);
207 } else {
2081616µs16397µs $apply->();
# spent 397µs making 16 calls to Class::C3::Componentised::__ANON__[Class/C3/Componentised.pm:199], avg 25µs/call
209 }
210 }
211 }
212}
213
214=head2 load_optional_class
215
216Returns a true value if the specified class is installed and loaded
217successfully, throws an exception if the class is found but not loaded
218successfully, and false if the class is not installed
219
220=cut
221
222
# spent 1.61ms (12µs+1.60) within Class::C3::Componentised::load_optional_class which was called: # once (12µs+1.60ms) by DBIx::Class::Storage::DBI::_determine_driver at line 1264 of DBIx/Class/Storage/DBI.pm
sub load_optional_class {
2231700ns my ($class, $f_class) = @_;
224
225 # ensure_class_loaded either returns a () (*not* true) or throws
22615µs eval {
22716µs11.60ms $class->ensure_class_loaded($f_class);
# spent 1.60ms making 1 call to Class::C3::Componentised::ensure_class_loaded
2281400ns 1;
229 } && return 1;
230
231 my $err = $@; # so we don't lose it
232
233 if ($f_class =~ $invalid_class) {
234 $err = "Invalid class name '$f_class'";
235 }
236 else {
237 my $fn = quotemeta( (join ('/', split ('::', $f_class) ) ) . '.pm' );
238 return 0 if ($err =~ /Can't locate ${fn} in \@INC/ );
239 }
240
241 if ($class->can('throw_exception')) {
242 $class->throw_exception($err);
243 }
244 else {
245 die $err;
246 }
247}
248
249=head1 AUTHORS
250
251Matt S. Trout and the L<DBIx::Class team|DBIx::Class/CONTRIBUTORS>
252
253Pulled out into separate module by Ash Berlin C<< <ash@cpan.org> >>
254
255Optimizations and overall bolt-tightening by Peter "ribasushi" Rabbitson
256C<< <ribasushi@cpan.org> >>
257
258=head1 COPYRIGHT
259
260Copyright (c) 2006 - 2011 the Class::C3::Componentised L</AUTHORS> as listed
261above.
262
263=head1 LICENSE
264
265You may distribute this code under the same terms as Perl itself.
266
267=cut
268
269110µs1;