← Index
NYTProf Performance Profile   « block view • line view • sub view »
For 05.Domain_and_Item.t
  Run on Tue May 4 17:21:41 2010
Reported on Tue May 4 17:22:23 2010

File /usr/local/lib/perl5/site_perl/5.10.1/Module/Find.pm
Statements Executed 94
Statement Execution Time 1.79ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1119.81ms10.9msModule::Find::::BEGIN@8Module::Find::BEGIN@8
1111.06ms56.9msModule::Find::::useallModule::Find::useall
521112µs1.11msModule::Find::::_wantedModule::Find::_wanted
111107µs2.02msModule::Find::::_findModule::Find::_find
112284µs84µsModule::Find::::CORE:ftdirModule::Find::CORE:ftdir (opcode)
11136µs36µsModule::Find::::BEGIN@3Module::Find::BEGIN@3
41213µs13µsModule::Find::::CORE:ftereadModule::Find::CORE:fteread (opcode)
11110µs16µsModule::Find::::BEGIN@4Module::Find::BEGIN@4
1119µs28µsModule::Find::::BEGIN@5Module::Find::BEGIN@5
4126µs6µsModule::Find::::CORE:substModule::Find::CORE:subst (opcode)
1115µs5µsModule::Find::::BEGIN@7Module::Find::BEGIN@7
4123µs3µsModule::Find::::CORE:matchModule::Find::CORE:match (opcode)
0000s0sModule::Find::::findallmodModule::Find::findallmod
0000s0sModule::Find::::findsubmodModule::Find::findsubmod
0000s0sModule::Find::::followsymlinksModule::Find::followsymlinks
0000s0sModule::Find::::ignoresymlinksModule::Find::ignoresymlinks
0000s0sModule::Find::::setmoduledirsModule::Find::setmoduledirs
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
3346µs136µs
# spent 36µs within Module::Find::BEGIN@3 which was called # once (36µs+0s) by SimpleDB::Class::BEGIN@142 at line 3
use 5.006001;
# spent 36µs making 1 call to Module::Find::BEGIN@3
4321µs222µs
# spent 16µs (10+6) within Module::Find::BEGIN@4 which was called # once (10µs+6µs) by SimpleDB::Class::BEGIN@142 at line 4
use strict;
# spent 16µs making 1 call to Module::Find::BEGIN@4 # spent 6µs making 1 call to strict::import
5321µs248µs
# spent 28µs (9+19) within Module::Find::BEGIN@5 which was called # once (9µs+19µs) by SimpleDB::Class::BEGIN@142 at line 5
use warnings;
# spent 28µs making 1 call to Module::Find::BEGIN@5 # spent 20µs making 1 call to warnings::import
6
7318µs15µs
# spent 5µs within Module::Find::BEGIN@7 which was called # once (5µs+0s) by SimpleDB::Class::BEGIN@142 at line 7
use File::Spec;
# spent 5µs making 1 call to Module::Find::BEGIN@7
83690µs210.9ms
# spent 10.9ms (9.81+1.06) within Module::Find::BEGIN@8 which was called # once (9.81ms+1.06ms) by SimpleDB::Class::BEGIN@142 at line 8
use File::Find;
# spent 10.9ms making 1 call to Module::Find::BEGIN@8 # spent 51µs making 1 call to Exporter::import
9
101800nsour $VERSION = '0.08';
11
121400nsour $basedir = undef;
131600nsour @results = ();
141100nsour $prune = 0;
151100nsour $followMode = 1;
16
1717µsour @ISA = qw(Exporter);
18
1911µsour @EXPORT = qw(findsubmod findallmod usesub useall setmoduledirs);
20
211500nsour @EXPORT_OK = qw(followsymlinks ignoresymlinks);
22
23=head1 NAME
24
25Module::Find - Find and use installed modules in a (sub)category
26
27=head1 SYNOPSIS
28
29 use Module::Find;
30
31 # use all modules in the Plugins/ directory
32 @found = usesub Mysoft::Plugins;
33
34 # use modules in all subdirectories
35 @found = useall Mysoft::Plugins;
36
37 # find all DBI::... modules
38 @found = findsubmod DBI;
39
40 # find anything in the CGI/ directory
41 @found = findallmod CGI;
42
43 # set your own search dirs (uses @INC otherwise)
44 setmoduledirs(@INC, @plugindirs, $appdir);
45
46 # not exported by default
47 use Module::Find qw(ignoresymlinks followsymlinks);
48
49 # ignore symlinks
50 ignoresymlinks();
51
52 # follow symlinks (default)
53 followsymlinks();
54
55=head1 DESCRIPTION
56
57Module::Find lets you find and use modules in categories. This can be very
58useful for auto-detecting driver or plugin modules. You can differentiate
59between looking in the category itself or in all subcategories.
60
61If you want Module::Find to search in a certain directory on your
62harddisk (such as the plugins directory of your software installation),
63make sure you modify C<@INC> before you call the Module::Find functions.
64
65=head1 FUNCTIONS
66
67=over
68
69=item C<setmoduledirs(@directories)>
70
71Sets the directories to be searched for modules. If not set, Module::Find
72will use @INC. If you use this function, @INC will I<not> be included
73automatically, so add it if you want it. Set to undef to revert to
74default behaviour.
75
76=cut
77
78sub setmoduledirs {
79 return @Module::Find::ModuleDirs = @_;
80}
81
82=item C<@found = findsubmod Module::Category>
83
84Returns modules found in the Module/Category subdirectories of your perl
85installation. E.g. C<findsubmod CGI> will return C<CGI::Session>, but
86not C<CGI::Session::File> .
87
88=cut
89
90sub findsubmod(*) {
91 $prune = 1;
92
93 return _find($_[0]);
94}
95
96=item C<@found = findallmod Module::Category>
97
98Returns modules found in the Module/Category subdirectories of your perl
99installation. E.g. C<findallmod CGI> will return C<CGI::Session> and also
100C<CGI::Session::File> .
101
102=cut
103
104sub findallmod(*) {
105 $prune = 0;
106
107 return _find($_[0]);
108}
109
110=item C<@found = usesub Module::Category>
111
112Uses and returns modules found in the Module/Category subdirectories of your perl
113installation. E.g. C<usesub CGI> will return C<CGI::Session>, but
114not C<CGI::Session::File> .
115
116=cut
117
118sub usesub(*) {
119 $prune = 1;
120
121 my @r = _find($_[0]);
122
123 foreach my $m (@r) {
124 eval " require $m; import $m ; ";
125 die $@ if $@;
126 }
127
128 return @r;
129}
130
131=item C<@found = useall Module::Category>
132
133Uses 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
134C<CGI::Session::File> .
135
136=cut
137
138
# spent 56.9ms (1.06+55.8) within Module::Find::useall which was called # once (1.06ms+55.8ms) by SimpleDB::Class::load_namespaces at line 189 of ../lib/SimpleDB/Class.pm
sub useall(*) {
13912153µs $prune = 0;
140
141 my @r = _find($_[0]);
# spent 2.02ms making 1 call to Module::Find::_find
142
143 foreach my $m (@r) {
1441516µs eval " require $m; import $m; ";
145 die $@ if $@;
146 }
147
148 return @r;
149}
150
151# 'wanted' functions for find()
152# you know, this would be a nice application for currying...
153
# spent 1.11ms (112µs+994µs) within Module::Find::_wanted which was called 5 times, avg 221µs/call: # 4 times (95µs+807µs) by File::Find::_find_dir_symlnk at line 1211 of File/Find.pm, avg 225µs/call # once (17µs+187µs) by File::Find::_find_dir_symlnk at line 1128 of File/Find.pm
sub _wanted {
15430143µs5933µs my $name = File::Spec->abs2rel($_, $basedir);
# spent 933µs making 5 calls to File::Spec::Unix::abs2rel, avg 187µs/call
155 return unless $name && $name ne File::Spec->curdir();
# spent 5µs making 5 calls to File::Spec::Unix::curdir, avg 1µs/call
156
157 if (-d && $prune) {
# spent 26µs making 4 calls to Module::Find::CORE:ftdir, avg 6µs/call
158 $File::Find::prune = 1;
159 return;
160 }
161
162 return unless /\.pm$/ && -r;
# spent 13µs making 4 calls to Module::Find::CORE:fteread, avg 3µs/call # spent 3µs making 4 calls to Module::Find::CORE:match, avg 850ns/call
163
164 $name =~ s|\.pm$||;
# spent 6µs making 4 calls to Module::Find::CORE:subst, avg 1µs/call
165 $name = join('::', File::Spec->splitdir($name));
# spent 8µs making 4 calls to File::Spec::Unix::splitdir, avg 2µs/call
166
167 push @results, $name;
168}
169
170
171# helper functions for finding files
172
173
# spent 2.02ms (107µs+1.91) within Module::Find::_find which was called # once (107µs+1.91ms) by Module::Find::useall at line 141
sub _find(*) {
17427155µs my ($category) = @_;
175 return undef unless defined $category;
176
177 my $dir = File::Spec->catdir(split(/::/, $category));
# spent 70µs making 1 call to File::Spec::Unix::catdir
178
179 my @dirs;
180 if (defined @Module::Find::ModuleDirs) {
181 @dirs = map { File::Spec->catdir($_, $dir) }
182 @Module::Find::ModuleDirs;
183 } else {
184 @dirs = map { File::Spec->catdir($_, $dir) } @INC;
# spent 118µs making 7 calls to File::Spec::Unix::catdir, avg 17µs/call
185 }
186 @results = ();
187
188 foreach $basedir (@dirs) {
189 next unless -d $basedir;
# spent 58µs making 7 calls to Module::Find::CORE:ftdir, avg 8µs/call
190
191 find({wanted => \&_wanted,
# spent 1.66ms making 1 call to File::Find::find
192 no_chdir => 1,
193 follow => $followMode}, $basedir);
194 }
195
196 # filter duplicate modules
197 my %seen = ();
198 @results = grep { not $seen{$_}++ } @results;
199
200 @results = map "$category\::$_", @results;
201 return @results;
202}
203
204=item C<ignoresymlinks()>
205
206Do not follow symlinks. This function is not exported by default.
207
208=cut
209
210sub ignoresymlinks {
211 $followMode = 0;
212}
213
214=item C<followsymlinks()>
215
216Follow symlinks (default behaviour). This function is not exported by default.
217
218=cut
219
220sub followsymlinks {
221 $followMode = 1;
222}
223
224=back
225
226=head1 HISTORY
227
228=over 8
229
230=item 0.01, 2004-04-22
231
232Original version; created by h2xs 1.22
233
234=item 0.02, 2004-05-25
235
236Added test modules that were left out in the first version. Thanks to
237Stuart Johnston for alerting me to this.
238
239=item 0.03, 2004-06-18
240
241Fixed a bug (non-localized $_) by declaring a loop variable in use functions.
242Thanks to Stuart Johnston for alerting me to this and providing a fix.
243
244Fixed non-platform compatibility by using File::Spec.
245Thanks to brian d foy.
246
247Added setmoduledirs and updated tests. Idea shamelessly stolen from
248...errm... inspired by brian d foy.
249
250=item 0.04, 2005-05-20
251
252Added POD tests.
253
254=item 0.05, 2005-11-30
255
256Fixed issue with bugfix in PathTools-3.14.
257
258=item 0.06, 2008-01-26
259
260Module::Find now won't report duplicate modules several times anymore (thanks to Uwe Völker for the report and the patch)
261
262=item 0.07, 2009-09-08
263
264Fixed RT#38302: Module::Find now follows symlinks by default (can be disabled).
265
266=back
267
268=head1 DEVELOPMENT NOTES
269
270Please report any bugs sing the CPAN RT system. The development repository for this module is hosted on GitHub: L<http://github.com/crenz/Module-Find/>.
271
272=head1 SEE ALSO
273
274L<perl>
275
276=head1 AUTHOR
277
278Christian Renz, E<lt>crenz@web42.comE<gt>
279
280=head1 COPYRIGHT AND LICENSE
281
282Copyright 2004-2008 by Christian Renz <crenz@web42.com>. All rights reserved.
283
284This library is free software; you can redistribute it and/or modify
285it under the same terms as Perl itself.
286
287=cut
288
289111µs1;
# spent 84µs within Module::Find::CORE:ftdir which was called 11 times, avg 8µs/call: # 7 times (58µs+0s) by Module::Find::_find at line 189 of Module/Find.pm, avg 8µs/call # 4 times (26µs+0s) by Module::Find::_wanted at line 157 of Module/Find.pm, avg 6µs/call
sub Module::Find::CORE:ftdir; # xsub
# spent 13µs within Module::Find::CORE:fteread which was called 4 times, avg 3µs/call: # 4 times (13µs+0s) by Module::Find::_wanted at line 162 of Module/Find.pm, avg 3µs/call
sub Module::Find::CORE:fteread; # xsub
# spent 3µs within Module::Find::CORE:match which was called 4 times, avg 850ns/call: # 4 times (3µs+0s) by Module::Find::_wanted at line 162 of Module/Find.pm, avg 850ns/call
sub Module::Find::CORE:match; # xsub
# spent 6µs within Module::Find::CORE:subst which was called 4 times, avg 1µs/call: # 4 times (6µs+0s) by Module::Find::_wanted at line 164 of Module/Find.pm, avg 1µs/call
sub Module::Find::CORE:subst; # xsub