Module-Find-0.11/000755 000765 000024 00000000000 11756557334 014042 5ustar00crenzstaff000000 000000 Module-Find-0.11/Changes000644 000765 000024 00000000052 11341765355 015324 0ustar00crenzstaff000000 000000 See Find.pm for a detaled version history.Module-Find-0.11/examples/000755 000765 000024 00000000000 11756557330 015654 5ustar00crenzstaff000000 000000 Module-Find-0.11/Find.pm000644 000765 000024 00000014622 11756557173 015266 0ustar00crenzstaff000000 000000 package Module::Find; use 5.006001; use strict; use warnings; use File::Spec; use File::Find; our $VERSION = '0.11'; our $basedir = undef; our @results = (); our $prune = 0; our $followMode = 1; our @ISA = qw(Exporter); our @EXPORT = qw(findsubmod findallmod usesub useall setmoduledirs); our @EXPORT_OK = qw(followsymlinks ignoresymlinks); =encoding utf-8 =head1 NAME Module::Find - Find and use installed modules in a (sub)category =head1 SYNOPSIS use Module::Find; # use all modules in the Plugins/ directory @found = usesub Mysoft::Plugins; # use modules in all subdirectories @found = useall Mysoft::Plugins; # find all DBI::... modules @found = findsubmod DBI; # find anything in the CGI/ directory @found = findallmod CGI; # set your own search dirs (uses @INC otherwise) setmoduledirs(@INC, @plugindirs, $appdir); # not exported by default use Module::Find qw(ignoresymlinks followsymlinks); # ignore symlinks ignoresymlinks(); # follow symlinks (default) followsymlinks(); =head1 DESCRIPTION Module::Find lets you find and use modules in categories. This can be very useful for auto-detecting driver or plugin modules. You can differentiate between looking in the category itself or in all subcategories. If you want Module::Find to search in a certain directory on your harddisk (such as the plugins directory of your software installation), make sure you modify C<@INC> before you call the Module::Find functions. =head1 FUNCTIONS =over =item C Sets the directories to be searched for modules. If not set, Module::Find will use @INC. If you use this function, @INC will I be included automatically, so add it if you want it. Set to undef to revert to default behaviour. =cut sub setmoduledirs { return @Module::Find::ModuleDirs = @_; } =item C<@found = findsubmod Module::Category> Returns modules found in the Module/Category subdirectories of your perl installation. E.g. C will return C, but not C . =cut sub findsubmod(*) { $prune = 1; return _find($_[0]); } =item C<@found = findallmod Module::Category> Returns modules found in the Module/Category subdirectories of your perl installation. E.g. C will return C and also C . =cut sub findallmod(*) { $prune = 0; return _find($_[0]); } =item C<@found = usesub Module::Category> Uses and returns modules found in the Module/Category subdirectories of your perl installation. E.g. C will return C, but not C . =cut sub usesub(*) { $prune = 1; my @r = _find($_[0]); foreach my $m (@r) { eval " require $m; import $m ; "; die $@ if $@; } return @r; } =item C<@found = useall Module::Category> Uses and returns modules found in the Module/Category subdirectories of your perl installation. E.g. C will return C and also C . =cut sub useall(*) { $prune = 0; my @r = _find($_[0]); foreach my $m (@r) { eval " require $m; import $m; "; die $@ if $@; } return @r; } # 'wanted' functions for find() # you know, this would be a nice application for currying... sub _wanted { my $name = File::Spec->abs2rel($_, $basedir); return unless $name && $name ne File::Spec->curdir(); if (-d && $prune) { $File::Find::prune = 1; return; } return unless /\.pm$/ && -r; $name =~ s|\.pm$||; $name = join('::', File::Spec->splitdir($name)); push @results, $name; } # helper functions for finding files sub _find(*) { my ($category) = @_; return undef unless defined $category; my $dir = File::Spec->catdir(split(/::/, $category)); my @dirs; if (@Module::Find::ModuleDirs) { @dirs = map { File::Spec->catdir($_, $dir) } @Module::Find::ModuleDirs; } else { @dirs = map { File::Spec->catdir($_, $dir) } @INC; } @results = (); foreach $basedir (@dirs) { next unless -d $basedir; find({wanted => \&_wanted, no_chdir => 1, follow => $followMode}, $basedir); } # filter duplicate modules my %seen = (); @results = grep { not $seen{$_}++ } @results; @results = map "$category\::$_", @results; return @results; } =item C Do not follow symlinks. This function is not exported by default. =cut sub ignoresymlinks { $followMode = 0; } =item C Follow symlinks (default behaviour). This function is not exported by default. =cut sub followsymlinks { $followMode = 1; } =back =head1 HISTORY =over 8 =item 0.01, 2004-04-22 Original version; created by h2xs 1.22 =item 0.02, 2004-05-25 Added test modules that were left out in the first version. Thanks to Stuart Johnston for alerting me to this. =item 0.03, 2004-06-18 Fixed a bug (non-localized $_) by declaring a loop variable in use functions. Thanks to Stuart Johnston for alerting me to this and providing a fix. Fixed non-platform compatibility by using File::Spec. Thanks to brian d foy. Added setmoduledirs and updated tests. Idea shamelessly stolen from ...errm... inspired by brian d foy. =item 0.04, 2005-05-20 Added POD tests. =item 0.05, 2005-11-30 Fixed issue with bugfix in PathTools-3.14. =item 0.06, 2008-01-26 Module::Find now won't report duplicate modules several times anymore (thanks to Uwe Völker for the report and the patch) =item 0.07, 2009-09-08 Fixed RT#38302: Module::Find now follows symlinks by default (can be disabled). =item 0.08, 2009-09-08 Fixed RT#49511: Removed Mac OS X extended attributes from distribution =item 0.09, 2010-02-26 Fixed RT#38302: Fixed META.yml generation (thanks very much to cpanservice for the help). =item 0.10, 2010-02-26 Fixed RT#55010: Removed Unicode BOM from Find.pm. =item 0.11, 2012-05-22 Fixed RT#74251: defined(@array) is deprecated under Perl 5.15.7. =back =head1 DEVELOPMENT NOTES Please report any bugs using the CPAN RT system. The development repository for this module is hosted on GitHub: L. =head1 SEE ALSO L =head1 AUTHOR Christian Renz, Ecrenz@web42.comE =head1 COPYRIGHT AND LICENSE Copyright 2004-2012 by Christian Renz . All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Module-Find-0.11/Makefile.PL000644 000765 000024 00000003620 11341764770 016007 0ustar00crenzstaff000000 000000 use 5.006001; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile1( MIN_PERL_VERSION => '5.006001', META_MERGE => { resources => { repository => 'http://github.com/crenz/Module-Find', }, recommends => { 'Test::Pod::Coverage' => 1.04, 'Test::Pod' => 1.14, #not a build prereq, dist can be built without it }, }, BUILD_REQUIRES => { 'Test::More' => 0, }, NAME => 'Module::Find', VERSION_FROM => 'Find.pm', # finds $VERSION PREREQ_PM => { 'File::Find' => 0, 'File::Spec' => 0}, ABSTRACT_FROM => 'Find.pm', # retrieve abstract from module AUTHOR => 'Christian Renz ', LICENSE => 'perl', ); sub WriteMakefile1 { #Written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade. my %params=@_; my $eumm_version=$ExtUtils::MakeMaker::VERSION; $eumm_version=eval $eumm_version; die "EXTRA_META is deprecated" if exists $params{EXTRA_META}; die "License not specified" if not exists $params{LICENSE}; if ($params{BUILD_REQUIRES} and $eumm_version < 6.5503) { #EUMM 6.5502 has problems with BUILD_REQUIRES $params{PREREQ_PM}={ %{$params{PREREQ_PM} || {}} , %{$params{BUILD_REQUIRES}} }; delete $params{BUILD_REQUIRES}; } delete $params{CONFIGURE_REQUIRES} if $eumm_version < 6.52; delete $params{MIN_PERL_VERSION} if $eumm_version < 6.48; delete $params{META_MERGE} if $eumm_version < 6.46; delete $params{META_ADD} if $eumm_version < 6.46; delete $params{LICENSE} if $eumm_version < 6.31; delete $params{AUTHOR} if $] < 5.005; delete $params{ABSTRACT_FROM} if $] < 5.005; delete $params{BINARY_LOCATION} if $] < 5.005; WriteMakefile(%params); } Module-Find-0.11/MANIFEST000644 000765 000024 00000000732 10746473443 015171 0ustar00crenzstaff000000 000000 Changes examples/example.pl Find.pm Makefile.PL MANIFEST MANIFEST.skip META.yml Module meta-data (added by MakeMaker) README t/1-use.t t/2-find.t t/3-usesub.t t/4-useall.t t/5-setmoduledirs.t t/6-duplicate-modules.t t/pod-coverage.t t/pod.t test/duplicates/ModuleFindTest.pm test/duplicates/ModuleFindTest/SubMod.pm test/duplicates/ModuleFindTest/SubMod/SubSubMod.pm test/ModuleFindTest.pm test/ModuleFindTest/SubMod.pm test/ModuleFindTest/SubMod/SubSubMod.pm test/README Module-Find-0.11/MANIFEST.skip000644 000765 000024 00000000076 10746472251 016133 0ustar00crenzstaff000000 000000 ~$ \.svn \.DS_Store \.bak \.old dist \.tar.gz$ blib Makefile$ Module-Find-0.11/META.yml000644 000765 000024 00000001342 11756557333 015312 0ustar00crenzstaff000000 000000 --- #YAML:1.0 name: Module-Find version: 0.11 abstract: Find and use installed modules in a (sub)category author: - Christian Renz license: perl distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: Test::More: 0 requires: File::Find: 0 File::Spec: 0 perl: 5.006001 resources: repository: http://github.com/crenz/Module-Find no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.56 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 recommends: Test::Pod: 1.14 Test::Pod::Coverage: 1.04 Module-Find-0.11/README000644 000765 000024 00000001253 11756556776 014734 0ustar00crenzstaff000000 000000 Module::Find ============ Module::Find lets you find and use modules in categories. This can be very useful for auto-detecting driver or plugin modules. You can differentiate between looking in the category itself or in all subcategories. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: Test::More File::Spec File::Find COPYRIGHT AND LICENCE Copyright (C) 2004-2012 Christian Renz . All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Module-Find-0.11/t/000755 000765 000024 00000000000 11756557330 014301 5ustar00crenzstaff000000 000000 Module-Find-0.11/test/000755 000765 000024 00000000000 11756557330 015015 5ustar00crenzstaff000000 000000 Module-Find-0.11/test/duplicates/000755 000765 000024 00000000000 11756557330 017152 5ustar00crenzstaff000000 000000 Module-Find-0.11/test/ModuleFindTest/000755 000765 000024 00000000000 11756557330 017703 5ustar00crenzstaff000000 000000 Module-Find-0.11/test/ModuleFindTest.pm000644 000765 000024 00000000066 10745446561 020243 0ustar00crenzstaff000000 000000 package ModuleFindTest; $ModuleFindTest::loaded = 1; Module-Find-0.11/test/README000644 000765 000024 00000000167 10745446561 015701 0ustar00crenzstaff000000 000000 This folder contains a few module files to test the functionality of Module::Find. Use "make test" to run the tests. Module-Find-0.11/test/ModuleFindTest/SubMod/000755 000765 000024 00000000000 11756557327 021102 5ustar00crenzstaff000000 000000 Module-Find-0.11/test/ModuleFindTest/SubMod.pm000644 000765 000024 00000000106 10745446561 021427 0ustar00crenzstaff000000 000000 package ModuleFindTest::SubMod; $ModuleFindTest::SubMod::loaded = 1; Module-Find-0.11/test/ModuleFindTest/SubMod/SubSubMod.pm000644 000765 000024 00000000134 10745446560 023272 0ustar00crenzstaff000000 000000 package ModuleFindTest::SubMod::SubSubMod; $ModuleFindTest::SubMod::SubSubMod::loaded = 1; Module-Find-0.11/test/duplicates/ModuleFindTest/000755 000765 000024 00000000000 11756557330 022040 5ustar00crenzstaff000000 000000 Module-Find-0.11/test/duplicates/ModuleFindTest.pm000644 000765 000024 00000000066 10746470237 022376 0ustar00crenzstaff000000 000000 package ModuleFindTest; $ModuleFindTest::loaded = 1; Module-Find-0.11/test/duplicates/ModuleFindTest/SubMod/000755 000765 000024 00000000000 11756557330 023231 5ustar00crenzstaff000000 000000 Module-Find-0.11/test/duplicates/ModuleFindTest/SubMod.pm000644 000765 000024 00000000106 10746470250 023555 0ustar00crenzstaff000000 000000 package ModuleFindTest::SubMod; $ModuleFindTest::SubMod::loaded = 1; Module-Find-0.11/test/duplicates/ModuleFindTest/SubMod/SubSubMod.pm000644 000765 000024 00000000134 10746470250 025421 0ustar00crenzstaff000000 000000 package ModuleFindTest::SubMod::SubSubMod; $ModuleFindTest::SubMod::SubSubMod::loaded = 1; Module-Find-0.11/t/1-use.t000644 000765 000024 00000000077 10745446561 015424 0ustar00crenzstaff000000 000000 use Test::More tests => 1; BEGIN { use_ok('Module::Find') }; Module-Find-0.11/t/2-find.t000644 000765 000024 00000000457 10745446561 015553 0ustar00crenzstaff000000 000000 use Test::More tests => 5; use Module::Find; use lib qw(./test); my @l; @l = findsubmod ModuleFindTest; ok($#l == 0); ok($l[0] eq 'ModuleFindTest::SubMod'); @l = findallmod ModuleFindTest; ok($#l == 1); ok($l[0] eq 'ModuleFindTest::SubMod'); ok($l[1] eq 'ModuleFindTest::SubMod::SubSubMod'); Module-Find-0.11/t/3-usesub.t000644 000765 000024 00000000622 10745446561 016134 0ustar00crenzstaff000000 000000 use Test::More tests => 4; use Module::Find; use lib qw(./test); my @l; @l = usesub ModuleFindTest; ok($#l == 0); ok($l[0] eq 'ModuleFindTest::SubMod'); ok($ModuleFindTest::SubMod::loaded); ok(!$ModuleFindTest::SubMod::SubSubMod::loaded); package ModuleFindTest::SubMod; $ModuleFindTest::SubMod::loaded = 0; package ModuleFindTest::SubSubMod; $ModuleFindTest::SubMod::SubSubMod::loaded = 0; Module-Find-0.11/t/4-useall.t000644 000765 000024 00000000705 10745446561 016116 0ustar00crenzstaff000000 000000 use Test::More tests => 5; use Module::Find; use lib qw(./test); my @l; @l = useall ModuleFindTest; ok($#l == 1); ok($l[0] eq 'ModuleFindTest::SubMod'); ok($l[1] eq 'ModuleFindTest::SubMod::SubSubMod'); ok($ModuleFindTest::SubMod::loaded); ok($ModuleFindTest::SubMod::SubSubMod::loaded); package ModuleFindTest::SubMod; $ModuleFindTest::SubMod::loaded = 0; package ModuleFindTest::SubSubMod; $ModuleFindTest::SubMod::SubSubMod::loaded = 0; Module-Find-0.11/t/5-setmoduledirs.t000644 000765 000024 00000001162 10745446561 017513 0ustar00crenzstaff000000 000000 use Test::More tests => 9; use Module::Find; # First, with @INC only @l = findsubmod ModuleFindTest; ok($#l == -1); @l = findallmod ModuleFindTest; ok($#l == -1); # Then, including our directory setmoduledirs('./test'); @l = findsubmod ModuleFindTest; ok($#l == 0); ok($l[0] eq 'ModuleFindTest::SubMod'); @l = findallmod ModuleFindTest; ok($#l == 1); ok($l[0] eq 'ModuleFindTest::SubMod'); ok($l[1] eq 'ModuleFindTest::SubMod::SubSubMod'); # Third, reset to @INC only setmoduledirs(); @l = findsubmod ModuleFindTest; ok($#l == -1); @l = findallmod ModuleFindTest; ok($#l == -1); # Then, including our directory Module-Find-0.11/t/6-duplicate-modules.t000644 000765 000024 00000000264 10746470350 020245 0ustar00crenzstaff000000 000000 use Test::More tests => 1; use Module::Find; use lib qw(./test ./test/duplicates); # Ensure duplicate modules are only reported once my @l = useall ModuleFindTest; ok($#l == 1);Module-Find-0.11/t/pod-coverage.t000644 000765 000024 00000000254 10745446561 017042 0ustar00crenzstaff000000 000000 #!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); Module-Find-0.11/t/pod.t000644 000765 000024 00000000214 10745446561 015245 0ustar00crenzstaff000000 000000 #!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); Module-Find-0.11/examples/example.pl000644 000765 000024 00000000570 10746473423 017644 0ustar00crenzstaff000000 000000 use Module::Find; # use all modules in the Plugins/ directory @found = usesub Mysoft::Plugins; # use modules in all subdirectories @found = useall Mysoft::Plugins; # find all DBI::... modules @found = findsubmod DBI; # find anything in the CGI/ directory @found = findallmod CGI; # set your own search dirs (uses @INC otherwise) setmoduledirs(@INC, @plugindirs, $appdir);