MegaDistro/InstallDeps.pm untested

filter: Statementstmt 0.0% 0 / 109 Branchbran 0.0% 0 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 171 CC 19 SCAR 25.9
CC
19
Cov
0%
init
30.0
get_modules
20.0
get_modobj
20.0
CRAP 13.4
1 package MegaDistro::InstallDeps;
2  
3 use strict;
4 use warnings;
5  
6 use base qw(Exporter);
7 our @EXPORT_OK = qw(get_modules mod_install);
8  
9 use lib './MegaDistro';
10  
11 use MegaDistro::Config;
12 use MegaDistro::ParseList qw(get_modlist);
13 use CPANPLUS::Backend;
14 use Module::CoreList;
15 use Data::Dumper;
16  
17 #use lib "$BUILDDIR";
18  
19  
20 our ( $cb, $conf );
21 my $init = 0;
22  
23 #called internally to explicitly init the CPANPLUS stuff
24 sub init {
25 if ( $args{'trace'} ) {
26 print 'MegaDistro::Install : Executing sub-routine: init' . "\n";
27 }
28  
29 if ( $args{'debug'} ) {
30 print "\t" . 'Instantiating CPANPLUS::Backend object' . "\n";
31 }
32  
33 # This can interfere with the operation of CPANPLUS.
34 delete $ENV{MAKEFLAGS};
35
36 #instantiate backend obj
37 $cb = CPANPLUS::Backend->new;
38  
39 if ( $args{'debug'} ) {
40 print "\t" . 'Instantiating CPANPLUS::Configure object' . "\n";
41 }
42 #instantiate configure obj
43 $conf = $cb->configure_object;
44 $conf->set_conf(
45 fetchdir => $FETCHDIR,
46 extractdir => $EXTRACTDIR,
47 verbose => $args{'verbose'},
48 skiptest => 0,
49 force => 0,
50 no_update => 1,
51 flush => 1,
52 prereqs => 3,
53 allow_build_interactivity => 0,
54 );
55 if ( $args{'quiet'} ) {
56 $conf->set_conf( makeflags => '--quiet' );
57 }
58 #FIXME: Change makemakerflags! (e.g. INST_LIB=VENDOR)
59 # $conf->set_conf( makemakerflags => "PREFIX=$BUILDDIR" );
60 $conf->set_conf( makemakerflags => "DESTDIR=$BUILDDIR/ INSTALLDIRS=vendor" );
61  
62 $init = 1;
63 }
64  
65  
66 sub get_modules {
67 if ( $args{'trace'} ) {
68 print 'MegaDistro::Install : Executing sub-routine: get_modules' . "\n";
69 }
70  
71 &init if !$init; # explicitly init the CPANPLUS::Backend obj here
72 my @modlist = &get_modlist;
73 my @modobjs;
74  
75 if ( $args{'debug'} ) {
76 print "\t" . 'Instantiating/Initializing CPANPLUS::Modules' . "\n";
77 }
78 @modobjs = $cb->module_tree(@modlist);
79  
80 return @modobjs;
81 }
82  
83 ##perform: fetch && extract && make && make test && make install
84 #sub make_install {
85 # if ( $args{'trace'} ) {
86 # print 'MegaDistro::Install : Executing sub-routine: make_install' . "\n";
87 # }
88 #
89 # my ( $mod ) = @_;
90 #
91 ## if ( $args{'debug'} ) {
92 # print "\t" . 'Processing module: ' . $mod->name . "\t";
93 ## }
94 #
95 # my $bool;
96 # if ( !$args{'verbose'} ) {
97 # local *STDOUT;
98 # local *STDERR;
99 # open 'STDOUT', '>/dev/null';
100 # open 'STDERR', '>/dev/null';
101 #
102 # $bool = $mod->install(
103 # target => 'install',
104 # skiptest => 0,
105 # );
106 # close 'STDOUT';
107 # close 'STDERR';
108 # }
109 # else {
110 # $bool = $mod->install(
111 # target => 'install',
112 # skiptest => 0,
113 # );
114 # }
115 # print '[ ' . ($bool ? "Success!" : "Failure!") . ' ]' . "\n";
116 # return $bool;
117 #}
118  
119  
120  
121 # Start of new implementation #
122  
123 our %modules;
124 our %Modules_Seen = ();
125 our %Modules_Installed = ();
126  
127  
128 sub get_modobj {
129 if ( $args{'trace'} ) {
130 print 'MegaDistro::Install : Executing sub-routine: get_modobj' . "\n";
131 }
132
133 &init if !$init;
134 my $modname = shift;
135 if ( $args{'debug'} ) {
136 print "\t" . 'Instantiating/Initializing CPANPLUS::Module : ' . $modname. "\n";
137 }
138 my $modobj = $cb->module_tree($modname);
139 $modules{$modname} = $modobj;
140  
141 return $modobj;
142 }
143  
144 sub get_moddeps {
145 if ( $args{'trace'} ) {
146 print 'MegaDistro::Install : Executing sub-routine: get_moddeps' . "\n";
147 }
148  
149 my $mod = shift;
150
151 $mod->prepare;
152 my %prereqs = %{$mod->status->prereqs}; #TODO: add mod throwback safety -here-
153 # foreach my $req (keys %prereqs) {
154 # print $req . '=>' . $prereqs{$req} . "\n";
155 # }
156  
157 my @moddeps;
158 foreach my $dep (keys %prereqs) {
159 push @moddeps, $dep if !&is_modcore($dep);
160 }
161
162 return @moddeps;
163 }
164  
165 #TODO: perhaps, use an implementation which implies core updates?
166 sub is_modcore {
167 if ( $args{'trace'} ) {
168 print 'MegaDistro::Install : Executing sub-routine: is_modcore' . "\n";
169 }
170
171 my $module = shift;
172 # my $mod = shift;
173 my $mod = &get_modobj($module);
174 # my $perlversion = sprintf("%vd", $^V);
175  
176 # print "Module: " . $mod->name . " is core: ";
177 # print Dumper $Module::CoreList::version{$]}{"Test::Harness"};
178  
179 return exists $Module::CoreList::version{$]}{$mod->name};
180 # return Module::CoreList->first_release($mod->name);
181 # return exists $Module::CoreList::version{$]}{$module};
182 # return exists $Module::CoreList::version{$perlversion}{$mod->name};
183 # return $mod->module_is_supplied_with_perl_core || $mod->package_is_perl_core;
184 }
185  
186 sub mod_install {
187 if ( $args{'trace'} ) {
188 print 'MegaDistro::Install : Executing sub-routine: mod_install' . "\n";
189 }
190
191 # my $module = shift;
192 # my $mod = &get_modobj($module);
193 my $mod = shift;
194 # return 1 if !$mod;
195
196 print "\t" . 'Processing module: ' . $mod->name . "\t";
197
198 my @moddeps = &get_moddeps($mod);
199 $cb->flush('lib');
200 use lib "$BUILDDIR";
201 foreach my $dep (@moddeps) {
202 print "\t\tResolving Dependency: $dep\n"; #if $args{'debug'};
203 next if $Modules_Seen{$dep}++;
204 # next if $Modules_Seen{$modules{$dep}->name}++;
205 mod_install($modules{$dep});
206 }
207  
208 if ( &mod_test($mod) ) {
209 &force_install($mod);
210 $Modules_Installed{$mod->name}++;
211 # $Modules_Installed{$modules{$dep}->name}++;
212 return 1;
213 }
214 else {
215 warn $mod->name . " failed its tests.\n"; #should be debug-info [only] - handle externally ?
216 return 0;
217 }
218 }
219  
220 sub mod_test {
221 if ( $args{'trace'} ) {
222 print 'MegaDistro::Install : Executing sub-routine: test' . "\n";
223 }
224  
225 my $mod = shift;
226 my $bool = $mod->test;
227 return $bool;
228 }
229  
230 sub force_install {
231 if ( $args{'trace'} ) {
232 print 'MegaDistro::Install : Executing sub-routine: force_install' . "\n";
233 }
234
235 my $mod = shift;
236 my $bool = $mod->install(
237 target => 'install',
238 skiptest => 1,
239 force => 0,
240 );
241 return $bool;
242 }
243  
244 1;