fix and regression test for RT #62642
[dbsrgits/DBIx-Class.git] / Makefile.PL
1 use inc::Module::Install 1.00;
2 use strict;
3 use warnings;
4
5 use 5.008001;
6
7 use FindBin;
8 use lib "$FindBin::Bin/lib";
9
10 # adjust ENV for $AUTHOR system() calls
11 use Config;
12 $ENV{PERL5LIB} = join ($Config{path_sep}, @INC);
13
14 use Getopt::Long ();
15
16 my $getopt = Getopt::Long::Parser->new(
17   config => [qw/gnu_getopt bundling_override no_ignore_case pass_through/]
18 );
19 my $args = {
20   skip_author_deps => undef,
21 };
22 $getopt->getoptions($args, 'skip_author_deps');
23 if (@ARGV) {
24   warn "\nIgnoring unrecognized option(s): @ARGV\n\n";
25 }
26
27 # get cpanX --installdeps . to behave in a checkout (most users do not need
28 # the deps for a full test suite run, and if they do - there's MI::AutoInstall
29 # for that)
30 ##
31 ## DO NOT USE THIS HACK IN YOUR DISTS!!! (it makes #toolchain sad)
32 ##
33 $Module::Install::AUTHOR = 0 if (grep { $ENV{"PERL5_${_}_IS_RUNNING"} } (qw/CPANM CPANPLUS CPAN/) );
34
35 ###
36 ### DO NOT ADD OPTIONAL DEPENDENCIES HERE, EVEN AS recommends()
37 ### All of them should go to DBIx::Class::Optional::Dependencies
38 ###
39
40 name     'DBIx-Class';
41 perl_version '5.008001';
42 all_from 'lib/DBIx/Class.pm';
43
44 my $build_requires = {
45   'DBD::SQLite'              => '1.29',
46 };
47
48 my $test_requires = {
49   'File::Temp'               => '0.22',
50   'Test::Builder'            => '0.33',
51   'Test::Exception'          => '0.31',
52   'Test::More'               => '0.92',
53   'Test::Warn'               => '0.21',
54 };
55
56 my $runtime_requires = {
57   'Carp::Clan'               => '6.0',
58   'Class::Accessor::Grouped' => '0.09008',
59   'Class::C3::Componentised' => '1.0005',
60   'Class::Inspector'         => '1.24',
61   'Data::Page'               => '2.00',
62   'DBI'                      => '1.609',
63   'File::Path'               => '2.07',
64   'MRO::Compat'              => '0.09',
65   'Module::Find'             => '0.06',
66   'Path::Class'              => '0.18',
67   'SQL::Abstract'            => '1.69',
68   'Sub::Name'                => '0.04',
69   'Variable::Magic'          => '0.44',
70   'Data::Dumper::Concise'    => '1.000',
71   'Scope::Guard'             => '0.03',
72   'Context::Preserve'        => '0.01',
73   'Try::Tiny'                => '0.04',
74   'namespace::clean'         => '0.14',
75   'Math::BigInt'             => '1.89',
76   'Math::Base36'             => '0.07',
77   'Config::Any'              => '0.20',
78 };
79
80 # this is so we can order requires alphabetically
81 # copies are needed for author requires injection
82 my $reqs = {
83   build_requires => { %$build_requires },
84   requires => { %$runtime_requires },
85   test_requires => { %$test_requires },
86 };
87
88
89 # require extra modules for testing if we're in a checkout
90 my $optdep_msg;
91 if ($Module::Install::AUTHOR) {
92   if ($args->{skip_author_deps}) {
93     $optdep_msg = <<'EOW';
94
95 ******************************************************************************
96 ******************************************************************************
97 ***                                                                        ***
98 *** IGNORING AUTHOR MODE: no optional test dependencies will be forced.    ***
99 ***                                                                        ***
100 *** If you are using this checkout with the intention of submitting a DBIC ***
101 *** patch, you are *STRONGLY ENCOURAGED* to install all dependencies, so   ***
102 *** that every possible unit-test will run.                                ***
103 ***                                                                        ***
104 ******************************************************************************
105 ******************************************************************************
106
107 EOW
108   }
109   else {
110     $optdep_msg = <<'EOW';
111
112 ******************************************************************************
113 ******************************************************************************
114 ***                                                                        ***
115 *** AUTHOR MODE: all optional test dependencies converted to hard requires ***
116 ***       ( to disable re-run Makefile.PL with --skip_author_deps )        ***
117 ***                                                                        ***
118 ******************************************************************************
119 ******************************************************************************
120
121 EOW
122
123     require DBIx::Class::Optional::Dependencies;
124     $reqs->{test_requires} = {
125       %{$reqs->{test_requires}},
126       map { %$_ } (values %{DBIx::Class::Optional::Dependencies->req_group_list}),
127     };
128   }
129 }
130
131 # compose final req list, for alphabetical ordering
132 my %final_req;
133 for my $rtype (keys %$reqs) {
134   for my $mod (keys %{$reqs->{$rtype}} ) {
135
136     # sanity check req duplications
137     if ($final_req{$mod}) {
138       die "$mod specified as both a '$rtype' and a '$final_req{$mod}[0]'\n";
139     }
140
141     $final_req{$mod} = [ $rtype, $reqs->{$rtype}{$mod}||0 ],
142   }
143 }
144
145 # actual require
146 for my $mod (sort keys %final_req) {
147   my ($rtype, $ver) = @{$final_req{$mod}};
148   no strict 'refs';
149   $rtype->($mod, $ver);
150 }
151
152 # output twice since the deplist is > 70 lines
153 warn $optdep_msg if $Module::Install::AUTHOR;
154 auto_install();
155 warn $optdep_msg if $Module::Install::AUTHOR;
156
157 # re-create various autogenerated documentation bits
158 if ($Module::Install::AUTHOR) {
159
160   print "Regenerating README\n";
161   system('pod2text lib/DBIx/Class.pm > README');
162
163   if (-f 'MANIFEST') {
164     print "Removing MANIFEST\n";
165     unlink 'MANIFEST';
166   }
167
168   print "Regenerating Optional/Dependencies.pod\n";
169   require DBIx::Class::Optional::Dependencies;
170   DBIx::Class::Optional::Dependencies->_gen_pod (Meta->version);
171
172   # FIXME Disabled due to unsolved issues, ask theorbtwo
173   #  require Module::Install::Pod::Inherit;
174   #  PodInherit();
175 }
176
177
178 tests_recursive (qw|
179     t
180 |);
181
182 # temporary(?) until I get around to fix M::I wrt xt/
183 # needs Module::Install::AuthorTests
184 eval {
185   recursive_author_tests (qw/xt/);
186   1;
187 } || do {
188   if ($Module::Install::AUTHOR && ! $args->{skip_author_deps}) {
189     my $err = $@;
190     eval { require Module::Install::AuthorTests }
191       || die "\nYou need Module::Install::AuthorTests installed to run this Makefile.PL in author mode (or supply --skip_author_deps):\n\n$@\n";
192     die $@;
193   }
194 };
195
196
197 install_script (qw|
198     script/dbicadmin
199 |);
200
201
202 ### Mangle makefile - read the comments for more info
203 #
204 postamble <<"EOP";
205
206 # This will add an extra dep-spec for the distdir target,
207 # which `make` will fold together in a first-come first-serve
208 # fashion. What we do here is essentially adding extra
209 # commands to execute once the distdir is assembled (via
210 # create_distdir), but before control is returned to a higher
211 # calling rule.
212 distdir : dbicadmin_pod_inject
213
214 # The pod self-injection code is in fact a hidden option in
215 # dbicadmin itself
216 dbicadmin_pod_inject :
217 \tcd \$(DISTVNAME) && \$(ABSPERL) -Ilib script/dbicadmin --selfinject-pod
218
219 # Regenerate manifest before running create_distdir.
220 create_distdir : manifest
221
222 EOP
223
224 homepage 'http://www.dbix-class.org/';
225 resources 'IRC'         => 'irc://irc.perl.org/#dbix-class';
226 resources 'license'     => 'http://dev.perl.org/licenses/';
227 resources 'repository'  => 'git://git.shadowcat.co.uk/dbsrgits/DBIx-Class.git';
228 resources 'MailingList' => 'http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class';
229 resources 'bugtracker'  => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class';
230
231 # Deprecated/internal modules need no exposure
232 no_index directory => $_ for (qw|
233   lib/DBIx/Class/Admin
234   lib/DBIx/Class/PK/Auto
235   lib/DBIx/Class/CDBICompat
236 |);
237 no_index package => $_ for (qw/
238   DBIx::Class::Storage::DBIHacks
239 /);
240
241 WriteAll();
242
243 # Re-write META.yml to _exclude_ all forced requires (we do not want to ship this)
244 # We are also not using M::I::AuthorRequires as this will be an extra dep, and
245 # deps in Makefile.PL suck (no autoinstall)
246 if ($Module::Install::AUTHOR && ! $args->{skip_author_deps} ) {
247
248   # FIXME test_requires is not yet part of META
249   my %original_build_requires = ( %$build_requires, %$test_requires );
250   my @all_build_requires = @{delete Meta->{values}{build_requires}};
251   my %removed_build_requires;
252
253   for (@all_build_requires) {
254     if ($original_build_requires{$_->[0]}) {
255       push @{Meta->{values}{build_requires}}, $_;
256     }
257     else {
258       $removed_build_requires{$_->[0]} = $_->[1]
259         unless $_->[0] eq 'ExtUtils::MakeMaker';
260     }
261   }
262
263   print "Regenerating META with author requires excluded\n";
264   Meta->write;
265
266   # test that we really took things away (just in case)
267   my $meta = do { local @ARGV = 'META.yml'; local $/; <> };
268   for (keys %removed_build_requires) {
269     delete $removed_build_requires{$_}
270       unless $meta =~ /^ \s+ $_: \s+ $removed_build_requires{$_} \s* $/mx
271   }
272
273   if (keys %removed_build_requires) {
274     die join ("\n",
275       "\n\nFATAL FAIL! It looks like some author dependencies made it to the META.yml:",
276       "(most likely a broken Module::Install)\n",
277       map { "\t$_" } (keys %removed_build_requires)
278     ) . "\n\n";
279   }
280 }