| 1 |
#!/usr/bin/env perl |
| 2 |
# pminst -- find modules whose names match this pattern |
| 3 |
|
| 4 |
# ------ pragmas |
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
|
| 8 |
our $VERSION = '2.2.0'; |
| 9 |
|
| 10 |
# ------ define variables |
| 11 |
my $pattern = undef; # module name pattern |
| 12 |
our $startdir = undef; # starting directory |
| 13 |
my $tmpname = undef; # temp version of full module name |
| 14 |
|
| 15 |
BEGIN { $^W = 1 } |
| 16 |
|
| 17 |
use Getopt::Std qw(getopts); |
| 18 |
use File::Find; |
| 19 |
|
| 20 |
getopts('ls') || die "bad usage"; |
| 21 |
|
| 22 |
if (@ARGV == 0) { |
| 23 |
@ARGV = ('.'); |
| 24 |
} |
| 25 |
|
| 26 |
die "usage: $0 [-l] [-s] pattern\n" unless @ARGV == 1; |
| 27 |
|
| 28 |
$pattern = shift(); |
| 29 |
$pattern =~ s,::,/,g; |
| 30 |
|
| 31 |
no lib '.'; |
| 32 |
|
| 33 |
use vars qw($opt_l $opt_s %seen); |
| 34 |
|
| 35 |
for $startdir (@INC) { |
| 36 |
next if (!-d $startdir); |
| 37 |
|
| 38 |
find({ wanted => \&wanted, follow => 1 }, $startdir); |
| 39 |
} |
| 40 |
|
| 41 |
sub wanted { |
| 42 |
if (-d && /^[a-z]/) { |
| 43 |
# this is so we don't go down site_perl etc too early |
| 44 |
$File::Find::prune = 1; |
| 45 |
return; |
| 46 |
} |
| 47 |
# Some expansions of @INC have subdirs of other @INC directories in them; |
| 48 |
# to wit: |
| 49 |
# /opt/perl/lib/site_perl/5.8.8 |
| 50 |
# /opt/perl/lib/site_perl |
| 51 |
# This will result in output, when looking for module Foo: |
| 52 |
# Foo |
| 53 |
# 5.8.8:Foo |
| 54 |
# We add full module paths for found modules to %seen so |
| 55 |
# we can skip them the next time around. |
| 56 |
return unless ( /\.pm$/ and not exists $seen{$File::Find::name} ); |
| 57 |
local $_ = $File::Find::name; |
| 58 |
($tmpname = $_) =~ s{^\Q$startdir/}{}; |
| 59 |
return unless $tmpname =~ /$pattern/o; |
| 60 |
|
| 61 |
if ($opt_l) { |
| 62 |
s{^(\Q$startdir\E)/}{$1 } if $opt_s; |
| 63 |
} |
| 64 |
else { |
| 65 |
s{^\Q$startdir/}{}; |
| 66 |
s/\.pm$//; |
| 67 |
s{/}{::}g; |
| 68 |
print "$startdir " if $opt_s; |
| 69 |
} |
| 70 |
|
| 71 |
$seen{$File::Find::name}=1; |
| 72 |
print $_, "\n"; |
| 73 |
} |
| 74 |
|
| 75 |
__END__ |
| 76 |
|
| 77 |
=head1 NAME |
| 78 |
|
| 79 |
pminst - find modules whose names match this pattern |
| 80 |
|
| 81 |
=head1 SYNOPSIS |
| 82 |
|
| 83 |
pminst [B<-s>] [B<-l>] [I<pattern>] |
| 84 |
|
| 85 |
=head1 DESCRIPTION |
| 86 |
|
| 87 |
Without arguments, show the names of all installed modules. Given a |
| 88 |
pattern, show all module names that match it. The B<-l> flag will show |
| 89 |
the full pathname. The B<-s> flag will separate the base directory from |
| 90 |
@INC from the module portion itself. |
| 91 |
|
| 92 |
|
| 93 |
=head1 EXAMPLES |
| 94 |
|
| 95 |
$ pminst |
| 96 |
(lists all installed modules) |
| 97 |
|
| 98 |
$ pminst Carp |
| 99 |
CGI::Carp |
| 100 |
Carp |
| 101 |
|
| 102 |
$ pminst ^IO:: |
| 103 |
IO::Socket::INET |
| 104 |
IO::Socket::UNIX |
| 105 |
IO::Select |
| 106 |
IO::Socket |
| 107 |
IO::Poll |
| 108 |
IO::Handle |
| 109 |
IO::Pipe |
| 110 |
IO::Seekable |
| 111 |
IO::Dir |
| 112 |
IO::File |
| 113 |
|
| 114 |
$ pminst '(?i)io' |
| 115 |
IO::Socket::INET |
| 116 |
IO::Socket::UNIX |
| 117 |
IO::Select |
| 118 |
IO::Socket |
| 119 |
IO::Poll |
| 120 |
IO::Handle |
| 121 |
IO::Pipe |
| 122 |
IO::Seekable |
| 123 |
IO::Dir |
| 124 |
IO::File |
| 125 |
IO |
| 126 |
Pod::Functions |
| 127 |
|
| 128 |
The -s flag provides output with the directory separated |
| 129 |
by a space: |
| 130 |
|
| 131 |
$ pminst -s | sort +1 |
| 132 |
(lists all modules, sorted by name, but with where they |
| 133 |
came from) |
| 134 |
|
| 135 |
$ oldperl -S pminst -s IO |
| 136 |
/usr/lib/perl5/i386-linux/5.00404 IO::File |
| 137 |
/usr/lib/perl5/i386-linux/5.00404 IO::Handle |
| 138 |
/usr/lib/perl5/i386-linux/5.00404 IO::Pipe |
| 139 |
/usr/lib/perl5/i386-linux/5.00404 IO::Seekable |
| 140 |
/usr/lib/perl5/i386-linux/5.00404 IO::Select |
| 141 |
/usr/lib/perl5/i386-linux/5.00404 IO::Socket |
| 142 |
/usr/lib/perl5/i386-linux/5.00404 IO |
| 143 |
/usr/lib/perl5/site_perl LWP::IO |
| 144 |
/usr/lib/perl5/site_perl LWP::TkIO |
| 145 |
/usr/lib/perl5/site_perl Tk::HTML::IO |
| 146 |
/usr/lib/perl5/site_perl Tk::IO |
| 147 |
/usr/lib/perl5/site_perl IO::Stringy |
| 148 |
/usr/lib/perl5/site_perl IO::Wrap |
| 149 |
/usr/lib/perl5/site_perl IO::ScalarArray |
| 150 |
/usr/lib/perl5/site_perl IO::Scalar |
| 151 |
/usr/lib/perl5/site_perl IO::Lines |
| 152 |
/usr/lib/perl5/site_perl IO::WrapTie |
| 153 |
/usr/lib/perl5/site_perl IO::AtomicFile |
| 154 |
|
| 155 |
The -l flag gives full paths: |
| 156 |
|
| 157 |
$ filsperl -S pminst -l Thread |
| 158 |
/usr/local/filsperl/lib/5.00554/i686-linux-thread/Thread/Queue.pm |
| 159 |
/usr/local/filsperl/lib/5.00554/i686-linux-thread/Thread/Semaphore.pm |
| 160 |
/usr/local/filsperl/lib/5.00554/i686-linux-thread/Thread/Signal.pm |
| 161 |
/usr/local/filsperl/lib/5.00554/i686-linux-thread/Thread/Specific.pm |
| 162 |
/usr/local/filsperl/lib/5.00554/i686-linux-thread/Thread.pm |
| 163 |
|
| 164 |
=head1 AUTHORS and COPYRIGHTS |
| 165 |
|
| 166 |
Copyright (C) 1999 Tom Christiansen. |
| 167 |
|
| 168 |
Copyright (C) 2006-2014, 2018 Mark Leighton Fisher. |
| 169 |
|
| 170 |
=head1 LICENSE |
| 171 |
|
| 172 |
This is free software; you can redistribute it and/or modify it |
| 173 |
under the terms of either: |
| 174 |
(a) the GNU General Public License as published by the Free |
| 175 |
Software Foundation; either version 1, or (at your option) any |
| 176 |
later version, or |
| 177 |
(b) the Perl "Artistic License". |
| 178 |
(This is the Perl 5 licensing scheme.) |
| 179 |
|
| 180 |
Please note this is a change from the |
| 181 |
original pmtools-1.00 (still available on CPAN), |
| 182 |
as pmtools-1.00 were licensed only under the |
| 183 |
Perl "Artistic License". |