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