#! /usr/bin/perl -w #--------------------------------------------------------------------- # $Id: perlver.pl 1800 2007-05-12 23:24:13Z cjm $ # Copyright 2007 Christopher J. Madsen # # This program is free software; you can redistribute it and/or modify # it under the same terms as Perl itself. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the # GNU General Public License or the Artistic License for more details. # # Print version numbers for Perl modules #--------------------------------------------------------------------- use strict; use Getopt::Long 2.10; my $VERSION = join('', 'r', (q$Rev: 1800 $ =~ /(\d+)/)); #--------------------------------------------------------------------- my $editModule; Getopt::Long::config(qw(bundling no_getopt_compat)); GetOptions( 'edit|e' => \$editModule, 'x' => sub { warn "-x is deprecated, use -e instead\n"; $editModule = 1 }, 'help' => \&usage, 'version' => \&usage ) or usage(); usage() unless @ARGV; sub usage { print "perlver $VERSION\n"; exit if $_[0] and $_[0] eq 'version'; print "\n" . <<'END HELP'; Usage: perlver [options] MODULE ... -e, --edit Open MODULE.pm in your editor -?, --help Display this help message --version Display version information END HELP exit; } # end usage #--------------------------------------------------------------------- foreach my $module (@ARGV) { $module =~ s![-/\\]!::!g; # Allow pathnames and distribution names eval "require $module;"; if (my $error = $@) { $error =~ s/\s+at \(eval \d+\) line \d+\.$//; print "$module not found:\n$error\n"; } else { my $file = $module; $file =~ s!::!/!g; my $fn = $INC{"$file.pm"}; my $version = $module->VERSION; printf("%s %s is\n %s\n", $module, (defined $version ? $version : ''), $fn); if ($editModule) { my $editor = ($ENV{EDITOR_NOWAIT} || $ENV{VISUAL} || $ENV{EDITOR} || die "Please set EDITOR_NOWAIT, VISUAL, or EDITOR\n"); system qq'$editor "$fn"'; } } # end else module found } # end foreach module to check