-
-
Save karenetheridge/ad7b73178ed5830662cc to your computer and use it in GitHub Desktop.
Inline stuff for ingy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends 'Dist::Zilla::Plugin::MakeMaker::Awesome'; | |
with 'Dist::Zilla::Role::AfterBuild'; # gives us the after_build hook | |
has module => ( | |
isa => 'ArrayRef[Str]', | |
traits => ['Array'], | |
handles => { modules => 'elements' }, | |
required => 1, | |
); | |
sub mvp_multivalue_args { qw(module) } | |
# add our FixMakefile call to Makefile.PL, respecting any other | |
# footer lines that were provided in dist.ini | |
around _build_footer => sub { | |
my $orig = shift; | |
my $self = shift; | |
return join "\n", | |
'FixMakefile(', | |
(map { " module => '" . $_ . "'," } $self->modules), | |
');', | |
'', | |
$self->$orig(@_); | |
}; | |
sub after_build { | |
my ($self, $opts) = @); | |
my $build_root = $opts->{build_root}; | |
... | |
} | |
# but, if we want a file munger: | |
with 'Dist::Zilla::Role::FileMunger'; | |
use List::Util 1.33 'none'; | |
sub munge_file { | |
my ($self, $file) = @_; | |
# this is a bit of a hack, and should be replaced with some ethercode | |
# using Module::Metadata | |
(my $module_name = $file->name) =~ s{/}{::}g; | |
$module_name =~ s/\.pm$//; | |
return if none { $module_name eq $_ } $self->modules; | |
# now we have a file object in $file, whose package name corresponds to | |
# something in $self->modules. | |
# its content is in ->content, a r/w accessor. | |
# and here, a miracle occurs... | |
$file->content('new file content here'); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or, using afterbuild;