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