Created
March 13, 2013 16:02
-
-
Save alecs/5153540 to your computer and use it in GitHub Desktop.
perl modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment