Last active
December 9, 2015 09:50
-
-
Save Eckankar/f61faced8fb7025dedb9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/env perl | |
use 5.012; | |
use warnings; | |
use File::Spec; | |
=head1 NAME | |
C<perlopen.pl> - Open perl modules quickly and easily | |
=head1 DESCRIPTION | |
Opens the modules specfied as arguments in your default text editor. | |
The environment variable C<EDITOR> must be set. | |
=head1 USAGE | |
perlopen module [module2 ...] | |
Example: | |
perlopen WWW::Mechanize Test::Deep | |
=cut | |
my @files = (); | |
sub demodulify { | |
my $module = shift; | |
$module =~ s{::}{/}g; | |
return "$module.pm"; | |
} | |
my $die = 0; | |
for my $m (@ARGV) { | |
my $f = demodulify($m); | |
my $fn; | |
for my $i (@INC) { | |
my $if = File::Spec->catfile($i, $f); | |
if (-e $if) { | |
$fn = $if; | |
last; | |
} | |
} | |
if ($fn) { | |
push(@files, $fn); | |
} else { | |
warn "Cannot locate module $m."; | |
$die = 1; | |
} | |
} | |
exit(1) if $die; | |
exec (split(/ /,$ENV{EDITOR}), @files); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment