bin/pminst

filter: Statementstmt 91.4% 43 / 47 Branchbran 55.0% 11 / 20 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 84.7% 72 / 85 CC 9 SCAR 18.6
CC
9
Cov
82%
wanted
10.6
BEGIN
1.0
BEGIN
1.0
CRAP 6.4
« blib/lib/Devel/Loaded.pm ↑ Summary bin/pmeth »
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
BranchTrueFalseTotal
&getopts("ls") or die "bad usage" 6 0 6
21  
22 6 ▶if (@ARGV == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV == 0) 6 0 6
23 6 @ARGV = ('.');
24 }
25  
26 6 ▶die "usage: $0 [-l] [-s] pattern\n" unless @ARGV == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV == 1 0 6 6
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
BranchTrueFalseTotal
unless -d $main::startdir 0 42 42
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
BranchTrueFalseTotal
if (-d $_ and /^[a-z]/) 150 14664 14814
Condition100%3/3
-d $_ and /^[a-z]/
!ll&&!rl&&r
120662598150
MC/DC100%2/2
-d $_ and /^[a-z]/
-d $_ /^[a-z]/
Truth table100%3/3
A and B
A= -d $_B= /^[a-z]/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless /\.pm$/ and not exists $main::seen{$File::Find::name} 4578 10086 14664
Condition100%3/3
/\.pm$/ and not exists $main::seen{$File::Find::name}
!ll&&!rl&&r
45661210086
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}
ABresult
0X0
100
111
57 10086 local $_ = $File::Find::name;
58 10086 ($tmpname = $_) =~ s{^\Q$startdir/}{};
59 10086 ▶ return unless $tmpname =~ /$pattern/o;
Branch: 1 branch
BranchTrueFalseTotal
unless $tmpname =~ /$pattern/o 0 10086 10086
60  
61 10086 ▶ if ($opt_l) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::opt_l) { } 10086 0 10086
62 10086 ▶ s{^(\Q$startdir\E)/}{$1 } if $opt_s;
Branch: 1 branch
BranchTrueFalseTotal
if $main::opt_s 0 10086 10086
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
BranchTrueFalseTotal
if $main::opt_s 0 0 0
69 }
70  
71 10086 $seen{$File::Find::name}=1;
72 10086 print $_, "\n";
73 }
74  
75 __END__
« blib/lib/Devel/Loaded.pm ↑ Summary bin/pmeth »