blib/lib/CPANPLUS/Shell/Default/Plugins/Prereqs.pm

filter: Statementstmt 92.3% 48 / 52 Branchbran 62.5% 15 / 24 Conditioncond 55.5% 5 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 79.2% 80 / 101 CC 16 SCAR 26.6
CC
16
Cov
80%
install_prereqs
21.0
BEGIN
1.0
BEGIN
1.0
CRAP 14.4
↑ Summary Build »
1 package CPANPLUS::Shell::Default::Plugins::Prereqs;
2  
3 # ABSTRACT: Plugin for CPANPLUS to automate the installation of prerequisites without installing the module
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Basename qw[basename];
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use CPANPLUS::Internals::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 our $VERSION = '0.12';
14  
15 sub plugins {
16 2 ▶ return ( prereqs => 'install_prereqs', );
Subroutine plugins: called CC=1 SCAR=0.0
Pod documented
17 }
18  
19 sub install_prereqs {
20 6 ▶ my $class = shift; # CPANPLUS::Shell::Default::Plugins::Prereqs
Subroutine install_prereqs: called CC=16 SCAR=30.5
Pod documented
21 6 my $shell = shift; # CPANPLUS::Shell::Default object
22 6 my $cb = shift; # CPANPLUS::Backend object
23 6 my $cmd = shift; # 'prereqs'
24 6 my $input = shift; # show|list|install [dirname]
25 6 ▶ my $opts = shift || {}; # { foo => 0, bar => 2 }
Condition50%1/2
shift() || {}
l!l
60
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
26  
27 # get the operation and possble target dir.
28 6 my ( $op, $dir ) = split /\s+/, $input, 2; ## no critic
29  
30 # default to the current dir
31 6 ▶ $dir ||= '.';
Condition50%1/2
$dir ||= "."
l!l
60
MC/DC0%0/1
$dir ||= "."
$dir
Truth table50%1/2
A
A= $dir
Aresult
11
00
32  
33 # you want us to install, or just list?
34 my $install = {
35 list => 0,
36 show => 0,
37 install => 1,
38 6 }->{ lc $op };
39  
40 # you passed an unknown operation
41 6 ▶ unless ( defined $install ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $install) 0 6 6
42 0 print __PACKAGE__->install_prereqs_help;
43 0 return;
44 }
45  
46 6 my $mod;
47  
48 # was a directory specified
49 6 ▶ if ( -d $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dir) { } 4 2 6
50  
51 # get the absolute path to the directory
52 4 $dir = File::Spec->rel2abs($dir);
53  
54 4 $mod = CPANPLUS::Module::Fake->new(
55 module => basename($dir),
56 path => $dir,
57 author => CPANPLUS::Module::Author::Fake->new,
58 package => basename($dir),
59 );
60  
61 # set the fetch & extract targets, so we know where to look
62 4 $mod->status->fetch($dir);
63 4 $mod->status->extract($dir);
64  
65 # figure out whether this module uses EU::MM or Module::Build
66 # do this manually, as we're setting the extract location
67 # ourselves.
68 4 ▶ $mod->get_installer_type or return;
Branch: 1 branch
BranchTrueFalseTotal
$mod->get_installer_type or return 0 4 4
69  
70 } else {
71  
72 # get the module per normal
73 2 ▶ $mod = $cb->parse_module( module => $dir )
Branch: 1 branch
BranchTrueFalseTotal
$mod = $cb->parse_module("module", $dir) or return 0 2 2
74 or return;
75  
76 }
77  
78 # run 'perl Makefile.PL' or 'M::B->new_from_context' to find the
79 # prereqs.
80 6 ▶ $mod->prepare(%$opts) or return;
Branch: 1 branch
BranchTrueFalseTotal
$mod->prepare(%$opts) or return 2 4 6
81  
82 # get the list of prereqs
83 4 ▶ my $href = $mod->status->prereqs or return;
Branch: 1 branch
BranchTrueFalseTotal
my $href = $mod->status->prereqs or return 0 4 4
84  
85 # print repreq header
86 4 ▶ printf "\n %-30s %10s %10s %10s %10s\n",
Branch: 1 branch
BranchTrueFalseTotal
if keys %$href 4 0 4
87 'Module', 'Req Ver', 'Installed', 'CPAN', 'Satisfied'
88 if keys %$href;
89  
90 # list and/or install the prereqs
91 4 ▶ while ( my ( $name, $version ) = each %$href ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$href) 20 4 24
92  
93 # find the module or display msg no such module
94 20 ▶ my $obj = $cb->module_tree($name)
Branch: 1 branch
BranchTrueFalseTotal
my $obj = $cb->module_tree($name) or print "Prerequisite '${name}' was not found on CPAN\n" and next 4 16 20
Condition60%3/5
(my $obj = $cb->module_tree($name)) || print("Prerequisite '${name}' was not found on CPAN\n") && (next)
l!l&&r!l&&!r
1640
print "Prerequisite '${name}' was not found on CPAN\n" and next
!ll
04
MC/DC0%0/2
(my $obj = $cb->module_tree($name)) || print("Prerequisite '${name}' was not found on CPAN\n") && (next)
(my $obj = $cb->module_tree($name)) print "Prerequisite '${name}' was not found on CPAN\n"
Truth table66%2/3
A || B
A= (my $obj = $cb->module_tree($name))B= print "Prerequisite '${name}' was not found on CPAN\n"
ABresult
1X1
011
000
95 or print "Prerequisite '$name' was not found on CPAN\n" and next;
96  
97 # display some info
98 16 ▶ printf " %-30s %10s %10s %10s %10s\n",
Branch: 1 branch
BranchTrueFalseTotal
$obj->is_uptodate('version', $version) ? : 16 0 16
99 $name, $version, $obj->installed_version, $obj->version,
100 ( $obj->is_uptodate( version => $version ) ? 'Yes' : 'No' );
101  
102 # that is it, unless we need to install
103 16 ▶ next unless $install;
Branch: 1 branch
BranchTrueFalseTotal
unless $install 16 0 16
104  
105 # we already have this version or better installed
106 0 ▶ next if $obj->is_uptodate( version => $version );
Branch: 1 branch
BranchTrueFalseTotal
if $obj->is_uptodate("version", $version) 0 0 0
107  
108 # install it
109 0 $obj->install(%$opts);
110 }
111  
112 4 return;
113 }
114  
115 sub install_prereqs_help {
116 return
117 1 ▶ " /prereqs <cmd> [mod] # Install missing prereqs for given module\n"
Subroutine install_prereqs_help: called CC=1 SCAR=0.0
Pod documented
118 . " <cmd> => show|list|install\n"
119 . " [mod] directory, module name or URL (defaults to .)\n";
120  
121 }
122  
123 2 1;
124  
125 __END__
↑ Summary Build »