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

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