| 1 |
#!/usr/bin/env perl |
| 2 |
# pmall -- show all installed versions and descs |
| 3 |
|
| 4 |
use strict; |
| 5 |
use warnings; |
| 6 |
use File::Find qw(find); |
| 7 |
use Getopt::Std qw(getopts); |
| 8 |
use Carp; |
| 9 |
|
| 10 |
use vars ( |
| 11 |
q!$opt_v!, # give debug info |
| 12 |
q!$opt_w!, # warn about missing descs on modules |
| 13 |
q!$opt_a!, # include relative paths |
| 14 |
q!$opt_s!, # sort output within each directory |
| 15 |
); |
| 16 |
|
| 17 |
our $VERSION = '2.0.0'; |
| 18 |
|
| 19 |
$| = 1; |
| 20 |
|
| 21 |
getopts('wvas') || die "bad usage"; |
| 22 |
|
| 23 |
@ARGV = @INC unless @ARGV; |
| 24 |
|
| 25 |
|
| 26 |
# Globals. wish I didn't really have to do this. |
| 27 |
use vars ( |
| 28 |
q!$Start_Dir!, # The top directory find was called with |
| 29 |
q!%Future!, # topdirs find will handle later |
| 30 |
); |
| 31 |
|
| 32 |
my $Module; |
| 33 |
|
| 34 |
if ($opt_s) { |
| 35 |
if (open(ME, "-|")) { |
| 36 |
$/ = ''; |
| 37 |
while (<ME>) { |
| 38 |
chomp; |
| 39 |
print join("\n", sort split /\n/), "\n"; |
| 40 |
} |
| 41 |
exit; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
MAIN: { |
| 46 |
my %visited; |
| 47 |
my ($dev,$ino); |
| 48 |
|
| 49 |
@Future{@ARGV} = (1) x @ARGV; |
| 50 |
|
| 51 |
foreach $Start_Dir (@ARGV) { |
| 52 |
delete $Future{$Start_Dir}; |
| 53 |
|
| 54 |
print "\n<<Modules from $Start_Dir>>\n\n" |
| 55 |
if $opt_v; |
| 56 |
|
| 57 |
next unless ($dev,$ino) = stat($Start_Dir); |
| 58 |
next if $visited{$dev,$ino}++; |
| 59 |
next unless $opt_a || $Start_Dir =~ m!^/!; |
| 60 |
|
| 61 |
find(\&wanted, $Start_Dir); |
| 62 |
} |
| 63 |
exit; |
| 64 |
} |
| 65 |
|
| 66 |
sub modname { |
| 67 |
local $_ = $File::Find::name; |
| 68 |
|
| 69 |
if (index($_, $Start_Dir . '/') == 0) { |
| 70 |
substr($_, 0, 1+length($Start_Dir)) = ''; |
| 71 |
} |
| 72 |
|
| 73 |
s { / } {::}gx; |
| 74 |
s { \.p(m|od)$ } {}x; |
| 75 |
|
| 76 |
return $_; |
| 77 |
} |
| 78 |
|
| 79 |
sub wanted { |
| 80 |
if ( $Future{$File::Find::name} ) { |
| 81 |
warn "\t(Skipping $File::Find::name, qui venit in futuro.)\n" |
| 82 |
if 0 and $opt_v; |
| 83 |
$File::Find::prune = 1; |
| 84 |
return; |
| 85 |
} |
| 86 |
return unless /\.pm$/ && -f; |
| 87 |
$Module = &modname; |
| 88 |
|
| 89 |
my $file = $_; |
| 90 |
|
| 91 |
unless (open(POD, "< $file")) { |
| 92 |
warn "\tcannot open $file: $!"; |
| 93 |
# if $opt_w; |
| 94 |
return 0; |
| 95 |
} |
| 96 |
|
| 97 |
$: = " -:"; |
| 98 |
|
| 99 |
local $/ = ''; |
| 100 |
local $_; |
| 101 |
while (<POD>) { |
| 102 |
if (/=head\d\s+NAME/) { |
| 103 |
chomp($_ = <POD>); |
| 104 |
s/^.*?-\s+//s; |
| 105 |
s/\n/ /g; |
| 106 |
#write; |
| 107 |
my $v; |
| 108 |
if (defined ($v = getversion($Module))) { |
| 109 |
print "$Module ($v) "; |
| 110 |
} else { |
| 111 |
print "$Module "; |
| 112 |
} |
| 113 |
print "- $_\n"; |
| 114 |
return 1; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
warn "\t(MISSING DESC FOR $File::Find::name)\n" |
| 119 |
if $opt_w; |
| 120 |
|
| 121 |
return 0; |
| 122 |
} |
| 123 |
|
| 124 |
sub getversion { |
| 125 |
my $mod = shift; |
| 126 |
my $vers = `$^X -m$mod -e 'print \$${mod}::VERSION' 2>&1`; |
| 127 |
#my $vers = `$^X -m$mod -e 'print \$${mod}::VERSION' 2>/dev/null`; |
| 128 |
# 2> due to errors from MM_Unix etc |
| 129 |
$vers =~ s/^\s*(.*?)\s*$/$1/; # why is there whitespace here?? |
| 130 |
return ($vers || undef); |
| 131 |
} |
| 132 |
|
| 133 |
sub getversion_internal { |
| 134 |
# This should really use system(), because otherwise we bloat. |
| 135 |
my $mod = shift; |
| 136 |
local $SIG{__WARN__} = sub {}; |
| 137 |
eval "local \$^W = 0; require $mod"; |
| 138 |
if ($@) { |
| 139 |
warn "Cannot require $mod -- $@\n" |
| 140 |
if $opt_v; |
| 141 |
return; |
| 142 |
} |
| 143 |
my $vers; |
| 144 |
{ |
| 145 |
no strict 'refs'; |
| 146 |
return unless defined ($vers = ${ $mod . "::VERSION" }); |
| 147 |
} |
| 148 |
$vers =~ s/^\s*(.*?)\s*$/$1/; # why is there whitespace here?? |
| 149 |
return $vers; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
format = |
| 154 |
^<<<<<<<<<<<<<<<<<~~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 155 |
$Module, $_ |
| 156 |
. |
| 157 |
|
| 158 |
__END__ |
| 159 |
|
| 160 |
=head1 NAME |
| 161 |
|
| 162 |
pmall - show all installed versions and descs |
| 163 |
|
| 164 |
=head1 SYNOPSIS |
| 165 |
|
| 166 |
pmall [-d] [-w] [-a] [-s] |
| 167 |
|
| 168 |
pmall - show all installed versions and descs |
| 169 |
|
| 170 |
=head1 DESCRIPTION |
| 171 |
|
| 172 |
This program runs through all your installed modules |
| 173 |
and tells you what they're for and what version |
| 174 |
number they are at. |
| 175 |
|
| 176 |
The following options are honored: |
| 177 |
|
| 178 |
=over 4 |
| 179 |
|
| 180 |
=item -v |
| 181 |
|
| 182 |
give debug info |
| 183 |
|
| 184 |
=item -w |
| 185 |
|
| 186 |
warn about missing descriptions on modules |
| 187 |
|
| 188 |
=item -a |
| 189 |
|
| 190 |
include relative paths |
| 191 |
|
| 192 |
=item -s |
| 193 |
|
| 194 |
sort output within each directory |
| 195 |
|
| 196 |
=back |
| 197 |
|
| 198 |
=head1 HISTORICAL NOTE |
| 199 |
|
| 200 |
This program used to be called I<pmdesc> and is included in I<The Perl |
| 201 |
Cookbook> under that name. However, that name has been usurped by |
| 202 |
a simpler program. |
| 203 |
|
| 204 |
For example, to find the versions of what is in your site-specific |
| 205 |
directory, the simpler I<pmdesc> might be preferred: |
| 206 |
|
| 207 |
$ pmdesc `pminst -s | perl -lane 'print $F[1] if $F[0] =~ /site/'` |
| 208 |
XML::Parser::Expat (2.19) - Lowlevel access to James Clark's expat XML parser |
| 209 |
XML::Parser (2.19) - A perl module for parsing XML documents |
| 210 |
|
| 211 |
=head1 KNOWN BUGS |
| 212 |
|
| 213 |
This program takes a long time to run. |
| 214 |
|
| 215 |
Some modules don't work right (CPAN.pm, ExtUtils) because of noisy things |
| 216 |
they do at compile time or poor formatting of the pod. |
| 217 |
|
| 218 |
=head1 SEE ALSO |
| 219 |
|
| 220 |
pmdesc(1) |
| 221 |
pmvers(1) |
| 222 |
|
| 223 |
=head1 AUTHORS and COPYRIGHTS |
| 224 |
|
| 225 |
Copyright (C) 1999 Tom Christiansen. |
| 226 |
|
| 227 |
Copyright (C) 2006-2014 Mark Leighton Fisher. |
| 228 |
|
| 229 |
=head1 LICENSE |
| 230 |
|
| 231 |
This is free software; you can redistribute it and/or modify it |
| 232 |
under the terms of either: |
| 233 |
(a) the GNU General Public License as published by the Free |
| 234 |
Software Foundation; either version 1, or (at your option) any |
| 235 |
later version, or |
| 236 |
(b) the Perl "Artistic License". |
| 237 |
(This is the Perl 5 licensing scheme.) |
| 238 |
|
| 239 |
Please note this is a change from the |
| 240 |
original pmtools-1.00 (still available on CPAN), |
| 241 |
as pmtools-1.00 were licensed only under the |
| 242 |
Perl "Artistic License". |