| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||
| 2 | # pminst -- find modules whose names match this pattern | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # ------ pragmas | ||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 6 | our $VERSION = '2.2.0'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # ------ define variables | ||||||||||||||||||||||||||||
| 11 | 6 | my $pattern = undef; # module name pattern | |||||||||||||||||||||||||||
| 12 | 6 | our $startdir = undef; # starting directory | |||||||||||||||||||||||||||
| 13 | 6 | my $tmpname = undef; # temp version of full module name | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 6 | ▶ | BEGIN { $^W = 1 } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use Getopt::Std qw(getopts); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 6 | ▶ | use File::Find; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 6 | ▶ | getopts('ls') || die "bad usage"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 6 | ▶ | if (@ARGV == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 6 | @ARGV = ('.'); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 6 | ▶ | die "usage: $0 [-l] [-s] pattern\n" unless @ARGV == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 6 | $pattern = shift(); | |||||||||||||||||||||||||||
| 29 | 6 | $pattern =~ s,::,/,g; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 6 | ▶ | no lib '.'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 6 | ▶ | use vars qw($opt_l $opt_s %seen); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 6 | for $startdir (@INC) { | |||||||||||||||||||||||||||
| 36 | 42 | ▶ | next if (!-d $startdir); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 42 | find({ wanted => \&wanted, follow => 1 }, $startdir); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 14814 | ▶ | sub wanted { | ||||||||||||||||||||||||||
|
Subroutine
wanted: called CC=9 SCAR=23.6
| |||||||||||||||||||||||||||||
| 42 | 14814 | ▶ | if (-d && /^[a-z]/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-d $_ and /^[a-z]/
MC/DC100%2/2
-d $_ and /^[a-z]/
-d $_
/^[a-z]/
Truth table100%3/3
A and B
A= -d $_B= /^[a-z]/
| |||||||||||||||||||||||||||||
| 43 | # this is so we don't go down site_perl etc too early | ||||||||||||||||||||||||||||
| 44 | 150 | $File::Find::prune = 1; | |||||||||||||||||||||||||||
| 45 | 150 | 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 | 14664 | ▶ | return unless ( /\.pm$/ and not exists $seen{$File::Find::name} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/\.pm$/ and not exists $main::seen{$File::Find::name}
MC/DC100%2/2
/\.pm$/ and not exists $main::seen{$File::Find::name}
/\.pm$/
not exists $main::seen{$File::Find::name}
Truth table100%3/3
A and not(B)
A= /\.pm$/B= not exists $main::seen{$File::Find::name}
| |||||||||||||||||||||||||||||
| 57 | 10086 | local $_ = $File::Find::name; | |||||||||||||||||||||||||||
| 58 | 10086 | ($tmpname = $_) =~ s{^\Q$startdir/}{}; | |||||||||||||||||||||||||||
| 59 | 10086 | ▶ | return unless $tmpname =~ /$pattern/o; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 10086 | ▶ | if ($opt_l) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 10086 | ▶ | s{^(\Q$startdir\E)/}{$1 } if $opt_s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | else { | ||||||||||||||||||||||||||||
| 65 | 0 | s{^\Q$startdir/}{}; | |||||||||||||||||||||||||||
| 66 | 0 | s/\.pm$//; | |||||||||||||||||||||||||||
| 67 | 0 | s{/}{::}g; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | print "$startdir " if $opt_s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 10086 | $seen{$File::Find::name}=1; | |||||||||||||||||||||||||||
| 72 | 10086 | print $_, "\n"; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||||||||||