Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/Module/Find.pm |
Statements | Executed 427 statements in 1.95ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 4.32ms | 4.53ms | BEGIN@8 | Module::Find::
45 | 2 | 1 | 546µs | 9.75ms | _wanted | Module::Find::
4 | 1 | 1 | 278µs | 12.3ms | _find | Module::Find::
65 | 2 | 1 | 215µs | 215µs | CORE:ftdir (opcode) | Module::Find::
41 | 1 | 1 | 103µs | 103µs | CORE:fteread (opcode) | Module::Find::
1 | 1 | 1 | 35µs | 35µs | BEGIN@3 | Module::Find::
41 | 1 | 1 | 30µs | 30µs | CORE:subst (opcode) | Module::Find::
41 | 1 | 1 | 21µs | 21µs | CORE:match (opcode) | Module::Find::
4 | 1 | 1 | 19µs | 12.3ms | findallmod | Module::Find::
1 | 1 | 1 | 10µs | 15µs | BEGIN@4 | Module::Find::
1 | 1 | 1 | 9µs | 26µs | BEGIN@5 | Module::Find::
1 | 1 | 1 | 6µs | 6µs | BEGIN@7 | Module::Find::
0 | 0 | 0 | 0s | 0s | findsubmod | Module::Find::
0 | 0 | 0 | 0s | 0s | followsymlinks | Module::Find::
0 | 0 | 0 | 0s | 0s | ignoresymlinks | Module::Find::
0 | 0 | 0 | 0s | 0s | setmoduledirs | Module::Find::
0 | 0 | 0 | 0s | 0s | useall | Module::Find::
0 | 0 | 0 | 0s | 0s | usesub | Module::Find::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Module::Find; | ||||
2 | |||||
3 | 3 | 45µs | 1 | 35µs | # spent 35µs within Module::Find::BEGIN@3 which was called:
# once (35µs+0s) by DBIx::Class::Schema::_findallmod at line 3 # spent 35µs making 1 call to Module::Find::BEGIN@3 |
4 | 3 | 19µs | 2 | 20µs | # spent 15µs (10+5) within Module::Find::BEGIN@4 which was called:
# once (10µs+5µs) by DBIx::Class::Schema::_findallmod at line 4 # spent 15µs making 1 call to Module::Find::BEGIN@4
# spent 5µs making 1 call to strict::import |
5 | 3 | 19µs | 2 | 44µs | # spent 26µs (9+17) within Module::Find::BEGIN@5 which was called:
# once (9µs+17µs) by DBIx::Class::Schema::_findallmod at line 5 # spent 26µs making 1 call to Module::Find::BEGIN@5
# spent 17µs making 1 call to warnings::import |
6 | |||||
7 | 3 | 18µs | 1 | 6µs | # spent 6µs within Module::Find::BEGIN@7 which was called:
# once (6µs+0s) by DBIx::Class::Schema::_findallmod at line 7 # spent 6µs making 1 call to Module::Find::BEGIN@7 |
8 | 3 | 686µs | 2 | 4.57ms | # spent 4.53ms (4.32+202µs) within Module::Find::BEGIN@8 which was called:
# once (4.32ms+202µs) by DBIx::Class::Schema::_findallmod at line 8 # spent 4.53ms making 1 call to Module::Find::BEGIN@8
# spent 48µs making 1 call to Exporter::import |
9 | |||||
10 | 1 | 500ns | our $VERSION = '0.10'; | ||
11 | |||||
12 | 1 | 400ns | our $basedir = undef; | ||
13 | 1 | 400ns | our @results = (); | ||
14 | 1 | 300ns | our $prune = 0; | ||
15 | 1 | 500ns | our $followMode = 1; | ||
16 | |||||
17 | 1 | 6µs | our @ISA = qw(Exporter); | ||
18 | |||||
19 | 1 | 1µs | our @EXPORT = qw(findsubmod findallmod usesub useall setmoduledirs); | ||
20 | |||||
21 | 1 | 600ns | our @EXPORT_OK = qw(followsymlinks ignoresymlinks); | ||
22 | |||||
23 | =encoding utf-8 | ||||
24 | |||||
25 | =head1 NAME | ||||
26 | |||||
27 | Module::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 | |||||
59 | Module::Find lets you find and use modules in categories. This can be very | ||||
60 | useful for auto-detecting driver or plugin modules. You can differentiate | ||||
61 | between looking in the category itself or in all subcategories. | ||||
62 | |||||
63 | If you want Module::Find to search in a certain directory on your | ||||
64 | harddisk (such as the plugins directory of your software installation), | ||||
65 | make 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 | |||||
73 | Sets the directories to be searched for modules. If not set, Module::Find | ||||
74 | will use @INC. If you use this function, @INC will I<not> be included | ||||
75 | automatically, so add it if you want it. Set to undef to revert to | ||||
76 | default behaviour. | ||||
77 | |||||
78 | =cut | ||||
79 | |||||
80 | sub setmoduledirs { | ||||
81 | return @Module::Find::ModuleDirs = @_; | ||||
82 | } | ||||
83 | |||||
84 | =item C<@found = findsubmod Module::Category> | ||||
85 | |||||
86 | Returns modules found in the Module/Category subdirectories of your perl | ||||
87 | installation. E.g. C<findsubmod CGI> will return C<CGI::Session>, but | ||||
88 | not C<CGI::Session::File> . | ||||
89 | |||||
90 | =cut | ||||
91 | |||||
92 | sub findsubmod(*) { | ||||
93 | $prune = 1; | ||||
94 | |||||
95 | return _find($_[0]); | ||||
96 | } | ||||
97 | |||||
98 | =item C<@found = findallmod Module::Category> | ||||
99 | |||||
100 | Returns modules found in the Module/Category subdirectories of your perl | ||||
101 | installation. E.g. C<findallmod CGI> will return C<CGI::Session> and also | ||||
102 | C<CGI::Session::File> . | ||||
103 | |||||
104 | =cut | ||||
105 | |||||
106 | # spent 12.3ms (19µs+12.3) within Module::Find::findallmod which was called 4 times, avg 3.07ms/call:
# 4 times (19µs+12.3ms) by DBIx::Class::Schema::_findallmod at line 170 of DBIx/Class/Schema.pm, avg 3.07ms/call | ||||
107 | 8 | 24µs | $prune = 0; | ||
108 | |||||
109 | 4 | 12.3ms | return _find($_[0]); # spent 12.3ms making 4 calls to Module::Find::_find, avg 3.07ms/call | ||
110 | } | ||||
111 | |||||
112 | =item C<@found = usesub Module::Category> | ||||
113 | |||||
114 | Uses and returns modules found in the Module/Category subdirectories of your perl | ||||
115 | installation. E.g. C<usesub CGI> will return C<CGI::Session>, but | ||||
116 | not C<CGI::Session::File> . | ||||
117 | |||||
118 | =cut | ||||
119 | |||||
120 | sub usesub(*) { | ||||
121 | $prune = 1; | ||||
122 | |||||
123 | my @r = _find($_[0]); | ||||
124 | |||||
125 | foreach my $m (@r) { | ||||
126 | eval " require $m; import $m ; "; | ||||
127 | die $@ if $@; | ||||
128 | } | ||||
129 | |||||
130 | return @r; | ||||
131 | } | ||||
132 | |||||
133 | =item C<@found = useall Module::Category> | ||||
134 | |||||
135 | 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 | ||||
136 | C<CGI::Session::File> . | ||||
137 | |||||
138 | =cut | ||||
139 | |||||
140 | sub useall(*) { | ||||
141 | $prune = 0; | ||||
142 | |||||
143 | my @r = _find($_[0]); | ||||
144 | |||||
145 | foreach my $m (@r) { | ||||
146 | eval " require $m; import $m; "; | ||||
147 | die $@ if $@; | ||||
148 | } | ||||
149 | |||||
150 | return @r; | ||||
151 | } | ||||
152 | |||||
153 | # 'wanted' functions for find() | ||||
154 | # you know, this would be a nice application for currying... | ||||
155 | # spent 9.75ms (546µs+9.20) within Module::Find::_wanted which was called 45 times, avg 217µs/call:
# 41 times (519µs+8.45ms) by File::Find::_find_dir_symlnk at line 1211 of File/Find.pm, avg 219µs/call
# 4 times (27µs+748µs) by File::Find::_find_dir_symlnk at line 1128 of File/Find.pm, avg 194µs/call | ||||
156 | 295 | 783µs | 45 | 8.82ms | my $name = File::Spec->abs2rel($_, $basedir); # spent 8.82ms making 45 calls to File::Spec::Unix::abs2rel, avg 196µs/call |
157 | 45 | 40µs | return unless $name && $name ne File::Spec->curdir(); # spent 40µs making 45 calls to File::Spec::Unix::curdir, avg 884ns/call | ||
158 | |||||
159 | 41 | 138µs | if (-d && $prune) { # spent 138µs making 41 calls to Module::Find::CORE:ftdir, avg 3µs/call | ||
160 | $File::Find::prune = 1; | ||||
161 | return; | ||||
162 | } | ||||
163 | |||||
164 | 82 | 124µs | return unless /\.pm$/ && -r; # spent 103µs making 41 calls to Module::Find::CORE:fteread, avg 3µs/call
# spent 21µs making 41 calls to Module::Find::CORE:match, avg 502ns/call | ||
165 | |||||
166 | 41 | 30µs | $name =~ s|\.pm$||; # spent 30µs making 41 calls to Module::Find::CORE:subst, avg 741ns/call | ||
167 | 41 | 51µs | $name = join('::', File::Spec->splitdir($name)); # spent 51µs making 41 calls to File::Spec::Unix::splitdir, avg 1µs/call | ||
168 | |||||
169 | push @results, $name; | ||||
170 | } | ||||
171 | |||||
172 | |||||
173 | # helper functions for finding files | ||||
174 | |||||
175 | # spent 12.3ms (278µs+12.0) within Module::Find::_find which was called 4 times, avg 3.07ms/call:
# 4 times (278µs+12.0ms) by Module::Find::findallmod at line 109, avg 3.07ms/call | ||||
176 | 100 | 337µs | my ($category) = @_; | ||
177 | return undef unless defined $category; | ||||
178 | |||||
179 | 4 | 97µs | my $dir = File::Spec->catdir(split(/::/, $category)); # spent 97µs making 4 calls to File::Spec::Unix::catdir, avg 24µs/call | ||
180 | |||||
181 | my @dirs; | ||||
182 | if (defined @Module::Find::ModuleDirs) { | ||||
183 | @dirs = map { File::Spec->catdir($_, $dir) } | ||||
184 | @Module::Find::ModuleDirs; | ||||
185 | } else { | ||||
186 | 24 | 354µs | @dirs = map { File::Spec->catdir($_, $dir) } @INC; # spent 354µs making 24 calls to File::Spec::Unix::catdir, avg 15µs/call | ||
187 | } | ||||
188 | @results = (); | ||||
189 | |||||
190 | foreach $basedir (@dirs) { | ||||
191 | 24 | 77µs | next unless -d $basedir; # spent 77µs making 24 calls to Module::Find::CORE:ftdir, avg 3µs/call | ||
192 | |||||
193 | 4 | 11.5ms | find({wanted => \&_wanted, # spent 11.5ms making 4 calls to File::Find::find, avg 2.86ms/call | ||
194 | no_chdir => 1, | ||||
195 | follow => $followMode}, $basedir); | ||||
196 | } | ||||
197 | |||||
198 | # filter duplicate modules | ||||
199 | my %seen = (); | ||||
200 | @results = grep { not $seen{$_}++ } @results; | ||||
201 | |||||
202 | @results = map "$category\::$_", @results; | ||||
203 | return @results; | ||||
204 | } | ||||
205 | |||||
206 | =item C<ignoresymlinks()> | ||||
207 | |||||
208 | Do not follow symlinks. This function is not exported by default. | ||||
209 | |||||
210 | =cut | ||||
211 | |||||
212 | sub ignoresymlinks { | ||||
213 | $followMode = 0; | ||||
214 | } | ||||
215 | |||||
216 | =item C<followsymlinks()> | ||||
217 | |||||
218 | Follow symlinks (default behaviour). This function is not exported by default. | ||||
219 | |||||
220 | =cut | ||||
221 | |||||
222 | sub followsymlinks { | ||||
223 | $followMode = 1; | ||||
224 | } | ||||
225 | |||||
226 | =back | ||||
227 | |||||
228 | =head1 HISTORY | ||||
229 | |||||
230 | =over 8 | ||||
231 | |||||
232 | =item 0.01, 2004-04-22 | ||||
233 | |||||
234 | Original version; created by h2xs 1.22 | ||||
235 | |||||
236 | =item 0.02, 2004-05-25 | ||||
237 | |||||
238 | Added test modules that were left out in the first version. Thanks to | ||||
239 | Stuart Johnston for alerting me to this. | ||||
240 | |||||
241 | =item 0.03, 2004-06-18 | ||||
242 | |||||
243 | Fixed a bug (non-localized $_) by declaring a loop variable in use functions. | ||||
244 | Thanks to Stuart Johnston for alerting me to this and providing a fix. | ||||
245 | |||||
246 | Fixed non-platform compatibility by using File::Spec. | ||||
247 | Thanks to brian d foy. | ||||
248 | |||||
249 | Added setmoduledirs and updated tests. Idea shamelessly stolen from | ||||
250 | ...errm... inspired by brian d foy. | ||||
251 | |||||
252 | =item 0.04, 2005-05-20 | ||||
253 | |||||
254 | Added POD tests. | ||||
255 | |||||
256 | =item 0.05, 2005-11-30 | ||||
257 | |||||
258 | Fixed issue with bugfix in PathTools-3.14. | ||||
259 | |||||
260 | =item 0.06, 2008-01-26 | ||||
261 | |||||
262 | Module::Find now won't report duplicate modules several times anymore (thanks to Uwe Völker for the report and the patch) | ||||
263 | |||||
264 | =item 0.07, 2009-09-08 | ||||
265 | |||||
266 | Fixed RT#38302: Module::Find now follows symlinks by default (can be disabled). | ||||
267 | |||||
268 | =item 0.08, 2009-09-08 | ||||
269 | |||||
270 | Fixed RT#49511: Removed Mac OS X extended attributes from distribution | ||||
271 | |||||
272 | =item 0.09, 2010-02-26 | ||||
273 | |||||
274 | Fixed RT#38302: Fixed META.yml generation (thanks very much to cpanservice for the help). | ||||
275 | |||||
276 | =item 0.10, 2010-02-26 | ||||
277 | |||||
278 | Fixed RT#55010: Removed Unicode BOM from Find.pm. | ||||
279 | |||||
280 | =back | ||||
281 | |||||
282 | =head1 DEVELOPMENT NOTES | ||||
283 | |||||
284 | Please 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/>. | ||||
285 | |||||
286 | =head1 SEE ALSO | ||||
287 | |||||
288 | L<perl> | ||||
289 | |||||
290 | =head1 AUTHOR | ||||
291 | |||||
292 | Christian Renz, E<lt>crenz@web42.comE<gt> | ||||
293 | |||||
294 | =head1 COPYRIGHT AND LICENSE | ||||
295 | |||||
296 | Copyright 2004-2010 by Christian Renz <crenz@web42.com>. All rights reserved. | ||||
297 | |||||
298 | This library is free software; you can redistribute it and/or modify | ||||
299 | it under the same terms as Perl itself. | ||||
300 | |||||
301 | =cut | ||||
302 | |||||
303 | 1 | 5µs | 1; | ||
sub Module::Find::CORE:ftdir; # opcode | |||||
# spent 103µs within Module::Find::CORE:fteread which was called 41 times, avg 3µs/call:
# 41 times (103µs+0s) by Module::Find::_wanted at line 164, avg 3µs/call | |||||
# spent 21µs within Module::Find::CORE:match which was called 41 times, avg 502ns/call:
# 41 times (21µs+0s) by Module::Find::_wanted at line 164, avg 502ns/call | |||||
# spent 30µs within Module::Find::CORE:subst which was called 41 times, avg 741ns/call:
# 41 times (30µs+0s) by Module::Find::_wanted at line 166, avg 741ns/call |