minor replication changes - use a real hash merge, clarify master_read_weight, really...
[dbsrgits/DBIx-Class.git] / Makefile.PL
1 use inc::Module::Install 0.79;
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 # configure_requires so _check_sqlite() below can run
13 # remove once test deprecated
14 configure_requires 'DBD::SQLite';
15
16 requires 'DBD::SQLite'              => 1.23;
17 requires 'Data::Page'               => 2.00;
18 requires 'Scalar::Util'             => 0;
19 requires 'SQL::Abstract'            => 1.54;
20 requires 'SQL::Abstract::Limit'     => 0.13;
21 requires 'Class::C3::Componentised' => 1.0005;
22 requires 'Storable'                 => 0;
23 requires 'Carp::Clan'               => 0;
24 requires 'DBI'                      => 1.40;
25 requires 'Module::Find'             => 0;
26 requires 'Class::Inspector'         => 0;
27 requires 'Class::Accessor::Grouped' => 0.08003;
28 requires 'JSON::Any'                => 1.17;
29 requires 'Scope::Guard'             => 0.03;
30 requires 'Path::Class'              => 0;
31 requires 'List::Util'               => 1.19;
32 requires 'Sub::Name'                => 0.04;
33 requires 'MRO::Compat'              => 0.09;
34
35 # Perl 5.8.0 doesn't have utf8::is_utf8()
36 requires 'Encode'                   => 0 if ($] <= 5.008000);  
37
38 test_requires 'Test::Builder'       => 0.33;
39 test_requires 'Test::Warn'          => 0.11;
40 test_requires 'Test::Exception'     => 0;
41 test_requires 'Test::Deep'          => 0;
42
43 recommends 'SQL::Translator'        => 0.09004;
44
45 install_script (qw|
46     script/dbicadmin
47 |);
48
49 tests_recursive (qw|
50     t
51 |);
52
53 # re-build README and require extra modules for testing if we're in a checkout
54
55 my %force_requires_if_author = (
56   'Test::Pod::Coverage'       => 1.04,
57   'SQL::Translator'           => 0.09004,
58
59   # CDBI-compat related
60   'DBIx::ContextualFetch'     => 0,
61   'Class::DBI::Plugin::DeepAbstractSearch' => 0,
62   'Class::Trigger'            => 0,
63   'Time::Piece::MySQL'        => 0,
64   'Clone'                     => 0,
65   'Date::Simple'              => 0,
66
67   # t/52cycle.t
68   'Test::Memory::Cycle'       => 0,
69
70   # t/60core.t
71   'DateTime::Format::MySQL'   => 0,
72
73   # t/72pg.t
74   $ENV{DBICTEST_PG_DSN}
75     ? ('Sys::SigAction'=> 0)
76     : ()
77   ,
78
79   # t/93storage_replication.t
80   'Moose',                        => 0.77,
81   'MooseX::AttributeHelpers'      => 0.12,
82   'MooseX::Types',                => 0.10,
83   'namespace::clean'              => 0.11,
84   'Hash::Merge',                  => 0.11,
85
86   # t/96_is_deteministic_value.t
87   'DateTime::Format::Strptime' => 0,
88 );
89
90 if ($Module::Install::AUTHOR) {
91
92   foreach my $module (keys %force_requires_if_author) {
93     build_requires ($module => $force_requires_if_author{$module});
94   }
95
96   system('pod2text lib/DBIx/Class.pm > README');
97 }
98
99 auto_provides;
100
101 if ($Module::Install::AUTHOR) {
102   warn <<'EOW';
103 ******************************************************************************
104 ******************************************************************************
105 ***                                                                        ***
106 *** AUTHOR MODE: all optional test dependencies converted to hard requires ***
107 ***                                                                        ***
108 ******************************************************************************
109 ******************************************************************************
110
111 EOW
112 }
113 auto_install;
114
115 # Have all prerequisites, check DBD::SQLite sanity
116 _check_sqlite() if (! $ENV{DBICTEST_NO_SQLITE_CHECK} );
117
118 WriteAll();
119
120 if ($Module::Install::AUTHOR) {
121   # Need to do this _after_ WriteAll else it loses track of them
122   Meta->{values}{build_requires} = [ grep {
123     my $ok = 1;
124     foreach my $module (keys %force_requires_if_author) {
125       if ($_->[0] =~ /$module/) {
126         $ok = 0;
127         last;
128       }
129     }
130     $ok;
131   } @{Meta->{values}{build_requires}} ];
132
133   Meta->{values}{resources} = [ 
134     [ 'MailingList', 'http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class' ],
135     [ 'IRC', 'irc://irc.perl.org/#dbix-class' ],
136     [ 'license', 'http://dev.perl.org/licenses/' ],
137     [ 'repository', 'http://dev.catalyst.perl.org/svnweb/bast/browse/DBIx-Class/' ],
138   ];
139   Meta->write;
140 }
141
142
143 # This is legacy code. Latest DBD::SQLite developments fixed all known bugs
144 # in this area. Remove before some arbitrary next version
145 sub _check_sqlite {
146
147   # Win32 does not have real fork()s so a segfault will bring
148   # everything down. Warn about it below, and don't try fork()
149   if ($^O ne 'MSWin32') {
150
151     my $pid = fork();
152     if (not defined $pid) {
153         die "Unable to fork(): $!";
154     }
155     elsif (! $pid) {
156       _torture_sqlite();
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
195           exit 0 unless ($ans =~ /^y(es)?$/i);
196       }
197     }
198   }
199
200   else {  # the win32 version
201
202     print <<'EOW';
203 ######################################################################
204 #                                                                    #
205 # A short stress-testing of DBD::SQLite will follow. If you have a   #
206 # buggy library this might very well be the last text you will see   #
207 # before the installation silently terminates. If this happens it    #
208 # would mean that you are running a buggy version of DBD::SQLite     #
209 # known to randomly segfault on errors. Even if you have the latest  #
210 # CPAN module version, the system sqlite3 dynamic library might have #
211 # been compiled against an older buggy sqlite3 dev library (oddly    #
212 # DBD::SQLite will prefer the system library against the one bundled #
213 # with it). You are strongly advised to resolve this issue before    #
214 # proceeding.                                                        #
215 #                                                                    #
216 # If this happens to you (this text is the last thing you see), and  #
217 # you just want to install this module without worrying about the    #
218 # tests (which will almost certainly fail) - set the environment     #
219 # variable DBICTEST_NO_SQLITE_CHECK to a true value and try again.   #
220 #                                                                    #
221 ######################################################################
222
223 EOW
224
225     _torture_sqlite();
226   }
227 }
228
229 sub _torture_sqlite {
230   require DBI;
231
232   for (1 .. 100) {
233     my $dbh = DBI->connect ('dbi:SQLite::memory:', undef, undef, {
234       AutoCommit => 1,
235       RaiseError => 0,
236       PrintError => 0,
237     }) or die "Unable to connect to database: $@";
238
239     $dbh->do ('CREATE TABLE name_with_no_columns');   # a subtle syntax error
240     $dbh->do ('COMMIT');                              # followed by commit
241     $dbh->disconnect;
242   }
243 }