2 #---------------------------------------------------------------------
3 # $Id: pmver.pl 2537 2011-10-27 07:20:59Z cjm $
4 # Copyright 2007 Christopher J. Madsen <perl@cjmweb.net>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the same terms as Perl itself.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
12 # GNU General Public License or the Artistic License for more details.
14 # Print version numbers for Perl modules
15 #---------------------------------------------------------------------
18 use Getopt
::Long
2.10;
20 my $VERSION = join('', 'r', (q
$Rev: 2537 $ =~ /(\d+)/));
22 #---------------------------------------------------------------------
23 my ($editModule, $pathOnly);
25 Getopt
::Long
::config
(qw(bundling no_getopt_compat));
27 'edit|e' => \
$editModule,
28 'path-only|p'=>\
$pathOnly,
29 'x' => sub { warn "-x is deprecated, use -e instead\n";
38 print "pmver $VERSION\n";
39 exit if $_[0] and $_[0] eq 'version';
40 print "\n" . <<'END HELP';
41 Usage: pmver [options] MODULE ...
42 -e, --edit Open MODULE.pm in your editor
43 -p, --path-only Display only the pathname (no version)
44 -?, --help Display this help message
45 --version Display version information
51 #---------------------------------------------------------------------
54 foreach my $module (@ARGV) {
55 $module =~ s!\s+\z!!g; # Remove trailing space, just in case
56 $module =~ s![-/\\ ]!::!g; # Allow pathnames and distribution names
57 $module =~ s!^dzp::!Dist::Zilla::Plugin::!i;
58 $module =~ s!^dzpb::!Dist::Zilla::PluginBundle::!i;
60 eval "require $module;";
62 $error =~ s/\s+at \(eval \d+\) line \d+\.$//;
63 print "$module not found:\n$error\n";
68 my $fn = $INC{"$file.pm"};
73 my $version = $module->VERSION;
74 printf("%s %s is\n %s\n",
75 $module, (defined $version ?
$version : '<NO $VERSION>'),
80 my $editor = ($ENV{EDITOR_NOWAIT
} || $ENV{VISUAL
} || $ENV{EDITOR
} ||
81 die "Please set EDITOR_NOWAIT, VISUAL, or EDITOR\n");
82 system qq'$editor "$fn"';
84 } # end else module found
85 } # end foreach module to check