← 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:50:58 2016
Reported on Fri Jan 8 13:51:27 2016

Filename/usr/share/perl5/Module/Find.pm
StatementsExecuted 3899 statements in 39.3ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
541212.63ms2.63msModule::Find::::CORE:ftdirModule::Find::CORE:ftdir (opcode)
517111.56ms1.56msModule::Find::::CORE:ftereadModule::Find::CORE:fteread (opcode)
69121996µs996µsModule::Find::::CORE:matchModule::Find::CORE:match (opcode)
211863µs45.4msModule::Find::::_findModule::Find::_find
51711799µs799µsModule::Find::::CORE:substModule::Find::CORE:subst (opcode)
11123µs23µsModule::Find::::BEGIN@3Module::Find::BEGIN@3
11117µs70µsModule::Find::::BEGIN@8Module::Find::BEGIN@8
11113µs24µsModule::Find::::BEGIN@4Module::Find::BEGIN@4
11112µs20µsModule::Find::::BEGIN@5Module::Find::BEGIN@5
21110µs45.4msModule::Find::::findallmodModule::Find::findallmod
11110µs10µsModule::Find::::BEGIN@7Module::Find::BEGIN@7
0000s0sModule::Find::::_wantedModule::Find::_wanted
0000s0sModule::Find::::findsubmodModule::Find::findsubmod
0000s0sModule::Find::::followsymlinksModule::Find::followsymlinks
0000s0sModule::Find::::ignoresymlinksModule::Find::ignoresymlinks
0000s0sModule::Find::::setmoduledirsModule::Find::setmoduledirs
0000s0sModule::Find::::useallModule::Find::useall
0000s0sModule::Find::::usesubModule::Find::usesub
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Module::Find;
2
3279µs123µs
# spent 23µs within Module::Find::BEGIN@3 which was called: # once (23µs+0s) by DBIx::Class::Schema::_findallmod at line 3
use 5.006001;
# spent 23µs making 1 call to Module::Find::BEGIN@3
4252µs236µs
# spent 24µs (13+11) within Module::Find::BEGIN@4 which was called: # once (13µs+11µs) by DBIx::Class::Schema::_findallmod at line 4
use strict;
# spent 24µs making 1 call to Module::Find::BEGIN@4 # spent 11µs making 1 call to strict::import
5255µs228µs
# spent 20µs (12+8) within Module::Find::BEGIN@5 which was called: # once (12µs+8µs) by DBIx::Class::Schema::_findallmod at line 5
use warnings;
# spent 20µs making 1 call to Module::Find::BEGIN@5 # spent 8µs making 1 call to warnings::import
6
7228µs110µs
# spent 10µs within Module::Find::BEGIN@7 which was called: # once (10µs+0s) by DBIx::Class::Schema::_findallmod at line 7
use File::Spec;
# spent 10µs making 1 call to Module::Find::BEGIN@7
82994µs2123µs
# spent 70µs (17+53) within Module::Find::BEGIN@8 which was called: # once (17µs+53µs) by DBIx::Class::Schema::_findallmod at line 8
use File::Find;
# spent 70µs making 1 call to Module::Find::BEGIN@8 # spent 53µs making 1 call to Exporter::import
9
101500nsour $VERSION = '0.12';
11
121200nsour $basedir = undef;
131600nsour @results = ();
141200nsour $prune = 0;
151100nsour $followMode = 1;
16
1719µsour @ISA = qw(Exporter);
18
191800nsour @EXPORT = qw(findsubmod findallmod usesub useall setmoduledirs);
20
211300nsour @EXPORT_OK = qw(followsymlinks ignoresymlinks);
22
23=encoding utf-8
24
25=head1 NAME
26
27Module::Find - Find and use installed modules in a (sub)category
28
29=head1 SYNOPSIS
30
31 use Module::Find;
32
33 # use all modules in the Plugins/ directory
34 @found = usesub Mysoft::Plugins;
35
36 # use modules in all subdirectories
37 @found = useall Mysoft::Plugins;
38
39 # find all DBI::... modules
40 @found = findsubmod DBI;
41
42 # find anything in the CGI/ directory
43 @found = findallmod CGI;
44
45 # set your own search dirs (uses @INC otherwise)
46 setmoduledirs(@INC, @plugindirs, $appdir);
47
48 # not exported by default
49 use Module::Find qw(ignoresymlinks followsymlinks);
50
51 # ignore symlinks
52 ignoresymlinks();
53
54 # follow symlinks (default)
55 followsymlinks();
56
57=head1 DESCRIPTION
58
59Module::Find lets you find and use modules in categories. This can be very
60useful for auto-detecting driver or plugin modules. You can differentiate
61between looking in the category itself or in all subcategories.
62
63If you want Module::Find to search in a certain directory on your
64harddisk (such as the plugins directory of your software installation),
65make sure you modify C<@INC> before you call the Module::Find functions.
66
67=head1 FUNCTIONS
68
69=over
70
71=item C<setmoduledirs(@directories)>
72
73Sets the directories to be searched for modules. If not set, Module::Find
74will use @INC. If you use this function, @INC will I<not> be included
75automatically, so add it if you want it. Set to undef to revert to
76default behaviour.
77
78=cut
79
80sub setmoduledirs {
81 return @Module::Find::ModuleDirs = grep { defined } @_;
82}
83
84=item C<@found = findsubmod Module::Category>
85
86Returns modules found in the Module/Category subdirectories of your perl
87installation. E.g. C<findsubmod CGI> will return C<CGI::Session>, but
88not C<CGI::Session::File> .
89
90=cut
91
92sub findsubmod(*) {
93 $prune = 1;
94
95 return _find($_[0]);
96}
97
98=item C<@found = findallmod Module::Category>
99
100Returns modules found in the Module/Category subdirectories of your perl
101installation. E.g. C<findallmod CGI> will return C<CGI::Session> and also
102C<CGI::Session::File> .
103
104=cut
105
106
# spent 45.4ms (10µs+45.4) within Module::Find::findallmod which was called 2 times, avg 22.7ms/call: # 2 times (10µs+45.4ms) by DBIx::Class::Schema::_findallmod at line 168 of DBIx/Class/Schema.pm, avg 22.7ms/call
sub findallmod(*) {
1072700ns $prune = 0;
108
10929µs245.4ms return _find($_[0]);
# spent 45.4ms making 2 calls to Module::Find::_find, avg 22.7ms/call
110}
111
112=item C<@found = usesub Module::Category>
113
114Uses and returns modules found in the Module/Category subdirectories of your perl
115installation. E.g. C<usesub CGI> will return C<CGI::Session>, but
116not C<CGI::Session::File> .
117
118If any module dies during loading, usesub will also die at this point.
119
120=cut
121
122sub usesub(*) {
123 $prune = 1;
124
125 my @r = _find($_[0]);
126
127 foreach my $m (@r) {
128 eval " require $m; import $m ; ";
129 die $@ if $@;
130 }
131
132 return @r;
133}
134
135=item C<@found = useall Module::Category>
136
137Uses and returns modules found in the Module/Category subdirectories of your perl installation. E.g. C<useall CGI> will return C<CGI::Session> and also
138C<CGI::Session::File> .
139
140If any module dies during loading, useall will also die at this point.
141
142=cut
143
144sub useall(*) {
145 $prune = 0;
146
147 my @r = _find($_[0]);
148
149 foreach my $m (@r) {
150 eval " require $m; import $m; ";
151 die $@ if $@;
152 }
153
154 return @r;
155}
156
157# 'wanted' functions for find()
158# you know, this would be a nice application for currying...
159sub _wanted {
16052024.1ms52019.7ms my $name = File::Spec->abs2rel($_, $basedir);
# spent 19.7ms making 520 calls to File::Spec::Unix::abs2rel, avg 38µs/call
1615201.65ms520385µs return unless $name && $name ne File::Spec->curdir();
# spent 385µs making 520 calls to File::Spec::Unix::curdir, avg 741ns/call
162
1635173.08ms5172.18ms if (-d && $prune) {
# spent 2.18ms making 517 calls to Module::Find::CORE:ftdir, avg 4µs/call
164 $File::Find::prune = 1;
165 return;
166 }
167
1685173.70ms10342.35ms return unless /\.pm$/ && -r;
# spent 1.56ms making 517 calls to Module::Find::CORE:fteread, avg 3µs/call # spent 790µs making 517 calls to Module::Find::CORE:match, avg 2µs/call
169
1705171.53ms517799µs $name =~ s|\.pm$||;
# spent 799µs making 517 calls to Module::Find::CORE:subst, avg 2µs/call
1715171.68ms517583µs $name = join('::', File::Spec->splitdir($name));
# spent 583µs making 517 calls to File::Spec::Unix::splitdir, avg 1µs/call
172
173517469µs push @results, $name;
174}
175
176
177# helper functions for finding files
178
179
# spent 45.4ms (863µs+44.5) within Module::Find::_find which was called 2 times, avg 22.7ms/call: # 2 times (863µs+44.5ms) by Module::Find::findallmod at line 109, avg 22.7ms/call
sub _find(*) {
1802900ns my ($category) = @_;
1812700ns return undef unless defined $category;
182
183232µs423µs my $dir = File::Spec->catdir(split(/::/, $category));
# spent 21µs making 2 calls to File::Spec::Unix::catdir, avg 11µs/call # spent 2µs making 2 calls to File::Spec::Unix::canonpath, avg 1µs/call
184
1852500ns my @dirs;
18622µs if (@Module::Find::ModuleDirs) {
187 @dirs = map { File::Spec->catdir($_, $dir) }
188 @Module::Find::ModuleDirs;
189 } else {
19026109µs4879µs @dirs = map { File::Spec->catdir($_, $dir) } @INC;
# spent 68µs making 24 calls to File::Spec::Unix::catdir, avg 3µs/call # spent 11µs making 24 calls to File::Spec::Unix::canonpath, avg 475ns/call
191 }
19227µs @results = ();
193
1942103µs foreach $basedir (@dirs) {
19524514µs24451µs next unless -d $basedir;
# spent 451µs making 24 calls to Module::Find::CORE:ftdir, avg 19µs/call
196
1973270µs343.8ms find({wanted => \&_wanted,
# spent 43.8ms making 3 calls to File::Find::find, avg 14.6ms/call
198 no_chdir => 1,
199 follow => $followMode}, $basedir);
200 }
201
202 # filter duplicate modules
20322µs my %seen = ();
2042207µs @results = grep { not $seen{$_}++ } @results;
205
206285µs @results = map "$category\::$_", @results;
207
208174416µs174206µs @results = map {
# spent 206µs making 174 calls to Module::Find::CORE:match, avg 1µs/call
209268µs ($_ =~ m{^(\w+(?:::\w+)*)$})[0] || die "$_ does not look like a package name"
210 } @results;
211
212232µs return @results;
213}
214
215=item C<ignoresymlinks()>
216
217Do not follow symlinks. This function is not exported by default.
218
219=cut
220
221sub ignoresymlinks {
222 $followMode = 0;
223}
224
225=item C<followsymlinks()>
226
227Follow symlinks (default behaviour). This function is not exported by default.
228
229=cut
230
231sub followsymlinks {
232 $followMode = 1;
233}
234
235=back
236
237=head1 HISTORY
238
239=over 8
240
241=item 0.01, 2004-04-22
242
243Original version; created by h2xs 1.22
244
245=item 0.02, 2004-05-25
246
247Added test modules that were left out in the first version. Thanks to
248Stuart Johnston for alerting me to this.
249
250=item 0.03, 2004-06-18
251
252Fixed a bug (non-localized $_) by declaring a loop variable in use functions.
253Thanks to Stuart Johnston for alerting me to this and providing a fix.
254
255Fixed non-platform compatibility by using File::Spec.
256Thanks to brian d foy.
257
258Added setmoduledirs and updated tests. Idea shamelessly stolen from
259...errm... inspired by brian d foy.
260
261=item 0.04, 2005-05-20
262
263Added POD tests.
264
265=item 0.05, 2005-11-30
266
267Fixed issue with bugfix in PathTools-3.14.
268
269=item 0.06, 2008-01-26
270
271Module::Find now won't report duplicate modules several times anymore (thanks to Uwe Völker for the report and the patch)
272
273=item 0.07, 2009-09-08
274
275Fixed RT#38302: Module::Find now follows symlinks by default (can be disabled).
276
277=item 0.08, 2009-09-08
278
279Fixed RT#49511: Removed Mac OS X extended attributes from distribution
280
281=item 0.09, 2010-02-26
282
283Fixed RT#38302: Fixed META.yml generation (thanks very much to cpanservice for the help).
284
285=item 0.10, 2010-02-26
286
287Fixed RT#55010: Removed Unicode BOM from Find.pm.
288
289=item 0.11, 2012-05-22
290
291Fixed RT#74251: defined(@array) is deprecated under Perl 5.15.7.
292Thanks to Roman F, who contributed the implementation.
293
294=item 0.12, 2014-02-08
295
296Fixed RT#81077: useall fails in taint mode
297Thanks to Aran Deltac, who contributed the implementation and test.
298
299Fixed RT#83596: Documentation doesn't describe behaviour if a module fails to load
300Clarified documentation for useall and usesub.
301
302Fixed RT#62923: setmoduledirs(undef) doesn't reset to searching @INC
303Added more explicit tests.
304Thanks to Colin Robertson for his input.
305
306=back
307
308=head1 DEVELOPMENT NOTES
309
310Please report any bugs using the CPAN RT system. The development repository for this module is hosted on GitHub: L<http://github.com/crenz/Module-Find/>.
311
312=head1 SEE ALSO
313
314L<perl>
315
316=head1 AUTHOR
317
318Christian Renz, E<lt>crenz@web42.comE<gt>
319
320=head1 COPYRIGHT AND LICENSE
321
322Copyright 2004-2014 by Christian Renz <crenz@web42.com>. All rights reserved.
323
324This library is free software; you can redistribute it and/or modify
325it under the same terms as Perl itself.
326
327=cut
328
32915µs1;
 
# spent 2.63ms within Module::Find::CORE:ftdir which was called 541 times, avg 5µs/call: # 517 times (2.18ms+0s) by File::Find::find at line 163, avg 4µs/call # 24 times (451µs+0s) by Module::Find::_find at line 195, avg 19µs/call
sub Module::Find::CORE:ftdir; # opcode
# spent 1.56ms within Module::Find::CORE:fteread which was called 517 times, avg 3µs/call: # 517 times (1.56ms+0s) by File::Find::find at line 168, avg 3µs/call
sub Module::Find::CORE:fteread; # opcode
# spent 996µs within Module::Find::CORE:match which was called 691 times, avg 1µs/call: # 517 times (790µs+0s) by File::Find::find at line 168, avg 2µs/call # 174 times (206µs+0s) by Module::Find::_find at line 208, avg 1µs/call
sub Module::Find::CORE:match; # opcode
# spent 799µs within Module::Find::CORE:subst which was called 517 times, avg 2µs/call: # 517 times (799µs+0s) by File::Find::find at line 170, avg 2µs/call
sub Module::Find::CORE:subst; # opcode