| 1 |
# vim: set ft=perl ts=8 sts=2 sw=2 tw=100 et : |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
package inc::CheckConflicts; |
| 5 |
use stable 0.031 'postderef'; |
| 6 |
|
| 7 |
use Moose; |
| 8 |
with 'Dist::Zilla::Role::InstallTool'; |
| 9 |
|
| 10 |
sub setup_installer { |
| 11 |
my $self = shift; |
| 12 |
|
| 13 |
my @mfpl = grep +($_->name eq 'Makefile.PL' or $_->name eq 'Build.PL'), $self->zilla->files->@*; |
| 14 |
$self->log_fatal('No Makefile.PL or Build.PL was found.') if not @mfpl; |
| 15 |
|
| 16 |
foreach my $file (@mfpl) { |
| 17 |
$self->log_debug([ 'munging %s in setup_installer phase', $file->name ]); |
| 18 |
|
| 19 |
my $orig_content = $file->content; |
| 20 |
$self->log_fatal('could not find position in ' . $file->name . ' to modify!') |
| 21 |
if not $orig_content =~ m/use strict;\nuse warnings;\n\n/g; |
| 22 |
|
| 23 |
my $pos = pos($orig_content); |
| 24 |
|
| 25 |
my $content = <<'CONTENT'; |
| 26 |
if ("$]" < 5.038) { |
| 27 |
die "This distribution will not install where builtin::Backport exists.\n" |
| 28 |
if eval { +require builtin::Backport; 1 }; |
| 29 |
} |
| 30 |
CONTENT |
| 31 |
|
| 32 |
$file->content(substr($orig_content, 0, $pos) . $content . substr($orig_content, $pos)); |
| 33 |
} |
| 34 |
|
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
1; |