Switch the shortener (used only by oracle) reqs to an optional dependency
[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
58 my $runtime_requires = {
59   'Carp::Clan'               => '6.0',
60   'Class::Accessor::Grouped' => '0.10000',
61   'Class::C3::Componentised' => '1.0005',
62   'Class::Inspector'         => '1.24',
63   'Config::Any'              => '0.20',
64   'Context::Preserve'        => '0.01',
65   'Data::Dumper::Concise'    => '1.000',
66   'Data::Page'               => '2.00',
67   'MRO::Compat'              => '0.09',
68   'Module::Find'             => '0.06',
69   'Path::Class'              => '0.18',
70   'Scope::Guard'             => '0.03',
71   'SQL::Abstract'            => '1.72',
72   'Try::Tiny'                => '0.04',
73
74   # XS (or XS-dependent) libs
75   'DBI'                      => '1.609',
76   'namespace::clean'         => '0.14',
77   'Sub::Name'                => '0.04',
78   'Variable::Magic'          => '0.44',
79
80   # dual-life corelibs needing a specific bugfixed version
81   'File::Path'               => '2.07',
82 };
83
84 # this is so we can order requires alphabetically
85 # copies are needed for author requires injection
86 my $reqs = {
87   build_requires => { %$build_requires },
88   requires => { %$runtime_requires },
89   test_requires => { %$test_requires },
90 };
91
92 my $opt_testdeps = {
93   map { %$_ } (values %{DBIx::Class::Optional::Dependencies->req_group_list})
94 };
95
96 # require extra modules for testing if we're in a checkout
97 my $optdep_msg;
98 if ($Module::Install::AUTHOR) {
99   if ($args->{skip_author_deps}) {
100     $optdep_msg = <<'EOW';
101
102 ******************************************************************************
103 ******************************************************************************
104 ***                                                                        ***
105 *** IGNORING AUTHOR MODE: no optional test dependencies will be forced.    ***
106 ***                                                                        ***
107 *** If you are using this checkout with the intention of submitting a DBIC ***
108 *** patch, you are *STRONGLY ENCOURAGED* to install all dependencies, so   ***
109 *** that every possible unit-test will run.                                ***
110 ***                                                                        ***
111 ******************************************************************************
112 ******************************************************************************
113
114 EOW
115   }
116   else {
117     $optdep_msg = <<'EOW';
118
119 ******************************************************************************
120 ******************************************************************************
121 ***                                                                        ***
122 *** AUTHOR MODE: all optional test dependencies converted to hard requires ***
123 ***       ( to disable re-run Makefile.PL with --skip_author_deps )        ***
124 ***                                                                        ***
125 ******************************************************************************
126 ******************************************************************************
127
128 EOW
129
130     $reqs->{test_requires} = {
131       %{$reqs->{test_requires}},
132       %$opt_testdeps
133     };
134   }
135 }
136
137 # compose final req list, for alphabetical ordering
138 my %final_req;
139 for my $rtype (keys %$reqs) {
140   for my $mod (keys %{$reqs->{$rtype}} ) {
141
142     # sanity check req duplications
143     if ($final_req{$mod}) {
144       die "$mod specified as both a '$rtype' and a '$final_req{$mod}[0]'\n";
145     }
146
147     $final_req{$mod} = [ $rtype, $reqs->{$rtype}{$mod}||0 ],
148   }
149 }
150
151 # actual require
152 for my $mod (sort keys %final_req) {
153   my ($rtype, $ver) = @{$final_req{$mod}};
154   no strict 'refs';
155   $rtype->($mod, $ver);
156 }
157
158 # output twice since the deplist is > 70 lines
159 warn $optdep_msg if $Module::Install::AUTHOR;
160 auto_install();
161 warn $optdep_msg if $Module::Install::AUTHOR;
162
163 # re-create various autogenerated documentation bits
164 if ($Module::Install::AUTHOR) {
165
166   print "Regenerating README\n";
167   system('pod2text lib/DBIx/Class.pm > README');
168
169   if (-f 'MANIFEST') {
170     print "Removing MANIFEST\n";
171     unlink 'MANIFEST';
172   }
173
174   print "Regenerating Optional/Dependencies.pod\n";
175   require DBIx::Class::Optional::Dependencies;
176   DBIx::Class::Optional::Dependencies->_gen_pod (Meta->version);
177
178   # FIXME Disabled due to unsolved issues, ask theorbtwo
179   #  require Module::Install::Pod::Inherit;
180   #  PodInherit();
181 }
182
183
184 tests_recursive (qw|
185     t
186 |);
187
188 # temporary(?) until I get around to fix M::I wrt xt/
189 # needs Module::Install::AuthorTests
190 eval {
191   recursive_author_tests (qw/xt/);
192   1;
193 } || do {
194   if ($Module::Install::AUTHOR && ! $args->{skip_author_deps}) {
195     my $err = $@;
196     eval { require Module::Install::AuthorTests }
197       || die "\nYou need Module::Install::AuthorTests installed to run this Makefile.PL in author mode (or supply --skip_author_deps):\n\n$@\n";
198     die $@;
199   }
200 };
201
202
203 install_script (qw|
204     script/dbicadmin
205 |);
206
207
208 ### Mangle makefile - read the comments for more info
209 #
210 postamble <<"EOP";
211
212 # This will add an extra dep-spec for the distdir target,
213 # which `make` will fold together in a first-come first-serve
214 # fashion. What we do here is essentially adding extra
215 # commands to execute once the distdir is assembled (via
216 # create_distdir), but before control is returned to a higher
217 # calling rule.
218 distdir : dbicadmin_pod_inject
219
220 # The pod self-injection code is in fact a hidden option in
221 # dbicadmin itself
222 dbicadmin_pod_inject :
223 \tcd \$(DISTVNAME) && \$(ABSPERL) -Ilib script/dbicadmin --selfinject-pod
224
225 # Regenerate manifest before running create_distdir.
226 create_distdir : manifest
227
228 EOP
229
230 homepage 'http://www.dbix-class.org/';
231 resources 'IRC'         => 'irc://irc.perl.org/#dbix-class';
232 resources 'license'     => 'http://dev.perl.org/licenses/';
233 resources 'repository'  => 'git://git.shadowcat.co.uk/dbsrgits/DBIx-Class.git';
234 resources 'MailingList' => 'http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class';
235 resources 'bugtracker'  => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class';
236
237 # Deprecated/internal modules need no exposure
238 no_index directory => $_ for (qw|
239   lib/DBIx/Class/Admin
240   lib/DBIx/Class/PK/Auto
241   lib/DBIx/Class/CDBICompat
242 |);
243 no_index package => $_ for (qw/
244   DBIx::Class::Storage::DBIHacks
245 /);
246
247 WriteAll();
248
249 # Re-write META.yml to _exclude_ all forced build-requires (we do not want to ship
250 # this) We are also not using M::I::AuthorRequires as this will be an extra dep,
251 # and deps in Makefile.PL still suck
252 # Also always test the result so we stop shipping borked dependency lists to CPAN
253
254 # FIXME test_requires is not yet part of META
255 my %original_build_requires = ( %$build_requires, %$test_requires );
256 my @all_build_requires = @{delete Meta->{values}{build_requires}};
257 my %removed_build_requires;
258
259 for (@all_build_requires) {
260   if ($original_build_requires{$_->[0]}) {
261     push @{Meta->{values}{build_requires}}, $_;
262   }
263   else {
264     $removed_build_requires{$_->[0]} = $_->[1]
265       unless $_->[0] eq 'ExtUtils::MakeMaker';
266   }
267 }
268
269 # Rewrite only in author mode, the original META should not contain anything anyway
270 # if we executed as non-author
271 if ($Module::Install::AUTHOR && keys %removed_build_requires) {
272   print "Regenerating META with author requires excluded\n";
273   Meta->write;
274 }
275
276 # test that we really took things away (just in case, happened twice somehow)
277 exit 0 unless -f 'META.yml';  # in case bizarro comes around
278 my $meta = do { local @ARGV = 'META.yml'; local $/; <> };
279
280 # this is safe as there is a fatal check earlier to make sure $opt_testdeps does
281 # not contain any real dependencies
282 my @illegal_leftovers = grep
283   { $meta =~ /^ \s+ \Q$_\E \: \s+ /mx }
284   ( sort keys %$opt_testdeps )
285 ;
286
287 if (@illegal_leftovers) {
288   die join ("\n",
289     "\n\nFATAL FAIL! It looks like some author dependencies made it to the META.yml:\n",
290     map { "\t$_" } @illegal_leftovers
291   ) . "\n\n";
292 }