Install.pm untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 108 CC 9 SCAR 24.7
CC
9
Cov
0%
compile_manifest
30.0
write_makefile
12.0
init
6.0
CRAP 11.8
1 package Package::Install;
2 use strict;
3 use base qw(Package::Base);
4 use Data::Dumper;
5 use ExtUtils::MakeMaker;
6 use Package::Configure;
7 use Term::ANSIColor;
8  
9 sub init {
10 my($self,%arg) = @_;
11  
12 $self->SUPER::init(%arg);
13  
14 $self->configure(Package::Configure->new(%arg)) unless $self->configure();
15 }
16  
17 =head2 compile_manifest()
18  
19 Usage : $obj->compile_manifest()
20 Function: Called by L</write_makefile()>, this iterates over all .pm
21 files in the distro MANIFEST and tries to compile them (perl -c)
22 prints to STDERR a diagnostic message for each.
23 Args : none.
24  
25  
26 =cut
27  
28 sub compile_manifest {
29 my ($self) = @_;
30  
31 my $statusformat = "%-60s[%s]\n";
32 my $fail = colored('FAILED','red');
33 my $pass = colored(' OK ','green');
34 my $base = 'lib/';
35  
36 if(! -e 'MANIFEST'){
37 print STDERR colored("<FATAL> can't find MANIFEST ($!), skipping", 'red bold')."\n";
38 return undef;
39 }
40  
41 my @entries;
42 open(M,"MANIFEST");
43 while(my $file = <M>){
44 chomp $file;
45 next unless $file =~ /\.pm$/ and $file =~ /^$base/;
46  
47 my($pack) = $file =~ /^(.+)\.pm$/; #untaint
48 $pack =~ s/^$base//; #strip leading path
49 $pack =~ s!/!::!g; #replace all / with ::
50  
51 push @entries, $pack;
52 }
53 close(M);
54  
55 print STDERR colored("compiling modules in MANIFEST", 'cyan')."\n";
56  
57 foreach my $pack (@entries){
58 eval "use $pack";
59 if($@ && $ENV{DEBUG}){ print "\n$@\n" }
60 print STDERR sprintf($statusformat,"use $pack", ($@ ? $fail : $pass));
61 }
62 }
63  
64  
65 =head2 write_makefile()
66  
67 Usage : $obj->write_makefile(%arg)
68 Function: calls ExtUtils::MakeMaker's WriteMakefile() with provided %arg,
69 as well as PL_FILES and EXE_FILES as determined by
70 Package::Configure (config file [PL_FILES] [EXE_FILES]
71 sections).
72 Returns :
73 Args : an anonymous hash of WriteMakefile() args. See
74 L<ExtUtils::MakeMaker> for details.
75  
76 =cut
77  
78 sub write_makefile {
79 my ($self,%arg) = @_;
80 $self->compile_manifest();
81 my %pl_files;
82 my @exe_files;
83 if($self->configure->ini()){
84 %pl_files = map {$_ => $self->configure->ini()->val('PL_FILES',$_)} $self->configure->ini()->Parameters('PL_FILES');
85  
86 #warn Dumper(\%pl_files);
87  
88 @exe_files = grep { $self->configure->ini()->val('EXE_FILES',$_) =~ /y1/i } $self->configure->ini()->Parameters('EXE_FILES');
89 }
90  
91 if($arg{bootstrap}){
92 $pl_files{'bin/pstub.PL'} = 'bin/pstub';
93 push @exe_files, 'bin/pstub';
94 delete($arg{bootstrap});
95 }
96  
97 WriteMakefile(
98 %arg,
99 'PL_FILES' => \%pl_files,
100 'EXE_FILES' => \@exe_files,
101 );
102 }
103  
104 =head2 configure()
105  
106 Usage : $obj->configure($newval)
107 Function: holds a Package::Configure instance
108 Example :
109 Returns : value of configure (a scalar)
110 Args : on set, new value (a scalar or undef, optional)
111  
112  
113 =cut
114  
115 sub configure {
116 my($self,$val) = @_;
117 $self->{'configure'} = $val if defined($val);
118 return $self->{'configure'};
119 }
120  
121 =head1 METHODS FOR ExtUtils::MakeMaker
122  
123 =cut
124  
125 sub MY::clean {
126 package MY;
127 my $inherited = shift->SUPER::clean(@_);
128 $inherited .= "\t\$(RM_F) pkg_config.cache\n";
129 return $inherited;
130 }
131  
132 1;