Switch to EU::HC (with an inc::latest-like approach)
[p5sagit/namespace-clean.git] / Makefile.PL
1 use strict;
2 use warnings;
3 use 5.008001;
4
5 my %META = (
6   name => 'namespace-clean',
7   license => 'perl_5',
8
9   abstract => 'Keep imports and functions out of your namespace',
10   author => [
11     'Robert \'phaylon\' Sedlacek <rs@474.at>',
12     'Florian Ragwitz <rafl@debian.org>',
13     'Jesse Luehrs <doy@tozt.net>',
14     'Peter Rabbitson <ribasushi@cpan.org>',
15     'Father Chrysostomos <sprout@cpan.org>',
16   ],
17
18   prereqs => {
19     configure => {
20       requires => {
21         'ExtUtils::MakeMaker'   => 0,
22       }
23     },
24     runtime => {
25       requires => {
26         'Package::Stash' => '0.23',
27         'B::Hooks::EndOfScope' => '0.12',
28         'perl' => '5.008001',
29       },
30     },
31     test => {
32       requires => {
33         'Test::More' => '0.47',
34       }
35     },
36   },
37
38   resources => {
39     x_IRC => 'irc://irc.perl.org/#toolchain',
40     homepage => 'http://search.cpan.org/dist/namespace-clean',
41     repository => {
42       type => 'git',
43       url => 'git://git.shadowcat.co.uk/p5sagit/namespace-clean.git',
44       web => 'https://github.com/p5sagit/namespace-clean',
45     },
46     bugtracker => {
47       mailto => 'bug-namespace-clean@rt.cpan.org',
48       web => 'http://rt.cpan.org/Public/Dist/Display.html?Name=namespace-clean',
49     },
50   },
51 );
52
53 my %MM_ARGS = ( (
54   # a sub-namer is needed if using the debugger on some perls
55   require 'lib/namespace/clean/_Util.pm'
56     and
57   namespace::clean::_Util::DEBUGGER_NEEDS_CV_RENAME()
58     and
59   namespace::clean::_Util::_namer_load_error()
60     and
61   usable_compiler_present()
62 )
63   # when changing version, also change $sn_ver in namespace/clean/_Util.pm
64   ? ( PREREQ_PM => { 'Sub::Name' => '0.04' } )
65   : ()
66 );
67
68 ## XS-checking BOILERPLATE ###################################################
69 sub usable_compiler_present {
70   return 0 if parse_args()->{PUREPERL_ONLY};
71
72   my $ucp;
73
74   local $@;
75   eval {
76     # poor man's inc::latest
77     my $euhc_fn = 'ExtUtils/HasCompiler.pm';
78     my $euhc_found_in_INC_dir;
79
80     ( ($euhc_found_in_INC_dir) = grep {
81       not length ref $_
82         and
83       -f "$_/$euhc_fn"
84         and
85       -r "$_/$euhc_fn"
86     } @INC )
87       and
88     (
89       MM->parse_version("$euhc_found_in_INC_dir/$euhc_fn")
90         >
91       MM->parse_version("inc/$euhc_fn")
92     )
93       and
94     eval { require ExtUtils::HasCompiler };
95
96     unless ( $INC{'ExtUtils/HasCompiler.pm'} ) {
97       local @INC = ( "inc", @INC );
98       require ExtUtils::HasCompiler;
99     }
100
101     $ucp = ExtUtils::HasCompiler::can_compile_loadable_object(quiet => 1)
102       ? 1
103       : 0
104     ;
105
106     1;
107   };
108
109   if( my $used_fn = $INC{'ExtUtils/HasCompiler.pm'} ) {
110     printf
111       "ExtUtils::HasCompiler::can_compile_loadable_object() v%s (loaded from %s) returned: %s\n",
112       ExtUtils::HasCompiler->VERSION,
113       $used_fn,
114       ( defined($ucp) ? $ucp : "UNKNOWN" ),
115     ;
116   }
117   else {
118     print "Something went wrong when trying to load/use ExtUtils::HasCompiler:\n$@\n\n";
119   }
120
121   $ucp;
122 }
123
124
125 # FIXME - this has been cargo-culted from
126 # https://metacpan.org/source/HAARG/strictures-2.000002/Makefile.PL
127 # There likely will be better ways to handle %ENV and @ARGV directly within
128 # EU::HC in the future
129 sub parse_args {
130   # copied from EUMM
131   require ExtUtils::MakeMaker;
132   require Text::ParseWords;
133   ExtUtils::MakeMaker::parse_args(
134     my $tmp = {},
135     Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''),
136     @ARGV,
137   );
138   return $tmp->{ARGS} || {};
139 }
140 ## END XS-checking BOILERPLATE ###############################################
141
142
143 ## BOILERPLATE ###############################################################
144 require ExtUtils::MakeMaker;
145
146 # have to do this since old EUMM dev releases miss the eval $VERSION line
147 my $eumm_version  = eval $ExtUtils::MakeMaker::VERSION;
148 my $mymeta        = $eumm_version >= 6.57_02;
149 my $mymeta_broken = $mymeta && $eumm_version < 6.57_07;
150
151 ($MM_ARGS{NAME} = $META{name}) =~ s/-/::/g;
152 ($MM_ARGS{VERSION_FROM} = "lib/$MM_ARGS{NAME}.pm") =~ s{::}{/}g;
153 $META{license} = [ $META{license} ]
154   if $META{license} && !ref $META{license};
155 $MM_ARGS{LICENSE} = $META{license}[0]
156   if $META{license} && $eumm_version >= 6.30;
157 $MM_ARGS{NO_MYMETA} = 1
158   if $mymeta_broken;
159 $MM_ARGS{META_ADD} = { 'meta-spec' => { version => 2 }, %META }
160   unless -f 'META.yml';
161
162 for (qw(configure build test runtime)) {
163   my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES';
164   my $r = $MM_ARGS{$key} = {
165     %{$META{prereqs}{$_}{requires} || {}},
166     %{delete $MM_ARGS{$key} || {}},
167   };
168   defined $r->{$_} or delete $r->{$_} for keys %$r;
169 }
170
171 $MM_ARGS{MIN_PERL_VERSION} = delete $MM_ARGS{PREREQ_PM}{perl} || 0;
172
173 delete $MM_ARGS{MIN_PERL_VERSION}
174   if $eumm_version < 6.47_01;
175 $MM_ARGS{BUILD_REQUIRES} = {%{$MM_ARGS{BUILD_REQUIRES}}, %{delete $MM_ARGS{TEST_REQUIRES}}}
176   if $eumm_version < 6.63_03;
177 $MM_ARGS{PREREQ_PM} = {%{$MM_ARGS{PREREQ_PM}}, %{delete $MM_ARGS{BUILD_REQUIRES}}}
178   if $eumm_version < 6.55_01;
179 delete $MM_ARGS{CONFIGURE_REQUIRES}
180   if $eumm_version < 6.51_03;
181
182 ExtUtils::MakeMaker::WriteMakefile(%MM_ARGS);
183 ## END BOILERPLATE ###########################################################