line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPANPLUS::Shell::Default::Plugins::Prereqs; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
148880
|
use strict; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
85
|
|
4
|
2
|
|
|
2
|
|
16
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
97
|
|
5
|
2
|
|
|
2
|
|
27
|
use File::Basename qw[basename]; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
157
|
|
6
|
2
|
|
|
2
|
|
1139
|
use CPANPLUS::Internals::Constants; |
|
2
|
|
|
|
|
59421
|
|
|
2
|
|
|
|
|
1107
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
17
|
use Carp; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
151
|
|
9
|
2
|
|
|
2
|
|
4303
|
use Data::Dumper; |
|
2
|
|
|
|
|
8486
|
|
|
2
|
|
|
|
|
2089
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub plugins { |
14
|
2
|
|
|
2
|
1
|
521
|
return ( prereqs => 'install_prereqs', ); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub install_prereqs { |
18
|
6
|
|
|
6
|
1
|
30165
|
my $class = shift; # CPANPLUS::Shell::Default::Plugins::Prereqs |
19
|
6
|
|
|
|
|
32
|
my $shell = shift; # CPANPLUS::Shell::Default object |
20
|
6
|
|
|
|
|
11
|
my $cb = shift; # CPANPLUS::Backend object |
21
|
6
|
|
|
|
|
12
|
my $cmd = shift; # 'prereqs' |
22
|
6
|
|
|
|
|
10
|
my $input = shift; # show|list|install [dirname] |
23
|
6
|
|
50
|
|
|
23
|
my $opts = shift || {}; # { foo => 0, bar => 2 } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# get the operation and possble target dir. |
26
|
6
|
|
|
|
|
24
|
my ( $op, $dir ) = split /\s+/, $input, 2; ## no critic |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# default to the current dir |
29
|
6
|
|
50
|
|
|
22
|
$dir ||= '.'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# you want us to install, or just list? |
32
|
6
|
|
|
|
|
68
|
my $install = { |
33
|
|
|
|
|
|
|
list => 0, |
34
|
|
|
|
|
|
|
show => 0, |
35
|
|
|
|
|
|
|
install => 1, |
36
|
|
|
|
|
|
|
}->{ lc $op }; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# you passed an unknown operation |
39
|
6
|
50
|
|
|
|
38
|
unless ( defined $install ) { |
40
|
0
|
|
|
|
|
0
|
print __PACKAGE__->install_prereqs_help; |
41
|
0
|
|
|
|
|
0
|
return; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
6
|
|
|
|
|
10
|
my $mod; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# was a directory specified |
47
|
6
|
50
|
|
|
|
120
|
if ( -d $dir ) { |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# get the absolute path to the directory |
50
|
6
|
|
|
|
|
259
|
$dir = File::Spec->rel2abs($dir); |
51
|
|
|
|
|
|
|
|
52
|
6
|
|
|
|
|
819
|
$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
|
|
|
|
|
4223
|
$mod->status->fetch($dir); |
61
|
6
|
|
|
|
|
7777
|
$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
|
50
|
|
|
|
479
|
$mod->get_installer_type or return; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} else { |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# get the module per normal |
71
|
0
|
0
|
|
|
|
0
|
$mod = $cb->parse_module( module => $dir ) |
72
|
|
|
|
|
|
|
or return; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# run 'perl Makefile.PL' or 'M::B->new_from_context' to find the |
77
|
|
|
|
|
|
|
# prereqs. |
78
|
6
|
50
|
|
|
|
1908413
|
$mod->prepare(%$opts) or return; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# get the list of prereqs |
81
|
6
|
50
|
|
|
|
2454901
|
my $href = $mod->status->prereqs or return; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# print repreq header |
84
|
6
|
50
|
|
|
|
1021
|
printf "\n %-30s %10s %10s %10s %10s\n", |
85
|
|
|
|
|
|
|
'Module', 'Req Ver', 'Installed', 'CPAN', 'Satisfied' |
86
|
|
|
|
|
|
|
if keys %$href; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# list and/or install the prereqs |
89
|
6
|
|
|
|
|
113
|
while ( my ( $name, $version ) = each %$href ) { |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# find the module or display msg no such module |
92
|
26
|
100
|
50
|
|
|
402
|
my $obj = $cb->module_tree($name) |
93
|
|
|
|
|
|
|
or print "Prerequisite '$name' was not found on CPAN\n" and next; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# display some info |
96
|
20
|
50
|
|
|
|
1212
|
printf " %-30s %10s %10s %10s %10s\n", |
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
|
50
|
|
|
|
559459
|
next unless $install; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# we already have this version or better installed |
104
|
0
|
0
|
|
|
|
0
|
next if $obj->is_uptodate( version => $version ); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# install it |
107
|
0
|
|
|
|
|
0
|
$obj->install(%$opts); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
6
|
|
|
|
|
395
|
return; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub install_prereqs_help { |
114
|
|
|
|
|
|
|
return |
115
|
1
|
|
|
1
|
1
|
642
|
" /prereqs [mod] # Install missing prereqs for given module\n" |
116
|
|
|
|
|
|
|
. " => show|list|install\n" |
117
|
|
|
|
|
|
|
. " [mod] directory, module name or URL (defaults to .)\n"; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |