| Filename | /usr/share/perl5/Module/Find.pm |
| Statements | Executed 0 statements in 0s |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 517 | 1 | 1 | 4.34ms | 4.34ms | Module::Find::CORE:subst (opcode) |
| 541 | 2 | 1 | 2.24ms | 2.24ms | Module::Find::CORE:ftdir (opcode) |
| 517 | 1 | 1 | 1.41ms | 1.41ms | Module::Find::CORE:fteread (opcode) |
| 691 | 2 | 1 | 990µs | 990µs | Module::Find::CORE:match (opcode) |
| 2 | 1 | 1 | 721µs | 92.6ms | Module::Find::_find |
| 1 | 1 | 1 | 26µs | 3.07ms | Module::Find::BEGIN@5 |
| 1 | 1 | 1 | 24µs | 24µs | Module::Find::BEGIN@3 |
| 1 | 1 | 1 | 17µs | 62µs | Module::Find::BEGIN@8 |
| 1 | 1 | 1 | 14µs | 14µs | Module::Find::BEGIN@7 |
| 2 | 1 | 1 | 10µs | 92.6ms | Module::Find::findallmod |
| 1 | 1 | 1 | 8µs | 16µs | Module::Find::BEGIN@4 |
| 0 | 0 | 0 | 0s | 0s | Module::Find::_wanted |
| 0 | 0 | 0 | 0s | 0s | Module::Find::findsubmod |
| 0 | 0 | 0 | 0s | 0s | Module::Find::followsymlinks |
| 0 | 0 | 0 | 0s | 0s | Module::Find::ignoresymlinks |
| 0 | 0 | 0 | 0s | 0s | Module::Find::setmoduledirs |
| 0 | 0 | 0 | 0s | 0s | Module::Find::useall |
| 0 | 0 | 0 | 0s | 0s | Module::Find::usesub |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Module::Find; | ||||
| 2 | |||||
| 3 | 1 | 24µs | # spent 24µs within Module::Find::BEGIN@3 which was called:
# once (24µs+0s) by DBIx::Class::Schema::_findallmod at line 3 # spent 24µs making 1 call to Module::Find::BEGIN@3 | ||
| 4 | 2 | 25µs | # spent 16µs (8+8) within Module::Find::BEGIN@4 which was called:
# once (8µs+8µs) by DBIx::Class::Schema::_findallmod at line 4 # spent 16µs making 1 call to Module::Find::BEGIN@4
# spent 8µs making 1 call to strict::import | ||
| 5 | 2 | 6.12ms | # spent 3.07ms (26µs+3.05) within Module::Find::BEGIN@5 which was called:
# once (26µs+3.05ms) by DBIx::Class::Schema::_findallmod at line 5 # spent 3.07ms making 1 call to Module::Find::BEGIN@5
# spent 3.05ms making 1 call to warnings::import | ||
| 6 | |||||
| 7 | 1 | 14µs | # spent 14µs within Module::Find::BEGIN@7 which was called:
# once (14µs+0s) by DBIx::Class::Schema::_findallmod at line 7 # spent 14µs making 1 call to Module::Find::BEGIN@7 | ||
| 8 | 2 | 108µs | # spent 62µs (17+45) within Module::Find::BEGIN@8 which was called:
# once (17µs+45µs) by DBIx::Class::Schema::_findallmod at line 8 # spent 62µs making 1 call to Module::Find::BEGIN@8
# spent 45µs making 1 call to Exporter::import | ||
| 9 | |||||
| 10 | our $VERSION = '0.12'; | ||||
| 11 | |||||
| 12 | our $basedir = undef; | ||||
| 13 | our @results = (); | ||||
| 14 | our $prune = 0; | ||||
| 15 | our $followMode = 1; | ||||
| 16 | |||||
| 17 | our @ISA = qw(Exporter); | ||||
| 18 | |||||
| 19 | our @EXPORT = qw(findsubmod findallmod usesub useall setmoduledirs); | ||||
| 20 | |||||
| 21 | 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 = grep { defined } @_; | ||||
| 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 92.6ms (10µs+92.6) within Module::Find::findallmod which was called 2 times, avg 46.3ms/call:
# 2 times (10µs+92.6ms) by DBIx::Class::Schema::_findallmod at line 168 of DBIx/Class/Schema.pm, avg 46.3ms/call | ||||
| 107 | $prune = 0; | ||||
| 108 | |||||
| 109 | 2 | 92.6ms | return _find($_[0]); # spent 92.6ms making 2 calls to Module::Find::_find, avg 46.3ms/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 | If any module dies during loading, usesub will also die at this point. | ||||
| 119 | |||||
| 120 | =cut | ||||
| 121 | |||||
| 122 | sub 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 | |||||
| 137 | 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 | ||||
| 138 | C<CGI::Session::File> . | ||||
| 139 | |||||
| 140 | If any module dies during loading, useall will also die at this point. | ||||
| 141 | |||||
| 142 | =cut | ||||
| 143 | |||||
| 144 | sub 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... | ||||
| 159 | sub _wanted { | ||||
| 160 | 520 | 40.8ms | my $name = File::Spec->abs2rel($_, $basedir); # spent 40.8ms making 520 calls to File::Spec::Unix::abs2rel, avg 78µs/call | ||
| 161 | 520 | 323µs | return unless $name && $name ne File::Spec->curdir(); # spent 323µs making 520 calls to File::Spec::Unix::curdir, avg 621ns/call | ||
| 162 | |||||
| 163 | 517 | 2.14ms | if (-d && $prune) { # spent 2.14ms making 517 calls to Module::Find::CORE:ftdir, avg 4µs/call | ||
| 164 | $File::Find::prune = 1; | ||||
| 165 | return; | ||||
| 166 | } | ||||
| 167 | |||||
| 168 | 1034 | 2.20ms | return unless /\.pm$/ && -r; # spent 1.41ms making 517 calls to Module::Find::CORE:fteread, avg 3µs/call
# spent 787µs making 517 calls to Module::Find::CORE:match, avg 2µs/call | ||
| 169 | |||||
| 170 | 517 | 4.34ms | $name =~ s|\.pm$||; # spent 4.34ms making 517 calls to Module::Find::CORE:subst, avg 8µs/call | ||
| 171 | 517 | 617µs | $name = join('::', File::Spec->splitdir($name)); # spent 617µs making 517 calls to File::Spec::Unix::splitdir, avg 1µs/call | ||
| 172 | |||||
| 173 | push @results, $name; | ||||
| 174 | } | ||||
| 175 | |||||
| 176 | |||||
| 177 | # helper functions for finding files | ||||
| 178 | |||||
| 179 | # spent 92.6ms (721µs+91.9) within Module::Find::_find which was called 2 times, avg 46.3ms/call:
# 2 times (721µs+91.9ms) by Module::Find::findallmod at line 109, avg 46.3ms/call | ||||
| 180 | my ($category) = @_; | ||||
| 181 | return undef unless defined $category; | ||||
| 182 | |||||
| 183 | 4 | 23µs | my $dir = File::Spec->catdir(split(/::/, $category)); # spent 21µs making 2 calls to File::Spec::Unix::catdir, avg 10µs/call
# spent 2µs making 2 calls to File::Spec::Unix::canonpath, avg 1µs/call | ||
| 184 | |||||
| 185 | my @dirs; | ||||
| 186 | if (@Module::Find::ModuleDirs) { | ||||
| 187 | @dirs = map { File::Spec->catdir($_, $dir) } | ||||
| 188 | @Module::Find::ModuleDirs; | ||||
| 189 | } else { | ||||
| 190 | 48 | 81µs | @dirs = map { File::Spec->catdir($_, $dir) } @INC; # spent 69µs making 24 calls to File::Spec::Unix::catdir, avg 3µs/call
# spent 12µs making 24 calls to File::Spec::Unix::canonpath, avg 496ns/call | ||
| 191 | } | ||||
| 192 | @results = (); | ||||
| 193 | |||||
| 194 | foreach $basedir (@dirs) { | ||||
| 195 | 24 | 104µs | next unless -d $basedir; # spent 104µs making 24 calls to Module::Find::CORE:ftdir, avg 4µs/call | ||
| 196 | |||||
| 197 | 3 | 91.5ms | find({wanted => \&_wanted, # spent 91.5ms making 3 calls to File::Find::find, avg 30.5ms/call | ||
| 198 | no_chdir => 1, | ||||
| 199 | follow => $followMode}, $basedir); | ||||
| 200 | } | ||||
| 201 | |||||
| 202 | # filter duplicate modules | ||||
| 203 | my %seen = (); | ||||
| 204 | @results = grep { not $seen{$_}++ } @results; | ||||
| 205 | |||||
| 206 | @results = map "$category\::$_", @results; | ||||
| 207 | |||||
| 208 | 174 | 204µs | @results = map { # spent 204µs making 174 calls to Module::Find::CORE:match, avg 1µs/call | ||
| 209 | ($_ =~ m{^(\w+(?:::\w+)*)$})[0] || die "$_ does not look like a package name" | ||||
| 210 | } @results; | ||||
| 211 | |||||
| 212 | return @results; | ||||
| 213 | } | ||||
| 214 | |||||
| 215 | =item C<ignoresymlinks()> | ||||
| 216 | |||||
| 217 | Do not follow symlinks. This function is not exported by default. | ||||
| 218 | |||||
| 219 | =cut | ||||
| 220 | |||||
| 221 | sub ignoresymlinks { | ||||
| 222 | $followMode = 0; | ||||
| 223 | } | ||||
| 224 | |||||
| 225 | =item C<followsymlinks()> | ||||
| 226 | |||||
| 227 | Follow symlinks (default behaviour). This function is not exported by default. | ||||
| 228 | |||||
| 229 | =cut | ||||
| 230 | |||||
| 231 | sub 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 | |||||
| 243 | Original version; created by h2xs 1.22 | ||||
| 244 | |||||
| 245 | =item 0.02, 2004-05-25 | ||||
| 246 | |||||
| 247 | Added test modules that were left out in the first version. Thanks to | ||||
| 248 | Stuart Johnston for alerting me to this. | ||||
| 249 | |||||
| 250 | =item 0.03, 2004-06-18 | ||||
| 251 | |||||
| 252 | Fixed a bug (non-localized $_) by declaring a loop variable in use functions. | ||||
| 253 | Thanks to Stuart Johnston for alerting me to this and providing a fix. | ||||
| 254 | |||||
| 255 | Fixed non-platform compatibility by using File::Spec. | ||||
| 256 | Thanks to brian d foy. | ||||
| 257 | |||||
| 258 | Added setmoduledirs and updated tests. Idea shamelessly stolen from | ||||
| 259 | ...errm... inspired by brian d foy. | ||||
| 260 | |||||
| 261 | =item 0.04, 2005-05-20 | ||||
| 262 | |||||
| 263 | Added POD tests. | ||||
| 264 | |||||
| 265 | =item 0.05, 2005-11-30 | ||||
| 266 | |||||
| 267 | Fixed issue with bugfix in PathTools-3.14. | ||||
| 268 | |||||
| 269 | =item 0.06, 2008-01-26 | ||||
| 270 | |||||
| 271 | Module::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 | |||||
| 275 | Fixed RT#38302: Module::Find now follows symlinks by default (can be disabled). | ||||
| 276 | |||||
| 277 | =item 0.08, 2009-09-08 | ||||
| 278 | |||||
| 279 | Fixed RT#49511: Removed Mac OS X extended attributes from distribution | ||||
| 280 | |||||
| 281 | =item 0.09, 2010-02-26 | ||||
| 282 | |||||
| 283 | Fixed RT#38302: Fixed META.yml generation (thanks very much to cpanservice for the help). | ||||
| 284 | |||||
| 285 | =item 0.10, 2010-02-26 | ||||
| 286 | |||||
| 287 | Fixed RT#55010: Removed Unicode BOM from Find.pm. | ||||
| 288 | |||||
| 289 | =item 0.11, 2012-05-22 | ||||
| 290 | |||||
| 291 | Fixed RT#74251: defined(@array) is deprecated under Perl 5.15.7. | ||||
| 292 | Thanks to Roman F, who contributed the implementation. | ||||
| 293 | |||||
| 294 | =item 0.12, 2014-02-08 | ||||
| 295 | |||||
| 296 | Fixed RT#81077: useall fails in taint mode | ||||
| 297 | Thanks to Aran Deltac, who contributed the implementation and test. | ||||
| 298 | |||||
| 299 | Fixed RT#83596: Documentation doesn't describe behaviour if a module fails to load | ||||
| 300 | Clarified documentation for useall and usesub. | ||||
| 301 | |||||
| 302 | Fixed RT#62923: setmoduledirs(undef) doesn't reset to searching @INC | ||||
| 303 | Added more explicit tests. | ||||
| 304 | Thanks to Colin Robertson for his input. | ||||
| 305 | |||||
| 306 | =back | ||||
| 307 | |||||
| 308 | =head1 DEVELOPMENT NOTES | ||||
| 309 | |||||
| 310 | 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/>. | ||||
| 311 | |||||
| 312 | =head1 SEE ALSO | ||||
| 313 | |||||
| 314 | L<perl> | ||||
| 315 | |||||
| 316 | =head1 AUTHOR | ||||
| 317 | |||||
| 318 | Christian Renz, E<lt>crenz@web42.comE<gt> | ||||
| 319 | |||||
| 320 | =head1 COPYRIGHT AND LICENSE | ||||
| 321 | |||||
| 322 | Copyright 2004-2014 by Christian Renz <crenz@web42.com>. All rights reserved. | ||||
| 323 | |||||
| 324 | This library is free software; you can redistribute it and/or modify | ||||
| 325 | it under the same terms as Perl itself. | ||||
| 326 | |||||
| 327 | =cut | ||||
| 328 | |||||
| 329 | 1; | ||||
sub Module::Find::CORE:ftdir; # opcode | |||||
# spent 1.41ms within Module::Find::CORE:fteread which was called 517 times, avg 3µs/call:
# 517 times (1.41ms+0s) by File::Find::find at line 168, avg 3µs/call | |||||
sub Module::Find::CORE:match; # opcode | |||||
# spent 4.34ms within Module::Find::CORE:subst which was called 517 times, avg 8µs/call:
# 517 times (4.34ms+0s) by File::Find::find at line 170, avg 8µs/call |