bd6963ab86aee873943af2cad1b7c20f77700f92
[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.53;
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.54,
81   'Moose::Util::TypeConstraints'  => 0.54,
82   'MooseX::AttributeHelpers'      => 0.12,
83   'Class::MOP'                    => 0.63,
84
85   # t/96_is_deteministic_value.t
86   'DateTime::Format::Strptime' => 0,
87 );
88
89 if ($Module::Install::AUTHOR) {
90
91   foreach my $module (keys %force_requires_if_author) {
92     build_requires ($module => $force_requires_if_author{$module});
93   }
94
95   system('pod2text lib/DBIx/Class.pm > README');
96 }
97
98 auto_provides;
99
100 if ($Module::Install::AUTHOR) {
101   warn <<'EOW';
102 ******************************************************************************
103 ******************************************************************************
104 ***                                                                        ***
105 *** AUTHOR MODE: all optional test dependencies converted to hard requires ***
106 ***                                                                        ***
107 ******************************************************************************
108 ******************************************************************************
109
110 EOW
111 }
112 auto_install;
113
114 # Have all prerequisites, check DBD::SQLite sanity
115 _check_sqlite() if (! $ENV{DBICTEST_NO_SQLITE_CHECK} );
116
117 WriteAll();
118
119 if ($Module::Install::AUTHOR) {
120   # Need to do this _after_ WriteAll else it loses track of them
121   Meta->{values}{build_requires} = [ grep {
122     my $ok = 1;
123     foreach my $module (keys %force_requires_if_author) {
124       if ($_->[0] =~ /$module/) {
125         $ok = 0;
126         last;
127       }
128     }
129     $ok;
130   } @{Meta->{values}{build_requires}} ];
131
132   Meta->{values}{resources} = [ 
133     [ 'MailingList', 'http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class' ],
134     [ 'IRC', 'irc://irc.perl.org/#dbix-class' ],
135     [ 'license', 'http://dev.perl.org/licenses/' ],
136     [ 'repository', 'http://dev.catalyst.perl.org/svnweb/bast/browse/DBIx-Class/' ],
137   ];
138   Meta->write;
139 }
140
141
142 # This is legacy code. Latest DBD::SQLite developments fixed all known bugs
143 # in this area. Remove before some arbitrary next version
144 sub _check_sqlite {
145
146   # Win32 does not have real fork()s so a segfault will bring
147   # everything down. Warn about it below, and don't try fork()
148   if ($^O ne 'MSWin32') {
149
150     my $pid = fork();
151     if (not defined $pid) {
152         die "Unable to fork(): $!";
153     }
154     elsif (! $pid) {
155       _torture_sqlite();
156       exit 0;
157     }
158     else {
159       eval {
160           local $SIG{ALRM} = sub { die "timeout\n" };
161           alarm 5;
162           wait();
163           alarm 0;
164       };
165       my $exception = $@;
166
167       my $sig = $? & 127;
168
169       # make sure process actually dies
170       $exception && kill POSIX::SIGKILL(), $pid;
171
172       if ($exception || $sig == POSIX::SIGSEGV() || $sig == POSIX::SIGABRT()
173         || $sig == 7) { # 7 == SIGBUS, haven't seen it but just in case
174           warn (<<EOE);
175
176 ############################### WARNING #################################
177 #                                                                       #
178 # You are running a buggy version of DBD::SQLite known to randomly      #
179 # segfault on errors.  Even if you have the latest CPAN module version, #
180 # the sqlite3 dynamic library on this system might have been compiled   #
181 # against an older buggy sqlite3 dev library (oddly DBD::SQLite will    #
182 # prefer the system library against the one bundled with it). You are   #
183 # strongly advised to resolve this issue before proceeding.             #
184 #                                                                       #
185 #########################################################################
186
187 EOE
188           my $ans = prompt (
189             "The test suite of this module is almost certain to fail.\n"
190             . 'Do you really want to continue?',
191             'no',
192           );
193           exit 0 unless ($ans =~ /^y(es)?$/i);
194       }
195     }
196   }
197
198   else {  # the win32 version
199
200     print <<'EOW';
201 ######################################################################
202 #                                                                    #
203 # A short stress-testing of DBD::SQLite will follow. If you have a   #
204 # buggy library this might very well be the last text you will see   #
205 # before the installation silently terminates. If this happens it    #
206 # would mean that you are running a buggy version of DBD::SQLite     #
207 # known to randomly segfault on errors. Even if you have the latest  #
208 # CPAN module version, the system sqlite3 dynamic library might have #
209 # been compiled against an older buggy sqlite3 dev library (oddly    #
210 # DBD::SQLite will prefer the system library against the one bundled #
211 # with it). You are strongly advised to resolve this issue before    #
212 # proceeding.                                                        #
213 #                                                                    #
214 # If this happens to you (this text is the last thing you see), and  #
215 # you just want to install this module without worrying about the    #
216 # tests (which will almost certainly fail) - set the environment     #
217 # variable DBICTEST_NO_SQLITE_CHECK to a true value and try again.   #
218 #                                                                    #
219 ######################################################################
220
221 EOW
222
223     _torture_sqlite();
224   }
225 }
226
227 sub _torture_sqlite {
228   require DBI;
229
230   for (1 .. 100) {
231     my $dbh = DBI->connect ('dbi:SQLite::memory:', undef, undef, {
232       AutoCommit => 1,
233       RaiseError => 0,
234       PrintError => 0,
235     }) or die "Unable to connect to database: $@";
236
237     $dbh->do ('CREATE TABLE name_with_no_columns');   # a subtle syntax error
238     $dbh->do ('COMMIT');                              # followed by commit
239     $dbh->disconnect;
240   }
241 }