File Coverage

inc/Module/Install/Makefile.pm
Criterion Covered Total %
statement 15 117 12.8
branch 0 48 0.0
condition 0 35 0.0
subroutine 5 18 27.7
pod 0 13 0.0
total 20 231 8.6


line stmt bran cond sub pod time code
1             #line 1
2             package Module::Install::Makefile;
3 1     1   5  
  1         2  
  1         32  
4 1     1   5 use strict 'vars';
  1         2  
  1         24  
5 1     1   5363 use Module::Install::Base;
  1         111084  
  1         28  
6             use ExtUtils::MakeMaker ();
7 1     1   9  
  1         1  
  1         86  
8             use vars qw{$VERSION $ISCORE @ISA};
9 1     1   2 BEGIN {
10 1         2 $VERSION = '0.65';
11 1         1647 $ISCORE = 1;
12             @ISA = qw{Module::Install::Base};
13             }
14 0     0 0    
15             sub Makefile { $_[0] }
16              
17             my %seen = ();
18              
19 0     0 0   sub prompt {
20             shift;
21              
22 0           # Infinite loop protection
23 0 0         my @c = caller();
24 0           if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) {
25             die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])";
26             }
27              
28 0 0 0       # In automated testing, always use defaults
29 0           if ( $ENV{AUTOMATED_TESTING} and ! $ENV{PERL_MM_USE_DEFAULT} ) {
30 0           local $ENV{PERL_MM_USE_DEFAULT} = 1;
31             goto &ExtUtils::MakeMaker::prompt;
32 0           } else {
33             goto &ExtUtils::MakeMaker::prompt;
34             }
35             }
36              
37 0     0 0   sub makemaker_args {
38 0   0       my $self = shift;
39 0 0         my $args = ($self->{makemaker_args} ||= {});
40 0           %$args = ( %$args, @_ ) if @_;
41             $args;
42             }
43              
44             # For mm args that take multiple space-seperated args,
45             # append an argument to the current list.
46 0     0 0   sub makemaker_append {
47 0           my $self = shift;
48 0           my $name = shift;
49 0 0         my $args = $self->makemaker_args;
50             $args->{name} = defined $args->{$name}
51             ? join( ' ', $args->{name}, @_ )
52             : join( ' ', @_ );
53             }
54              
55 0     0 0   sub build_subdirs {
56 0   0       my $self = shift;
57 0           my $subdirs = $self->makemaker_args->{DIR} ||= [];
58 0           for my $subdir (@_) {
59             push @$subdirs, $subdir;
60             }
61             }
62              
63 0     0 0   sub clean_files {
64 0   0       my $self = shift;
65 0           my $clean = $self->makemaker_args->{clean} ||= {};
66             %$clean = (
67             %$clean,
68             FILES => join(' ', grep length, $clean->{FILES}, @_),
69             );
70             }
71              
72 0     0 0   sub realclean_files {
73 0   0       my $self = shift;
74 0           my $realclean = $self->makemaker_args->{realclean} ||= {};
75             %$realclean = (
76             %$realclean,
77             FILES => join(' ', grep length, $realclean->{FILES}, @_),
78             );
79             }
80              
81 0     0 0   sub libs {
82 0 0         my $self = shift;
83 0           my $libs = ref $_[0] ? shift : [ shift ];
84             $self->makemaker_args( LIBS => $libs );
85             }
86              
87 0     0 0   sub inc {
88 0           my $self = shift;
89             $self->makemaker_args( INC => shift );
90             }
91              
92 0     0 0   sub write {
93 0 0         my $self = shift;
94             die "&Makefile->write() takes no arguments\n" if @_;
95 0            
96 0           my $args = $self->makemaker_args;
97 0   0       $args->{DISTNAME} = $self->name;
98 0   0       $args->{NAME} = $self->module_name || $self->name || $self->determine_NAME($args);
99 0           $args->{VERSION} = $self->version || $self->determine_VERSION($args);
100 0 0         $args->{NAME} =~ s/-/::/g;
101 0           if ( $self->tests ) {
102             $args->{test} = { TESTS => $self->tests };
103 0 0         }
104 0           if ($] >= 5.005) {
105 0           $args->{ABSTRACT} = $self->abstract;
106             $args->{AUTHOR} = $self->author;
107 0 0         }
108 0           if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) {
109             $args->{NO_META} = 1;
110 0 0 0       }
111 0           if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) {
112             $args->{SIGN} = 1;
113 0 0         }
114 0           unless ( $self->is_admin ) {
115             delete $args->{SIGN};
116             }
117              
118 0   0       # merge both kinds of requires into prereq_pm
119 0           my $prereq = ($args->{PREREQ_PM} ||= {});
  0            
  0            
120             %$prereq = ( %$prereq, map { @$_ } map { @$_ } grep $_,
121             ($self->build_requires, $self->requires) );
122              
123 0   0       # merge both kinds of requires into prereq_pm
124 0 0         my $subdirs = ($args->{DIR} ||= []);
125 0           if ($self->bundles) {
  0            
126 0           foreach my $bundle (@{ $self->bundles }) {
127 0 0         my ($file, $dir) = @$bundle;
128 0           push @$subdirs, $dir if -d $dir;
129             delete $prereq->{$file};
130             }
131             }
132 0 0          
133 0 0         if ( my $perl_version = $self->perl_version ) {
134             eval "use $perl_version; 1"
135             or die "ERROR: perl: Version $] is installed, "
136             . "but we need version >= $perl_version";
137             }
138 0            
139             $args->{INSTALLDIRS} = $self->installdirs;
140 0            
  0            
  0            
141             my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args;
142 0            
143 0 0         my $user_preop = delete $args{dist}->{PREOP};
144 0           if (my $preop = $self->admin->preop($user_preop)) {
145             $args{dist} = $preop;
146             }
147 0            
148 0   0       my $mm = ExtUtils::MakeMaker::WriteMakefile(%args);
149             $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile');
150             }
151              
152 0     0 0   sub fix_up_makefile {
153 0           my $self = shift;
154 0   0       my $makefile_name = shift;
155 0   0       my $top_class = ref($self->_top) || '';
156             my $top_version = $self->_top->VERSION || '';
157 0 0          
158             my $preamble = $self->preamble
159             ? "# Preamble by $top_class $top_version\n"
160             . $self->preamble
161 0   0       : '';
162             my $postamble = "# Postamble by $top_class $top_version\n"
163             . ($self->postamble || '');
164 0            
165 0 0         local *MAKEFILE;
166 0           open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
  0            
  0            
167 0 0         my $makefile = do { local $/; <MAKEFILE> };
168             close MAKEFILE or die $!;
169 0            
170 0           $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /;
171 0           $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g;
172 0           $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g;
173 0           $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m;
174             $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m;
175              
176             # Module::Install will never be used to build the Core Perl
177             # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks
178 0           # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist
179             $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m;
180             #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m;
181              
182 0           # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well.
183             $makefile =~ s/("?)-I\$\(PERL_LIB\)\1//g;
184              
185             # XXX - This is currently unused; not sure if it breaks other MM-users
186             # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg;
187 0 0          
188 0 0         open MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
189 0 0         print MAKEFILE "$preamble$makefile$postamble" or die $!;
190             close MAKEFILE or die $!;
191 0            
192             1;
193             }
194              
195 0     0 0   sub preamble {
196 0 0         my ($self, $text) = @_;
197 0           $self->{preamble} = $text . $self->{preamble} if defined $text;
198             $self->{preamble};
199             }
200              
201 0     0 0   sub postamble {
202 0   0       my ($self, $text) = @_;
203 0 0         $self->{postamble} ||= $self->admin->postamble;
204 0           $self->{postamble} .= $text if defined $text;
205             $self->{postamble}
206             }
207              
208             1;
209              
210             __END__
211              
212             #line 338