MegaDistro/Install.pm untested

filter: Statementstmt 0.0% 0 / 113 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 168 CC 16 SCAR 30.6
CC
16
Cov
0%
make_install
56.0
init
20.0
get_modules
20.0
CRAP 21.3
1 package MegaDistro::Install;
2  
3 use strict;
4 use warnings;
5  
6 use base qw(Exporter);
7 our @EXPORT_OK = qw(get_modules make_install);
8  
9 use lib './MegaDistro';
10  
11 use MegaDistro::Config qw(:default push_libs);
12 use MegaDistro::ParseList qw(get_modlist);
13 use CPANPLUS::Backend;
14 use Config;
15  
16 our ( $cb, $conf );
17 my $init = 0;
18  
19 #called internally to explicitly init the CPANPLUS stuff
20 sub init {
21 if ( $args{'trace'} ) {
22 print 'MegaDistro::Install : Executing sub-routine: init' . "\n";
23 }
24  
25 if ( $args{'debug'} ) {
26 print "\t" . 'Instantiating CPANPLUS::Backend object' . "\n";
27 }
28  
29 # This can interfere with the operation of CPANPLUS.
30 delete $ENV{MAKEFLAGS};
31
32 #instantiate backend obj
33 $cb = CPANPLUS::Backend->new;
34  
35 if ( $args{'debug'} ) {
36 print "\t" . 'Instantiating CPANPLUS::Configure object' . "\n";
37 }
38 #instantiate configure obj
39 $conf = $cb->configure_object;
40 $conf->set_program( sudo => '' );
41 $conf->set_conf(
42 fetchdir => $Conf{'fetchdir'},
43 extractdir => $Conf{'extractdir'},
44 # verbose => $args{'verbose'}, #bugged 0.055, 0.0562
45 # #conflicts with allow_build_interactivity
46 verbose => 0,
47 skiptest => 0,
48 force => 0,
49 no_update => 0,
50 prereqs => 3,
51 allow_build_interactivity => 0,
52 flush => 1,
53 # makeflags => '--quiet', # only gnu make supports this option, apparently.
54 makemakerflags => "PREFIX=$Conf{'prefixdir'} INSTALLDIRS=vendor",
55 lib => [
56 MegaDistro::Config::prop_libs()
57 ]
58 );
59  
60 print 'Rebuilding module indicies...' . "\n";
61 $cb->flush('all');
62  
63 $init = 1;
64 }
65  
66  
67 sub get_modules {
68 if ( $args{'trace'} ) {
69 print 'MegaDistro::Install : Executing sub-routine: get_modules' . "\n";
70 }
71  
72 &init if !$init; # explicitly init the CPANPLUS::Backend obj here
73 my @modlist = &get_modlist;
74 my @modobjs;
75  
76 if ( $args{'debug'} ) {
77 print "\t" . 'Instantiating/Initializing CPANPLUS::Modules' . "\n";
78 }
79 @modobjs = $cb->module_tree(@modlist);
80  
81 return @modobjs;
82 }
83  
84 #perform: fetch && extract && make && make test && make install
85 sub make_install {
86  
87 my $mod = shift;
88  
89 #catch exceptions here, for non-init cpan mods that fall-thru
90 if ( !$mod ) {
91 printf "\n%18s", ' ';
92 print '*Module was not found on cpan - skipping...';
93 return 0;
94 }
95  
96 printf "%-45s", $mod->name; #print module name for process list
97  
98 if ( &is_modcore($mod) ) { #check if the module is core
99 printf "\n%18s", ' ';
100 print '*Module is part of the perl core - skipping...';
101 return 1;
102 }
103  
104 &push_libs; # is this necessary, with the CPANPLUS::Configure 'libs' attr set?
105
106 my $bool = &make_test($mod); #test the module
107 my $fool;
108 if ( $args{'trace'} ) {
109 print 'MegaDistro::Install : Executing sub-routine: make_install' . "\n";
110 }
111  
112 if ( !$bool && $args{'force'} ) { # if tests failed, but --force is enabled
113 printf "\n%18s", ' ';
114 print '*Module failed one or more tests - forcing install...';
115 $fool = &force_install($mod);
116 $bool = $fool;
117 }
118 elsif ( !$bool ) { # if tests failed
119 print "\n";
120 printf "%18s", ' ';
121 print '*Module failed one or more tests - force install? (Y/N) ';
122 my $force;
123 do {
124 $force = <>;
125 printf "%56s", ' ';
126 } while ($force !~ /^[YN]/i);
127 if ( $force =~ /^[Y]/i ) {
128 $fool = &force_install($mod);
129 $bool = $fool;
130 }
131 else {
132 $bool = 0;
133 }
134 }
135 else { # if tests pass
136 $fool = &force_install($mod);
137 $bool = $fool;
138  
139 }
140
141 return $bool; #return installation status of module, being processed
142 }
143  
144 sub make_test {
145 if ( $args{'trace'} ) {
146 print 'MegaDistro::Install : Executing sub-routine: make_test' . "\n";
147 }
148
149 my $mod = shift;
150
151 my $bool;
152 if ( !$args{'verbose'} ) {
153 local *STDOUT;
154 local *STDERR;
155 open 'STDOUT', '>/dev/null';
156 open 'STDERR', '>/dev/null';
157 $bool = $mod->test;
158 close 'STDOUT';
159 close 'STDERR';
160 }
161 else {
162 $bool = $mod->test;
163 }
164 return $bool;
165 }
166  
167 sub force_install {
168  
169 my $mod = shift;
170  
171 my $bool;
172 if ( !$args{'verbose'} ) {
173 local *STDOUT;
174 local *STDERR;
175 open 'STDOUT', '>/dev/null';
176 open 'STDERR', '>/dev/null';
177
178 $bool = $mod->install(
179 target => 'install',
180 skiptest => 1,
181 force => 1,
182 );
183
184 close 'STDOUT';
185 close 'STDERR';
186 }
187 else {
188 $bool = $mod->install(
189 target => 'install',
190 skiptest => 1,
191 force => 1,
192 );
193
194 }
195  
196 return $bool;
197 }
198  
199 # method will settle compat (between 5.6 -> 5.8, at least)
200 sub is_modcore {
201 my $mod = shift;
202 return exists $Module::CoreList::version{$]}{$mod->name};
203 }
204  
205 1;