Advertisement
Guest User

mutew

a guest
May 30th, 2009
1,955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.30 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. use File::Find;
  6.  
  7. my $modPattern = shift;
  8. my @match;
  9.  
  10. find( { wanted => \&findModules,
  11.         follow => 1,
  12.         no_chdir => 1,
  13.       },
  14.       ## Do not include the '.' directory in the file search,
  15.       ## This is to prevent issues with recursing soft-links
  16.       ## TODO: fix the softlink issue outlined above
  17.       grep { $_ !~ '^\.$' } @INC
  18. );
  19.  
  20. eval { defined $modPattern && "" =~ /$modPattern/ };
  21. die "Invalid pattern : $modPattern\n" if $@;
  22.  
  23. sub findModules {
  24.     my $fullPath = $File::Find::name;
  25.     my $regExp = join "|", @INC;
  26.    
  27.     if ( -f $fullPath && m{\.pm$} ) {
  28.         # Format the perl module to its :: eq name
  29.         my $modName = $fullPath;
  30.         # Replace the leading directory name and trailing .pm extension
  31.         $modName =~ s/^($regExp)[\\\/](.+)\.pm/$2/;
  32.         # Change all separators to ::
  33.         $modName =~ s/[\/\\]/::/g;
  34.        
  35.         # Check the module name against the user-supplied expression
  36.         # if any, else just populate it into @match
  37.         if ( defined $modPattern ) {
  38.             push @match, $modName
  39.               if $modName =~ m{$modPattern}i;
  40.         }
  41.         else {
  42.             push @match, $modName;
  43.         }
  44.     }
  45. }
  46.  
  47. print join "\n", @match;
  48. print "\n" if @match;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement