File Coverage

blib/lib/Dist/Zilla/Plugin/MakeMaker/SkipInstall.pm
Criterion Covered Total %
statement 23 23 100.0
branch 5 10 50.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 34 39 87.1


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::MakeMaker::SkipInstall;
2             $Dist::Zilla::Plugin::MakeMaker::SkipInstall::VERSION = '1.201';
3 2     2   1408592 use Moose;
  2         301189  
  2         13  
4 2     2   9085 use File::Spec;
  2         2  
  2         610  
5              
6             with 'Dist::Zilla::Role::AfterBuild';
7              
8             has filename => (
9             isa => 'Str',
10             is => 'ro',
11             default => 'Makefile.PL',
12             );
13              
14             sub after_build {
15 1     1 1 681 my ($self, $args) = @_;
16 1         3 my $build_root = $args->{build_root};
17 1         40 my $filename = File::Spec->catfile($build_root, $self->filename);
18            
19 1         3 my $content = _slurp($filename);
20 1         29 my ($pre, $post) = split(/^\s*WriteMakefile[(]/sm, $content);
21 1         4 $content = $pre
22             . q{
23              
24             exit 0 if $ENV{AUTOMATED_TESTING};
25             sub MY::install { "install ::\n" }
26              
27             }
28             . "\nWriteMakefile("
29             . $post;
30            
31 1 50       96 open(my $fh, '>', $filename) or Carp::croak("error opening file '$filename' for writing: $!");
32 1 50       5 print $fh $content or Carp::croak("error writing to $filename: $!");
33 1 50       41 close($fh) or Carp::croak("error closing $filename: $!");
34             }
35              
36             sub _slurp {
37 2     2   330 local $/;
38 2 50       118 open(my $fh, '<', $_[0]) or Carp::croak("error opening file '$_[0]' for reading: $!");
39 2         31 my $content = <$fh>;
40 2 50       52 close($fh) or Carp::croak("error closing $_[0]: $!");
41              
42 2         11 return $content;
43             }
44              
45             __PACKAGE__->meta->make_immutable;
46 2     2   20 no Moose;
  2         4  
  2         8  
47             1;
48              
49             __END__
50              
51             =head1 NAME
52              
53             Dist::Zilla::Plugin::MakeMaker::SkipInstall - skip the install rule of MakeMaker
54              
55             =head1 VERSION
56              
57             version 1.201
58              
59             =head1 SYNOPSIS
60              
61             In your C<dist.ini> file:
62              
63             [MakeMaker::SkipInstall]
64              
65             =head1 DESCRIPTION
66              
67             This small plugin will edit the C<Makefile.PL> file, and override the
68             install target to become a no-op.
69              
70             This will make your module fail the install phase. It will be built, and
71             tested but will never be installed.
72              
73             The most common use for this techinique is for L<Task> modules. Without
74             a proper install phase, you can install your Task module repetedly.
75              
76              
77             =head1 CREDITS
78              
79             The technique was described by Marcel Gruenauer (hanekomu) in his
80             article "Repeatedly installing Task::* distributions":
81              
82             L<http://hanekomu.at/blog/dev/20091005-1227-repeatedly_installing_task_distributions.html>
83              
84             The author just wrapped the concept into a L<Dist::Zilla> plugin.
85              
86              
87             =head1 SEE ALSO
88              
89             L<Dist::Zilla>.
90              
91              
92             =head1 AUTHOR
93              
94             Pedro Melo, C<< <melo at cpan.org> >>
95              
96              
97             =head1 COPYRIGHT & LICENSE
98              
99             Copyright 2009 Pedro Melo.
100              
101             This program is free software; you can redistribute it and/or modify it
102             under the same terms as Perl itself.
103              
104              
105             =begin make-pod-coverage-happy
106              
107             =over 4
108              
109             =item after_build()
110              
111             Edits the C<Makefile.PL> in place, searches for C<WriteMakefile> and
112             prepends our override.
113              
114             =back
115              
116             =end make-pod-coverage-happy
117              
118             =cut