Skip to content

Instantly share code, notes, and snippets.

@Eckankar
Last active December 9, 2015 09:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eckankar/f61faced8fb7025dedb9 to your computer and use it in GitHub Desktop.
Save Eckankar/f61faced8fb7025dedb9 to your computer and use it in GitHub Desktop.
#!/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