Skip to content

Instantly share code, notes, and snippets.

@globau
Created January 31, 2013 16:15
Show Gist options
  • Save globau/4684007 to your computer and use it in GitHub Desktop.
Save globau/4684007 to your computer and use it in GitHub Desktop.
give perlwhich a module name, and it will tell which which file defines it.
#!/usr/bin/perl
use strict;
my $syntax = <<EOF;
syntax: perlwhich [-v] <package>
displays the file where <package> is implemented
-v shows the version of any packages found
EOF
my $show_version = grep { $_ eq '-v' } @ARGV;
@ARGV = grep { !/^-/ } @ARGV;
my $package = shift or die $syntax;
$package =~ s/-/::/g;
my $file = $package;
$file =~ s/::/\//g;
$file .= '.pm';
our @INC;
foreach my $dir (@INC) {
next unless -e "$dir/$file";
print "$dir/$file";
if ($show_version) {
require "$dir/$file";
my $version;
eval '$version = $' . $package . '::VERSION';
print " v$version" if $version;
}
print "\n";
exit;
}
print "$package not found\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment