Dist-Zilla-PluginBundle-Author-Plicease
view release on metacpan or search on metacpan
lib/Dist/Zilla/Plugin/Author/Plicease/MakeMaker.pm view on Meta::CPAN
package Dist::Zilla::Plugin::Author::Plicease::MakeMaker 2.79 {
use 5.020;
use Moose;
use namespace::autoclean;
use Perl::Tidy ();
use Dist::Zilla::Plugin::Author::Plicease ();
use List::Util qw( first );
use experimental qw( postderef );
# ABSTRACT: munge the AUTHOR section
extends 'Dist::Zilla::Plugin::MakeMaker';
with 'Dist::Zilla::Role::MetaProvider';
around write_makefile_args => sub {
my($orig, $self, @args) = @_;
my $h = $self->$orig(@args);
# to prevent any non .pm/.pod files from being installed in lib
# because shit like this is stuff we ought to have to customize.
my %PM = map {; "lib/$_" => "\$(INST_LIB)/$_" }
map { s/^lib\///r }
grep /^lib\/.*\.p(od|m)$/,
map { $_->name }
$self->zilla->files->@*;
$h->{PM} = \%PM;
$h;
};
around setup_installer => sub {
my($orig, $self, @args) = @_;
$self->$orig(@args);
my $file = first { $_->name eq 'Makefile.PL' } $self->zilla->files->@*;
my $mod = first { $_->name eq 'inc/mymm.pl' } $self->zilla->files->@*;
my $config = first { $_->name eq 'inc/mymm-config.pl' } $self->zilla->files->@*;
my $build = first { $_->name eq 'inc/mymm-build.pl' } $self->zilla->files->@*;
my $test = first { $_->name eq 'inc/mymm-test.pl' } $self->zilla->files->@*;
my $clean = first { $_->name eq 'inc/mymm-clean.pl' } $self->zilla->files->@*;
my @content = do {
my $in = $file->content;
my $out = '';
my $err = '';
local @ARGV = ();
my $error = Perl::Tidy::perltidy(
source => \$in,
destination => \$out,
stderr => \$err,
perltidyrc => Dist::Zilla::Plugin::Author::Plicease->dist_dir->child('perltidyrc')->stringify,
);
$self->log("perltidy: $_") for split /\n/, $err;
$self->log_fatal("perltidy failed!") if $error;
split /\n/, $out;
};
# pet-peve1: remove blank lines between use
{
my $i = 0;
while($i<$#content)
{
if($content[$i] =~ /^(use|#)/)
{ $i++ }
elsif($content[$i] =~ /^\s*$/)
{ @content = @content[0..($i-1),($i+1)..$#content] }
else
{
my @extra = ('');
if($mod)
{
unshift @extra, 'require "./inc/mymm.pl";';
}
@content = (
@content[0..($i-1)],
@extra,
@content[($i)..$#content]
);
last;
}
}
}
# pet-peve2: squeeze multiple blank lines
{
my @new;
my $last_empty = 0;
foreach my $line (@content)
{
if($line =~ /^\s*$/)
{
if($last_empty)
{ next }
else
{
$last_empty = 1;
}
}
else
{
$last_empty = 0;
}
push @new, $line;
( run in 2.286 seconds using v1.01-cache-2.11-cpan-b9db842bd85 )