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