RT45195 various indexer fixes
[dbsrgits/DBIx-Class.git] / Makefile.PL
1 use inc::Module::Install 0.67;
2 use strict;
3 use warnings;
4 use POSIX ();
5
6 use 5.006001; # delete this line if you want to send patches for earlier.
7
8 name     'DBIx-Class';
9 perl_version '5.006001';
10 all_from 'lib/DBIx/Class.pm';
11
12 requires 'DBD::SQLite'              => 1.23;
13 requires 'Data::Page'               => 2.00;
14 requires 'Scalar::Util'             => 0;
15 requires 'SQL::Abstract'            => 1.51;
16 requires 'SQL::Abstract::Limit'     => 0.13;
17 requires 'Class::C3::Componentised' => 1.0005;
18 requires 'Storable'                 => 0;
19 requires 'Carp::Clan'               => 0;
20 requires 'DBI'                      => 1.40;
21 requires 'Module::Find'             => 0;
22 requires 'Class::Inspector'         => 0;
23 requires 'Class::Accessor::Grouped' => 0.08003;
24 requires 'JSON::Any'                => 1.17;
25 requires 'Scope::Guard'             => 0.03;
26 requires 'Path::Class'              => 0;
27 requires 'List::Util'               => 1.19;
28 requires 'Sub::Name'                => 0.04;
29 requires 'MRO::Compat'              => 0.09;
30
31 # Perl 5.8.0 doesn't have utf8::is_utf8()
32 requires 'Encode'                   => 0 if ($] <= 5.008000);  
33
34 # configure_requires so the sanity check below can run
35 configure_requires 'DBD::SQLite';
36
37 test_requires 'Test::Builder'       => 0.33;
38 test_requires 'Test::Warn'          => 0.11;
39 test_requires 'Test::Exception'     => 0;
40 test_requires 'Test::Deep'          => 0;
41
42 recommends 'SQL::Translator'        => 0.09004;
43
44 install_script 'script/dbicadmin';
45
46 tests_recursive 't';
47
48 # re-build README and require extra modules for testing if we're in a checkout
49
50 my %force_requires_if_author = (
51   'Test::Pod::Coverage'       => 1.04,
52   'SQL::Translator'           => 0.09004,
53
54   # CDBI-compat related
55   'DBIx::ContextualFetch'     => 0,
56   'Class::DBI::Plugin::DeepAbstractSearch' => 0,
57   'Class::Trigger'            => 0,
58   'Time::Piece'               => 0,
59   'Clone'                     => 0,
60
61   # t/52cycle.t
62   'Test::Memory::Cycle'       => 0,
63
64   # t/60core.t
65   'DateTime::Format::MySQL'   => 0,
66
67   # t/72pg.t
68   $ENV{DBICTEST_PG_DSN}
69     ? ('Sys::SigAction'=> 0)
70     : ()
71   ,
72
73   # t/93storage_replication.t
74   'Moose',                    => 0,
75   'MooseX::AttributeHelpers'  => 0.12,
76
77   # t/96_is_deteministic_value.t
78   'DateTime::Format::Strptime' => 0,
79 );
80
81 if ($Module::Install::AUTHOR) {
82
83   foreach my $module (keys %force_requires_if_author) {
84     build_requires ($module => $force_requires_if_author{$module});
85   }
86
87   system('pod2text lib/DBIx/Class.pm > README');
88 }
89
90 auto_provides;
91
92 if ($Module::Install::AUTHOR) {
93   warn <<'EOW';
94 ******************************************************************************
95 ******************************************************************************
96 ***                                                                        ***
97 *** AUTHOR MODE: all optional test dependencies converted to hard requires ***
98 ***                                                                        ***
99 ******************************************************************************
100 ******************************************************************************
101
102 EOW
103 }
104 auto_install;
105
106 # Have all prerequisites, check DBD::SQLite sanity
107 if (! $ENV{DBICTEST_NO_SQLITE_CHECK} ) {
108
109   my $pid = fork();
110   if (not defined $pid) {
111       die "Unable to fork(): $!";
112   }
113   elsif (! $pid) {
114
115       # Win32 does not have real fork()s so a segfault will bring
116       # everything down. Warn about it.
117       if ($^O eq 'MSWin32') {
118         print <<'EOW';
119
120 ######################################################################
121 #                                                                    #
122 # A short stress-testing of DBD::SQLite will follow. If you have a   #
123 # buggy library this might very well be the last text you will see   #
124 # before the installation silently terminates. If this happens it    #
125 # would mean that you are running a buggy version of DBD::SQLite     #
126 # known to randomly segfault on errors. Even if you have the latest  #
127 # CPAN module version, the system sqlite3 dynamic library might have #
128 # been compiled against an older buggy sqlite3 dev library (oddly    #
129 # DBD::SQLite will prefer the system library against the one bundled #
130 # with it). You are strongly advised to resolve this issue before    #
131 # proceeding.                                                        #
132 #                                                                    #
133 # If this happens to you (this text is the last thing you see), and  #
134 # you just want to install this module without worrying about the    #
135 # tests (which will almost certainly fail) - set the environment     #
136 # variable DBICTEST_NO_SQLITE_CHECK to a true value and try again.   #
137 #                                                                    #
138 ######################################################################
139
140 EOW
141       }
142
143       require DBI;
144       for (1 .. 100) {
145           my $dbh;
146           $dbh = DBI->connect ('dbi:SQLite::memory:', undef, undef, {
147               AutoCommit => 1,
148               RaiseError => 0,
149               PrintError => 0,
150           })
151               or die "Unable to connect to database: $@";
152           $dbh->do ('CREATE TABLE name_with_no_columns');   # a subtle syntax error
153           $dbh->do ('COMMIT');                              # followed by commit
154           $dbh->disconnect;
155       }
156
157       exit 0;
158   }
159   else {
160       eval {
161           local $SIG{ALRM} = sub { die "timeout\n" };
162           alarm 5;
163           wait();
164           alarm 0;
165       };
166       my $exception = $@;
167
168       my $sig = $? & 127;
169
170 # make sure process actually dies
171       $exception && kill POSIX::SIGKILL(), $pid;
172
173       if ($exception || $sig == POSIX::SIGSEGV() || $sig == POSIX::SIGABRT()
174         || $sig == 7) { # 7 == SIGBUS, haven't seen it but just in case
175           warn (<<EOE);
176
177 ############################### WARNING #################################
178 #                                                                       #
179 # You are running a buggy version of DBD::SQLite known to randomly      #
180 # segfault on errors.  Even if you have the latest CPAN module version, #
181 # the sqlite3 dynamic library on this system might have been compiled   #
182 # against an older buggy sqlite3 dev library (oddly DBD::SQLite will    #
183 # prefer the system library against the one bundled with it). You are   #
184 # strongly advised to resolve this issue before proceeding.             #
185 #                                                                       #
186 #########################################################################
187
188 EOE
189           my $ans = prompt (
190             "The test suite of this module is almost certain to fail.\n"
191             . 'Do you really want to continue?',
192             'no',
193           );
194           exit 0 unless ($ans =~ /^y(es)?$/i);
195       }
196   }
197 }
198
199
200 WriteAll();
201
202
203 if ($Module::Install::AUTHOR) {
204   # Need to do this _after_ WriteAll else it loses track of them
205   Meta->{values}{build_requires} = [ grep {
206     my $ok = 1;
207     foreach my $module (keys %force_requires_if_author) {
208       if ($_->[0] =~ /$module/) {
209         $ok = 0;
210         last;
211       }
212     }
213     $ok;
214   } @{Meta->{values}{build_requires}} ];
215
216   my @scalar_keys = Module::Install::Metadata::Meta_TupleKeys();
217   my $cr = Module::Install::Metadata->can("Meta_TupleKeys");
218   {
219     no warnings 'redefine';
220     *Module::Install::Metadata::Meta_TupleKeys = sub {
221       return $cr->(@_), 'resources';
222     };
223   }
224   Meta->{values}{resources} = [ 
225     [ 'MailingList', 'http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class' ],
226     [ 'IRC', 'irc://irc.perl.org/#dbix-class' ],
227     [ 'license', 'http://dev.perl.org/licenses/' ],
228     [ 'repository', 'http://dev.catalyst.perl.org/svnweb/bast/browse/DBIx-Class/' ],
229   ];
230   Meta->write;
231 }
232