From 5ceef90c2388f73c0de979cd19cb3ff5060ecb66 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 1 Aug 2013 11:06:44 -0400 Subject: refactor this to make it easier to modify --- Makefile.PL | 23 +++++++++-------------- inc/MMHelper.pm | 26 ++++++++++++++++++++++++++ inc/MakeMaker.pm | 19 ++++++------------- 3 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 inc/MMHelper.pm diff --git a/Makefile.PL b/Makefile.PL index 2179cc5..d6d0ece 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -8,19 +8,14 @@ use warnings; use Config; use ExtUtils::MakeMaker::Dist::Zilla::Develop; -use Devel::CallParser 'callparser1_h', 'callparser_linkable'; -open my $fh, '>', 'callparser1.h' or die "Couldn't write to callparser1.h"; -$fh->print(callparser1_h); +use inc::MMHelper; -my @linkable = callparser_linkable; -unshift @linkable, "Keyword$Config{obj_ext}" if @linkable; - -WriteMakefile( - NAME => 'Parse::Keyword', - clean => { - FILES => "callparser1.h", - }, - (@linkable - ? (OBJECT => join(' ', @linkable)) - : ()), +my %WriteMakefileArgs = ( + NAME => 'Parse::Keyword', + %{ inc::MMHelper::mm_args() }, ); + +eval inc::MMHelper::makefile_pl_extra . ';1;' + or die $@; + +WriteMakefile(%WriteMakefileArgs); diff --git a/inc/MMHelper.pm b/inc/MMHelper.pm new file mode 100644 index 0000000..8e42fa9 --- /dev/null +++ b/inc/MMHelper.pm @@ -0,0 +1,26 @@ +package inc::MMHelper; +use strict; +use warnings; + +sub makefile_pl_extra { + return <<'EXTRA'; +use Config; +use Devel::CallParser 'callparser1_h', 'callparser_linkable'; +open my $fh, '>', 'callparser1.h' or die "Couldn't write to callparser1.h"; +$fh->print(callparser1_h); +my @linkable = callparser_linkable; +unshift @linkable, "Keyword$Config{obj_ext}" if @linkable; +$WriteMakefileArgs{OBJECT} = join(' ', @linkable) if @linkable; +EXTRA +} + +sub mm_args { + return { + NORECURS => 1, + clean => { + FILES => "callparser1.h", + } + }; +} + +1; diff --git a/inc/MakeMaker.pm b/inc/MakeMaker.pm index 25cbf7e..bb31600 100644 --- a/inc/MakeMaker.pm +++ b/inc/MakeMaker.pm @@ -1,5 +1,6 @@ package inc::MakeMaker; use Moose; +use inc::MMHelper; extends 'Dist::Zilla::Plugin::MakeMaker::Awesome'; @@ -7,15 +8,7 @@ around _build_MakeFile_PL_template => sub { my $orig = shift; my $self = shift; my $tmpl = $self->$orig; - my $extra = <<'EXTRA'; -use Config; -use Devel::CallParser 'callparser1_h', 'callparser_linkable'; -open my $fh, '>', 'callparser1.h' or die "Couldn't write to callparser1.h"; -$fh->print(callparser1_h); -my @linkable = callparser_linkable; -unshift @linkable, "Keyword$Config{obj_ext}" if @linkable; -$WriteMakefileArgs{OBJECT} = join(' ', @linkable) if @linkable; -EXTRA + my $extra = inc::MMHelper::makefile_pl_extra; $tmpl =~ s/^(WriteMakefile\()/$extra\n$1/m or die "Couldn't fix template"; return $tmpl; @@ -25,10 +18,10 @@ around _build_WriteMakefile_args => sub { my $orig = shift; my $self = shift; my $args = $self->$orig(@_); - $args->{clean} = { - FILES => "callparser1.h", - }; - return $args; + return { + %$args, + %{ inc::MMHelper::mm_args() }, + } }; __PACKAGE__->meta->make_immutable; -- cgit v1.2.3