#!/usr/bin/perl -w
#
# Return all modules in the @IRC path
# that match the regexp given on the command line, case-insensitive
#
# Copyright (C) Bek Oberin, 1998.  Artistic licence, like Perl.
# Be nice.
#
# Arkuat <arkuat@idiom.com> helped.
#
# Last updated by gossamer on Fri Nov  6 13:33:14 EST 1998
#

=pod

=head findmod

     findmod some_regexp

=head1 DESCRIPTION

  B<findmod> looks through your modules and returns the module
  names of all those that match (case-insensitive) the regexp
  given.  For example, all modules C<findmod SQL> on my system
  returns:

     DBD::mysql
     Mysql

=head1 AUTHOR

   Gossamer <gossamer@tertius.net.au>

=head1 PREREQUISITES
File::Find
=head1 SCRIPT CATEGORIES
Perl
=cut
#


use strict;
use File::Find;

my @modules;

# return only matching modules
sub wanted { 
   /^.*\.pm$/ && /$ARGV[0]/i && push @modules, $File::Find::name;
}

# look in the @IRC dirs that exist
find(\&wanted, grep { -r and -d } @INC);

# de-dupe
my %saw;
@modules = grep(!$saw{$_}++, @modules);

# strip extraneous directories off the modules
for my $prefix ( sort { length $b <=> length $a } @INC ) {
   for (@modules) { 
      next if s/^\Q$prefix// 
   }
}

# nice printout
foreach (@modules) {
   s#^/(.*)\.pm$#$1#;
   s#/#::#;
   print "$_\n";
}

#
# End.
#