package Dist::Zilla::Plugin::MakeMaker::SkipInstall;
$Dist::Zilla::Plugin::MakeMaker::SkipInstall::VERSION = '1.201';
use Moose;
use File::Spec;

with 'Dist::Zilla::Role::AfterBuild';

has filename => (
  isa => 'Str',
  is  => 'ro',
  default =>  'Makefile.PL',

sub after_build {
  my ($self, $args) = @_;
  my $build_root = $args->{build_root};
  my $filename = File::Spec->catfile($build_root, $self->filename);
  my $content = _slurp($filename);
  my ($pre, $post) = split(/^\s*WriteMakefile[(]/sm, $content);
  $content = $pre
           . q{

sub MY::install { "install ::\n" }

           . "\nWriteMakefile("
           . $post;
  open(my $fh, '>', $filename) or Carp::croak("error opening file '$filename' for writing: $!");
  print $fh $content or Carp::croak("error writing to $filename: $!");
  close($fh) or Carp::croak("error closing $filename: $!");

sub _slurp {
  local $/;
  open(my $fh, '<', $_[0]) or Carp::croak("error opening file '$_[0]' for reading: $!");
  my $content = <$fh>;
  close($fh) or Carp::croak("error closing $_[0]: $!");

  return $content;

no Moose;


=head1 NAME

Dist::Zilla::Plugin::MakeMaker::SkipInstall - skip the install rule of MakeMaker

=head1 VERSION

version 1.201


In your C<dist.ini> file:



This small plugin will edit the C<Makefile.PL> file, and override the
install target to become a no-op.

This will make your module fail the install phase. It will be built, and
tested but will never be installed.

The most common use for this techinique is for L<Task> modules. Without
a proper install phase, you can install your Task module repetedly.

=head1 CREDITS

The technique was described by Marcel Gruenauer (hanekomu) in his
article "Repeatedly installing Task::* distributions":


The author just wrapped the concept into a L<Dist::Zilla> plugin.

=head1 SEE ALSO


=head1 AUTHOR

Pedro Melo, C<< <melo at> >>


Copyright 2009 Pedro Melo.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=begin make-pod-coverage-happy

=over 4

=item after_build()

Edits the C<Makefile.PL> in place, searches for C<WriteMakefile> and
prepends our override.


=end make-pod-coverage-happy