Created
January 31, 2013 16:15
-
-
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.
This file contains 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; | |
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