I mostly use this for things I install from CPAN, which are (usually!) well-behaved. But your point is well taken. It also won't work if the module has any sort of error in it.
I found a copy of pmtools here in perl.org and I think you're referring to the pmpath program in it; to get the same effect as this, you would do vi `pmpath What::Ever`. But pmpath also has the same issue in that it does a require of the module.
So here's a variation that walks down your @INC statically until it finds a file fitting the description:
#!/usr/bin/perl -w
ARG:
foreach (@ARGV)
{
next if /^-/;
s|::|/|g;
$_ .= '.pm' unless /\.pm$/;
foreach my $d (@INC)
{
$_ = "$d/$_", next ARG if -f "$d/$_" and -r _;
}
die "Can't find a module named $_\n";
}
exec $ENV{EDITOR} || '/bin/vi', @ARGV;
Arguments starting with - are still passed through unchanged, and it still doesn't do a lot of error checking.
Props to merlyn for pushing me to improve the
code. ;-) |