Profile of /usr/local/lib/perl5/site_perl/5.10.1/Module/Find.pm

← 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:52 2010

File | /usr/local/lib/perl5/site_perl/5.10.1/Module/Find.pm
Statements Executed | 93
Statement Execution Time | 1.79ms

Subroutines — ordered by exclusive time
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 9.81ms | 10.9ms | Module::Find::::BEGIN@8Module::Find::BEGIN@8
1 | 1 | 1 | 1.06ms | 56.9ms | Module::Find::::useallModule::Find::useall
5 | 2 | 1 | 112µs | 1.11ms | Module::Find::::_wantedModule::Find::_wanted
1 | 1 | 1 | 107µs | 2.02ms | Module::Find::::_findModule::Find::_find
11 | 2 | 2 | 84µs | 84µs | Module::Find::::CORE:ftdirModule::Find::CORE:ftdir (opcode)
1 | 1 | 1 | 36µs | 36µs | Module::Find::::BEGIN@3Module::Find::BEGIN@3
4 | 1 | 2 | 13µs | 13µs | Module::Find::::CORE:ftereadModule::Find::CORE:fteread (opcode)
1 | 1 | 1 | 10µs | 16µs | Module::Find::::BEGIN@4Module::Find::BEGIN@4
1 | 1 | 1 | 9µs | 28µs | Module::Find::::BEGIN@5Module::Find::BEGIN@5
4 | 1 | 2 | 6µs | 6µs | Module::Find::::CORE:substModule::Find::CORE:subst (opcode)
1 | 1 | 1 | 5µs | 5µs | Module::Find::::BEGIN@7Module::Find::BEGIN@7
4 | 1 | 2 | 3µs | 3µs | Module::Find::::CORE:matchModule::Find::CORE:match (opcode)
0 | 0 | 0 | 0s | 0s | Module::Find::::findallmodModule::Find::findallmod
0 | 0 | 0 | 0s | 0s | Module::Find::::findsubmodModule::Find::findsubmod
0 | 0 | 0 | 0s | 0s | Module::Find::::followsymlinksModule::Find::followsymlinks
0 | 0 | 0 | 0s | 0s | Module::Find::::ignoresymlinksModule::Find::ignoresymlinks
0 | 0 | 0 | 0s | 0s | Module::Find::::setmoduledirsModule::Find::setmoduledirs
0 | 0 | 0 | 0s | 0s | Module::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
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package Module::Find;
2 |  |  |  |  |
3 | 3 | 46µs | 1 | 36µ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
4 | 3 | 21µs | 2 | 22µ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
5 | 3 | 21µs | 2 | 48µ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 |  |  |  |  |
7 | 3 | 18µs | 1 | 5µ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
8 | 3 | 690µs | 2 | 10.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 |  |  |  |  |
10 | 1 | 800ns |  |  | our $VERSION = '0.08';
11 |  |  |  |  |
12 | 1 | 400ns |  |  | our $basedir = undef;
13 | 1 | 600ns |  |  | our @results = ();
14 | 1 | 100ns |  |  | our $prune = 0;
15 | 1 | 100ns |  |  | our $followMode = 1;
16 |  |  |  |  |
17 | 1 | 7µs |  |  | our @ISA = qw(Exporter);
18 |  |  |  |  |
19 | 1 | 1µs |  |  | our @EXPORT = qw(findsubmod findallmod usesub useall setmoduledirs);
20 |  |  |  |  |
21 | 1 | 500ns |  |  | our @EXPORT_OK = qw(followsymlinks ignoresymlinks);
22 |  |  |  |  |
23 |  |  |  |  | =head1 NAME
24 |  |  |  |  |
25 |  |  |  |  | Module::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 |  |  |  |  |
57 |  |  |  |  | Module::Find lets you find and use modules in categories. This can be very
58 |  |  |  |  | useful for auto-detecting driver or plugin modules. You can differentiate
59 |  |  |  |  | between looking in the category itself or in all subcategories.
60 |  |  |  |  |
61 |  |  |  |  | If you want Module::Find to search in a certain directory on your
62 |  |  |  |  | harddisk (such as the plugins directory of your software installation),
63 |  |  |  |  | make 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 |  |  |  |  |
71 |  |  |  |  | Sets the directories to be searched for modules. If not set, Module::Find
72 |  |  |  |  | will use @INC. If you use this function, @INC will I<not> be included
73 |  |  |  |  | automatically, so add it if you want it. Set to undef to revert to
74 |  |  |  |  | default behaviour.
75 |  |  |  |  |
76 |  |  |  |  | =cut
77 |  |  |  |  |
78 |  |  |  |  | sub setmoduledirs {
79 |  |  |  |  | return @Module::Find::ModuleDirs = @_;
80 |  |  |  |  | }
81 |  |  |  |  |
82 |  |  |  |  | =item C<@found = findsubmod Module::Category>
83 |  |  |  |  |
84 |  |  |  |  | Returns modules found in the Module/Category subdirectories of your perl
85 |  |  |  |  | installation. E.g. C<findsubmod CGI> will return C<CGI::Session>, but
86 |  |  |  |  | not C<CGI::Session::File> .
87 |  |  |  |  |
88 |  |  |  |  | =cut
89 |  |  |  |  |
90 |  |  |  |  | sub findsubmod(*) {
91 |  |  |  |  | $prune = 1;
92 |  |  |  |  |
93 |  |  |  |  | return _find($_[0]);
94 |  |  |  |  | }
95 |  |  |  |  |
96 |  |  |  |  | =item C<@found = findallmod Module::Category>
97 |  |  |  |  |
98 |  |  |  |  | Returns modules found in the Module/Category subdirectories of your perl
99 |  |  |  |  | installation. E.g. C<findallmod CGI> will return C<CGI::Session> and also
100 |  |  |  |  | C<CGI::Session::File> .
101 |  |  |  |  |
102 |  |  |  |  | =cut
103 |  |  |  |  |
104 |  |  |  |  | sub findallmod(*) {
105 |  |  |  |  | $prune = 0;
106 |  |  |  |  |
107 |  |  |  |  | return _find($_[0]);
108 |  |  |  |  | }
109 |  |  |  |  |
110 |  |  |  |  | =item C<@found = usesub Module::Category>
111 |  |  |  |  |
112 |  |  |  |  | Uses and returns modules found in the Module/Category subdirectories of your perl
113 |  |  |  |  | installation. E.g. C<usesub CGI> will return C<CGI::Session>, but
114 |  |  |  |  | not C<CGI::Session::File> .
115 |  |  |  |  |
116 |  |  |  |  | =cut
117 |  |  |  |  |
118 |  |  |  |  | sub 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 |  |  |  |  |
133 |  |  |  |  | Uses 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
134 |  |  |  |  | C<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(*) {
139 | 4 | 16µ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) {
144 | 8 | 653µ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 {
154 | 30 | 143µs | 5 | 933µ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(*) {
174 | 11 | 53µ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 | 1 | 7µs |  |  | if (defined @Module::Find::ModuleDirs) {
181 |  |  |  |  | @dirs = map { File::Spec->catdir($_, $dir) }
182 |  |  |  |  | @Module::Find::ModuleDirs;
183 |  |  |  |  | } else {
184 | 7 | 9µs | 7 | 118µs | @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 | 8 | 86µs | 7 | 58µs | 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 |  |  |  |  |
206 |  |  |  |  | Do not follow symlinks. This function is not exported by default.
207 |  |  |  |  |
208 |  |  |  |  | =cut
209 |  |  |  |  |
210 |  |  |  |  | sub ignoresymlinks {
211 |  |  |  |  | $followMode = 0;
212 |  |  |  |  | }
213 |  |  |  |  |
214 |  |  |  |  | =item C<followsymlinks()>
215 |  |  |  |  |
216 |  |  |  |  | Follow symlinks (default behaviour). This function is not exported by default.
217 |  |  |  |  |
218 |  |  |  |  | =cut
219 |  |  |  |  |
220 |  |  |  |  | sub 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 |  |  |  |  |
232 |  |  |  |  | Original version; created by h2xs 1.22
233 |  |  |  |  |
234 |  |  |  |  | =item 0.02, 2004-05-25
235 |  |  |  |  |
236 |  |  |  |  | Added test modules that were left out in the first version. Thanks to
237 |  |  |  |  | Stuart Johnston for alerting me to this.
238 |  |  |  |  |
239 |  |  |  |  | =item 0.03, 2004-06-18
240 |  |  |  |  |
241 |  |  |  |  | Fixed a bug (non-localized $_) by declaring a loop variable in use functions.
242 |  |  |  |  | Thanks to Stuart Johnston for alerting me to this and providing a fix.
243 |  |  |  |  |
244 |  |  |  |  | Fixed non-platform compatibility by using File::Spec.
245 |  |  |  |  | Thanks to brian d foy.
246 |  |  |  |  |
247 |  |  |  |  | Added setmoduledirs and updated tests. Idea shamelessly stolen from
248 |  |  |  |  | ...errm... inspired by brian d foy.
249 |  |  |  |  |
250 |  |  |  |  | =item 0.04, 2005-05-20
251 |  |  |  |  |
252 |  |  |  |  | Added POD tests.
253 |  |  |  |  |
254 |  |  |  |  | =item 0.05, 2005-11-30
255 |  |  |  |  |
256 |  |  |  |  | Fixed issue with bugfix in PathTools-3.14.
257 |  |  |  |  |
258 |  |  |  |  | =item 0.06, 2008-01-26
259 |  |  |  |  |
260 |  |  |  |  | Module::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 |  |  |  |  |
264 |  |  |  |  | Fixed RT#38302: Module::Find now follows symlinks by default (can be disabled).
265 |  |  |  |  |
266 |  |  |  |  | =back
267 |  |  |  |  |
268 |  |  |  |  | =head1 DEVELOPMENT NOTES
269 |  |  |  |  |
270 |  |  |  |  | Please 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 |  |  |  |  |
274 |  |  |  |  | L<perl>
275 |  |  |  |  |
276 |  |  |  |  | =head1 AUTHOR
277 |  |  |  |  |
278 |  |  |  |  | Christian Renz, E<lt>crenz@web42.comE<gt>
279 |  |  |  |  |
280 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
281 |  |  |  |  |
282 |  |  |  |  | Copyright 2004-2008 by Christian Renz <crenz@web42.com>. All rights reserved.
283 |  |  |  |  |
284 |  |  |  |  | This library is free software; you can redistribute it and/or modify
285 |  |  |  |  | it under the same terms as Perl itself.
286 |  |  |  |  |
287 |  |  |  |  | =cut
288 |  |  |  |  |
289 | 1 | 11µs |  |  | 1;
|  |  |  |  | # 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