script/whichpm

filter: Statementstmt 95.0% 38 / 40 Branchbran 76.9% 20 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 88.8% 64 / 72 CC 14 SCAR 24.1
CC
14
Cov
88%
main
14.8
BEGIN
1.0
BEGIN
1.0
CRAP 11.2
↑ Summary blib/lib/App/whichpm.pm »
1 #!/usr/bin/perl
2  
3 =head1 NAME
4  
5 whichpm - locate a Perl module and it's version
6  
7 =head1 SYNOPSIS
8  
9 # shows path and version (if vailable) of the Perl module
10 whichpm Some::Module::Name
11 whichpm -v Some::Module::Name
12 whichpm --verbose Some::Module::Name
13  
14 # shows just path to the Perl module
15 whichpm -q Some::Module::Name
16 whichpm --quiet Some::Module::Name
17  
18 # add lib/ into @INC
19 whichpmv -l Some::Module::Name
20 # add mylib into @INC
21 whichpmv -Imylib Some::Module::Name
22  
23 # show version of App::whichpm
24 whichpm --version
25  
26 # show/edit .pm file
27 less `whichpm Some::Module::Name`
28 vim `whichpm Some::Module::Name`
29  
30 =head1 DESCRIPTION
31  
32 Loads the module, prints its file system location and version.
33  
34 When STDOUT is not a TTY, prints just file name by default. (-v can force
35 printing version too)
36  
37 =cut
38  
39  
40 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 4 ▶use App::whichpm qw(which_pm);
Subroutine BEGIN: called CC=1 SCAR=0.0
44 4 ▶use Getopt::Long qw(:config no_ignore_case);
Subroutine BEGIN: called CC=1 SCAR=0.0
45 4 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 4 exit main();
48  
49 4 ▶sub main {
Subroutine main: called CC=14 SCAR=26.9
50 4 my $help;
51 4 ▶ my $quiet = (-t STDOUT ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
-t STDOUT ? : 0 4 4
52 4 my ($version, $verbose, @into_inc, $add_lib);
53  
54 # allow -Ilib style of include dir options
55 4 ▶ @ARGV = map { $_ =~ m/^-I(.+)$/ ? ('-I', $1) : $_ } @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /^-I(.+)$/ ? : 0 4 4
56  
57 4 ▶ GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("help|h", \$help, "quiet|q", \$quiet, "version|V", \$version, "verbose|v", \$verbose, "I=s", \@into_inc, "lib|l", \$add_lib) or pod2usage() 4 0 4
58 'help|h' => \$help,
59 'quiet|q' => \$quiet,
60 'version|V' => \$version,
61 'verbose|v' => \$verbose,
62 'I=s' => \@into_inc,
63 'lib|l' => \$add_lib,
64 ) or pod2usage;
65 4 ▶ pod2usage if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 0 4 4
66  
67 4 unshift(@INC, @into_inc);
68 4 ▶ unshift(@INC, 'lib')
Branch: 1 branch
BranchTrueFalseTotal
if $add_lib 0 4 4
69 if $add_lib;
70  
71 4 ▶ $quiet = 0 if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 1 3 4
72  
73 # show version
74 4 ▶ if ($version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version) 0 4 4
75 0 print App::whichpm->VERSION, "\n";
76 0 return 0;
77 }
78  
79 4 ▶ unless (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ARGV) 1 3 4
80 1 print STDERR "usage: $0 Some::Module::Name\n";
81 1 return 1;
82 }
83  
84 # lookup for all modules passed on command line
85 3 my $all_ok = 1;
86 3 ▶ while (my $mn = shift @ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mn = shift @ARGV) 3 3 6
87 3 my ($filename, $version) = which_pm($mn);
88  
89 # don't show version in quiet mode
90 3 ▶ $version = undef
Branch: 1 branch
BranchTrueFalseTotal
if $quiet 2 1 3
91 if $quiet;
92  
93 3 ▶ if ($filename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename) { } 2 1 3
94 2 ▶ print $filename, (defined $version ? ' '.$version : ()), "\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $version ? : 1 1 2
95 }
96 else {
97 1 $all_ok = 0;
98 }
99 }
100  
101 3 ▶ return ($all_ok ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$all_ok ? : 2 1 3
102 }
↑ Summary blib/lib/App/whichpm.pm »