Skip to content

Instantly share code, notes, and snippets.

@karenetheridge
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karenetheridge/ad7b73178ed5830662cc to your computer and use it in GitHub Desktop.
Save karenetheridge/ad7b73178ed5830662cc to your computer and use it in GitHub Desktop.
Inline stuff for ingy
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;
}
@karenetheridge
Copy link
Author

Or, using afterbuild;

with 'Dist::Zilla::Role::AfterBuild';
sub after_build { ... }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment