| 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() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 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 ||= "."
MC/DC0%0/1
$dir ||= "."
$dir
Truth table50%1/2
A
A= $dir
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | # get the module per normal | ||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $mod = $cb->parse_module( module => $dir ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | # get the list of prereqs | ||||||||||||||||||||||||||||||||
| 81 | 6 | ▶ | my $href = $mod->status->prereqs or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | # print repreq header | ||||||||||||||||||||||||||||||||
| 84 | 6 | ▶ | printf "\n %-30s %10s %10s %10s %10s\n", | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | # find the module or display msg no such module | ||||||||||||||||||||||||||||||||
| 92 | 26 | ▶ | my $obj = $cb->module_tree($name) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
(my $obj = $cb->module_tree($name)) || print("Prerequisite '${name}' was not found on CPAN\n") && (next)
print "Prerequisite '${name}' was not found on CPAN\n" and next
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"
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | # we already have this version or better installed | ||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | next if $obj->is_uptodate( version => $version ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||