#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
my $modPattern = shift;
my @match;
find( { wanted => \&findModules,
follow => 1,
no_chdir => 1,
},
## Do not include the '.' directory in the file search,
## This is to prevent issues with recursing soft-links
## TODO: fix the softlink issue outlined above
grep { $_ !~ '^\.$' } @INC
);
eval { defined $modPattern && "" =~ /$modPattern/ };
die "Invalid pattern : $modPattern\n" if $@;
sub findModules {
my $fullPath = $File::Find::name;
my $regExp = join "|", @INC;
if ( -f $fullPath && m{\.pm$} ) {
# Format the perl module to its :: eq name
my $modName = $fullPath;
# Replace the leading directory name and trailing .pm extension
$modName =~ s/^($regExp)[\\\/](.+)\.pm/$2/;
# Change all separators to ::
$modName =~ s/[\/\\]/::/g;
# Check the module name against the user-supplied expression
# if any, else just populate it into @match
if ( defined $modPattern ) {
push @match, $modName
if $modName =~ m{$modPattern}i;
}
else {
push @match, $modName;
}
}
}
print join "\n", @match;
print "\n" if @match;