← Index
Performance Profile   « block view • line view • sub view »
For /wise/base/deliv/dev/bin/getfix
  Run on Thu May 20 15:30:03 2010
Reported on Thu May 20 16:25:28 2010

File/wise/base/static/lib/perl5/site_perl/5.10.0/Module/Find.pm
Statements Executed22
Total Time0.001157 seconds

Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
00000Module::Find::BEGIN
00000Module::Find::_find
00000Module::Find::_wanted
00000Module::Find::findallmod
00000Module::Find::findsubmod
00000Module::Find::setmoduledirs
00000Module::Find::useall
00000Module::Find::usesub

LineStmts.Exclusive
Time
Avg.Code
1package Module::Find;
2
330.000113.6e-5use 5.006001;
434.1e-51.4e-5use strict;
# spent 11µs making 1 call to strict::import
532.6e-58.7e-6use warnings;
# spent 23µs making 1 call to warnings::import
6
732.6e-58.7e-6use File::Spec;
# spent 5µs making 1 call to import
830.000940.00031use File::Find;
# spent 56µs making 1 call to Exporter::import
9
1012.0e-62.0e-6our $VERSION = '0.06';
11
12100our $basedir = undef;
1311.0e-61.0e-6our @results = ();
1411.0e-61.0e-6our $prune = 0;
15
1615.0e-65.0e-6our @ISA = qw(Exporter);
17
1811.0e-61.0e-6our @EXPORT = qw(findsubmod findallmod usesub useall setmoduledirs);
19
20=head1 NAME
21
22Module::Find - Find and use installed modules in a (sub)category
23
24=head1 SYNOPSIS
25
26 use Module::Find;
27
28 # use all modules in the Plugins/ directory
29 @found = usesub Mysoft::Plugins;
30
31 # use modules in all subdirectories
32 @found = useall Mysoft::Plugins;
33
34 # find all DBI::... modules
35 @found = findsubmod DBI;
36
37 # find anything in the CGI/ directory
38 @found = findallmod CGI;
39
40 # set your own search dirs (uses @INC otherwise)
41 setmoduledirs(@INC, @plugindirs, $appdir);
42
43=head1 DESCRIPTION
44
45Module::Find lets you find and use modules in categories. This can be very
46useful for auto-detecting driver or plugin modules. You can differentiate
47between looking in the category itself or in all subcategories.
48
49If you want Module::Find to search in a certain directory on your
50harddisk (such as the plugins directory of your software installation),
51make sure you modify C<@INC> before you call the Module::Find functions.
52
53=head1 FUNCTIONS
54
55=over
56
57=item C<setmoduledirs(@directories)>
58
59Sets the directories to be searched for modules. If not set, Module::Find
60will use @INC. If you use this function, @INC will I<not> be included
61automatically, so add it if you want it. Set to undef to revert to
62default behaviour.
63
64=cut
65
66sub setmoduledirs {
67 return @Module::Find::ModuleDirs = @_;
68}
69
70=item C<@found = findsubmod Module::Category>
71
72Returns modules found in the Module/Category subdirectories of your perl
73installation. E.g. C<findsubmod CGI> will return C<CGI::Session>, but
74not C<CGI::Session::File> .
75
76=cut
77
78sub findsubmod(*) {
79 $prune = 1;
80
81 return _find($_[0]);
82}
83
84=item C<@found = findallmod Module::Category>
85
86Returns modules found in the Module/Category subdirectories of your perl
87installation. E.g. C<findallmod CGI> will return C<CGI::Session> and also
88C<CGI::Session::File> .
89
90=cut
91
92sub findallmod(*) {
93 $prune = 0;
94
95 return _find($_[0]);
96}
97
98=item C<@found = usesub Module::Category>
99
100Uses and returns modules found in the Module/Category subdirectories of your perl
101installation. E.g. C<usesub CGI> will return C<CGI::Session>, but
102not C<CGI::Session::File> .
103
104=cut
105
106sub usesub(*) {
107 $prune = 1;
108
109 my @r = _find($_[0]);
110
111 foreach my $m (@r) {
112 eval " require $m; import $m ; ";
113 die $@ if $@;
114 }
115
116 return @r;
117}
118
119=item C<@found = useall Module::Category>
120
121Uses and returns modules found in the Module/Category subdirectories of your perl
122installation. E.g. C<useall CGI> will return C<CGI::Session> and also
123C<CGI::Session::File> .
124
125=cut
126
127sub useall(*) {
128 $prune = 0;
129
130 my @r = _find($_[0]);
131
132 foreach my $m (@r) {
133 eval " require $m; import $m; ";
134 die $@ if $@;
135 }
136
137 return @r;
138}
139
140# 'wanted' functions for find()
141# you know, this would be a nice application for currying...
142sub _wanted {
143 my $name = File::Spec->abs2rel($_, $basedir);
144 return unless $name && $name ne File::Spec->curdir();
145
146 if (-d && $prune) {
147 $File::Find::prune = 1;
148 return;
149 }
150
151 return unless /\.pm$/ && -r;
152
153 $name =~ s|\.pm$||;
154 $name = join('::', File::Spec->splitdir($name));
155
156 push @results, $name;
157}
158
159
160# helper functions for finding files
161
162sub _find(*) {
163 my ($category) = @_;
164 return undef unless defined $category;
165
166 my $dir = File::Spec->catdir(split(/::/, $category));
167
168 my @dirs;
169 if (defined @Module::Find::ModuleDirs) {
170 @dirs = map { File::Spec->catdir($_, $dir) }
171 @Module::Find::ModuleDirs;
172 } else {
173 @dirs = map { File::Spec->catdir($_, $dir) } @INC;
174 }
175 @results = ();
176
177 foreach $basedir (@dirs) {
178 next unless -d $basedir;
179
180 find({wanted => \&_wanted,
181 no_chdir => 1}, $basedir);
182 }
183
184 # filter duplicate modules
185 my %seen = ();
186 @results = grep { not $seen{$_}++ } @results;
187
188 @results = map "$category\::$_", @results;
189 return @results;
190}
191
192=back
193
194=head1 HISTORY
195
196=over 8
197
198=item 0.01, 2004-04-22
199
200Original version; created by h2xs 1.22
201
202=item 0.02, 2004-05-25
203
204Added test modules that were left out in the first version. Thanks to
205Stuart Johnston for alerting me to this.
206
207=item 0.03, 2004-06-18
208
209Fixed a bug (non-localized $_) by declaring a loop variable in use functions.
210Thanks to Stuart Johnston for alerting me to this and providing a fix.
211
212Fixed non-platform compatibility by using File::Spec.
213Thanks to brian d foy.
214
215Added setmoduledirs and updated tests. Idea shamelessly stolen from
216...errm... inspired by brian d foy.
217
218=item 0.04, 2005-05-20
219
220Added POD tests.
221
222=item 0.05, 2005-11-30
223
224Fixed issue with bugfix in PathTools-3.14.
225
226=item 0.06, 2008-01-26
227
228Module::Find now won't report duplicate modules several times anymore (thanks to Uwe Všlker for the report and the patch)
229
230=back
231
232=head1 SEE ALSO
233
234L<perl>
235
236=head1 AUTHOR
237
238Christian Renz, E<lt>crenz@web42.comE<gt>
239
240=head1 COPYRIGHT AND LICENSE
241
242Copyright 2004-2008 by Christian Renz <crenz@web42.com>. All rights reserved.
243
244This library is free software; you can redistribute it and/or modify
245it under the same terms as Perl itself.
246
247=cut
248
24918.0e-68.0e-61;