| 1 |
#!/usr/bin/env perl |
| 2 |
# pmvers -- print out a module's version, if findable |
| 3 |
|
| 4 |
# ------ pragmas |
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
|
| 8 |
our $VERSION = '2.0.0'; |
| 9 |
|
| 10 |
# ------ define variables |
| 11 |
my $errors = 0; # error count |
| 12 |
my $module = undef; # module name |
| 13 |
my $version = undef; # module version string |
| 14 |
|
| 15 |
BEGIN { $^W = 1 } |
| 16 |
|
| 17 |
$errors = 0; |
| 18 |
|
| 19 |
for $module (@ARGV) { |
| 20 |
eval "local \$^W = 0; require $module"; |
| 21 |
if ($@) { |
| 22 |
$@ =~ s/at \(eval.*$//; |
| 23 |
warn "$0: $@"; |
| 24 |
$errors++; |
| 25 |
next; |
| 26 |
} |
| 27 |
print "$module: " if @ARGV > 1; |
| 28 |
if (defined($version = $module->VERSION())) { |
| 29 |
print "$version\n"; |
| 30 |
} |
| 31 |
else { |
| 32 |
$errors++; |
| 33 |
if (@ARGV > 1) { |
| 34 |
print "unknown version\n"; |
| 35 |
} |
| 36 |
else { |
| 37 |
warn "$0: unknown version for module `$module'\n"; |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
exit ($errors != 0); |
| 43 |
|
| 44 |
|
| 45 |
__END__ |
| 46 |
|
| 47 |
=head1 NAME |
| 48 |
|
| 49 |
pmvers - print out a module's version |
| 50 |
|
| 51 |
=head1 DESCRIPTION |
| 52 |
|
| 53 |
Given one or more module names, show the version number if present. |
| 54 |
If more than one argument is given, the name of the module will also |
| 55 |
be printed. Not all modules define version numbers, however. |
| 56 |
|
| 57 |
=head1 EXAMPLES |
| 58 |
|
| 59 |
$ pmvers CGI |
| 60 |
2.46 |
| 61 |
|
| 62 |
$ pmvers IO::Socket Text::Parsewords |
| 63 |
IO::Socket: 1.25 |
| 64 |
Text::ParseWords: 3.1 |
| 65 |
|
| 66 |
$ oldperl -S pmvers CGI |
| 67 |
2.42 |
| 68 |
|
| 69 |
$ filsperl -S pmvers CGI |
| 70 |
2.46 |
| 71 |
|
| 72 |
$ pmvers Devel::Loaded |
| 73 |
pmvers: unknown version for module `Devel::Loaded' |
| 74 |
|
| 75 |
=head1 SEE ALSO |
| 76 |
|
| 77 |
pmdesc(1), |
| 78 |
pmpath(1), |
| 79 |
pmcat(1). |
| 80 |
|
| 81 |
=head1 AUTHORS and COPYRIGHTS |
| 82 |
|
| 83 |
Copyright (C) 1999 Tom Christiansen. |
| 84 |
|
| 85 |
Copyright (C) 2006-2014 Mark Leighton Fisher. |
| 86 |
|
| 87 |
=head1 LICENSE |
| 88 |
|
| 89 |
This is free software; you can redistribute it and/or modify it |
| 90 |
under the terms of either: |
| 91 |
(a) the GNU General Public License as published by the Free |
| 92 |
Software Foundation; either version 1, or (at your option) any |
| 93 |
later version, or |
| 94 |
(b) the Perl "Artistic License". |
| 95 |
(This is the Perl 5 licensing scheme.) |
| 96 |
|
| 97 |
Please note this is a change from the |
| 98 |
original pmtools-1.00 (still available on CPAN), |
| 99 |
as pmtools-1.00 were licensed only under the |
| 100 |
Perl "Artistic License". |