check a couple more signals during sqlite health check
[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 'Data::Page'                => 2.00;
13 requires 'Scalar::Util'              => 0;
14 requires 'SQL::Abstract'             => 1.24;
15 requires 'SQL::Abstract::Limit'      => 0.13;
16 requires 'Class::C3'                 => 0.20;
17 requires 'Class::C3::Componentised'  => 0;
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.08002;
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 'namespace::clean'          => 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 'DBD::SQLite'         => 1.14;
35
36 test_requires 'Test::Builder'       => 0.33;
37 test_requires 'Test::Warn'          => 0.11;
38 test_requires 'Test::Exception'     => 0;
39 test_requires 'Test::Deep'          => 0;
40
41 install_script 'script/dbicadmin';
42
43 tests_recursive 't';
44
45 # re-build README and require CDBI modules for testing if we're in a checkout
46
47 my @force_build_requires_if_author = qw(
48   DBIx::ContextualFetch
49   Class::Trigger
50   Time::Piece
51   Clone
52   Test::Pod::Coverage
53   Test::Memory::Cycle
54 );
55
56 if ($Module::Install::AUTHOR) {
57
58   foreach my $module (@force_build_requires_if_author) {
59     build_requires $module;
60   }
61
62   system('pod2text lib/DBIx/Class.pm > README');
63 }
64
65 auto_provides;
66
67 auto_install;
68
69 # Have all prerequisites, check DBD::SQLite sanity
70 if (! $ENV{DBICTEST_NO_SQLITE_CHECK} ) {
71
72   my $pid = fork();
73   if (not defined $pid) {
74       die "Unable to fork(): $!";
75   }
76   elsif (! $pid) {
77
78       # Win32 does not have real fork()s so a segfault will bring
79       # everything down. Warn about it.
80       if ($^O eq 'MSWin32') {
81         print <<'EOW';
82
83 ######################################################################
84 #                                                                    #
85 # A short stress-testing of DBD::SQLite will follow. If you have a   #
86 # buggy library this might very well be the last text you will see   #
87 # before the installation silently terminates. If this happens it    #
88 # would mean that you are running a buggy version of DBD::SQLite     #
89 # known to randomly segfault on errors. Even if you have the latest  #
90 # CPAN module version, the system sqlite3 dynamic library might have #
91 # been compiled against an older buggy sqlite3 dev library (oddly    #
92 # DBD::SQLite will prefer the system library against the one bundled #
93 # with it). You are strongly advised to resolve this issue before    #
94 # proceeding.                                                        #
95 #                                                                    #
96 # If this happens to you (this text is the last thing you see), and  #
97 # you just want to install this module without worrying about the    #
98 # tests (which will almost certainly fail) - set the environment     #
99 # variable DBICTEST_NO_SQLITE_CHECK to a true value and try again.   #
100 #                                                                    #
101 ######################################################################
102
103 EOW
104       }
105
106       require DBI;
107       for (1 .. 100) {
108           my $dbh;
109           $dbh = DBI->connect ('dbi:SQLite::memory:', undef, undef, {
110               AutoCommit => 1,
111               RaiseError => 0,
112               PrintError => 0,
113           })
114               or die "Unable to connect to database: $@";
115           $dbh->do ('CREATE TABLE name_with_no_columns');   # a subtle syntax error
116           $dbh->do ('COMMIT');                              # followed by commit
117           $dbh->disconnect;
118       }
119
120       exit 0;
121   }
122   else {
123       eval {
124           local $SIG{ALRM} = sub { die "timeout\n" };
125           alarm 5;
126           wait();
127           alarm 0;
128       };
129       my $sig = $? & 127;
130       if ($@ || $sig == POSIX::SIGSEGV() || $sig == POSIX::SIGABRT()
131         || $sig == 7) {
132           warn (<<EOE);
133
134 ############################### WARNING #################################
135 #                                                                       #
136 # You are running a buggy version of DBD::SQLite known to randomly      #
137 # segfault on errors.  Even if you have the latest CPAN module version, #
138 # the sqlite3 dynamic library on this system might have been compiled   #
139 # against an older buggy sqlite3 dev library (oddly DBD::SQLite will    #
140 # prefer the system library against the one bundled with it). You are   #
141 # strongly advised to resolve this issue before proceeding.             #
142 #                                                                       #
143 #########################################################################
144
145 EOE
146           my $ans = prompt (
147             "The test suite of this module is almost certain to fail.\n"
148             . 'Do you really want to continue?',
149             'no',
150           );
151           exit 0 unless ($ans =~ /^y(es)?$/i);
152       }
153   }
154 }
155
156
157 WriteAll();
158
159
160 if ($Module::Install::AUTHOR) {
161   # Need to do this _after_ WriteAll else it looses track of them
162   Meta->{values}{build_requires} = [ grep {
163     my $ok = 1;
164     foreach my $module (@force_build_requires_if_author) {
165       if ($_->[0] =~ /$module/) {
166         $ok = 0;
167         last;
168       }
169     }
170     $ok;
171   } @{Meta->{values}{build_requires}} ];
172
173   my @scalar_keys = Module::Install::Metadata::Meta_TupleKeys();
174   my $cr = Module::Install::Metadata->can("Meta_TupleKeys");
175   {
176     no warnings 'redefine';
177     *Module::Install::Metadata::Meta_TupleKeys = sub {
178       return $cr->(@_), 'resources';
179     };
180   }
181   Meta->{values}{resources} = [ 
182     [ 'MailingList', 'http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class' ],
183     [ 'IRC', 'irc://irc.perl.org/#dbix-class' ],
184     [ 'license', 'http://dev.perl.org/licenses/' ],
185     [ 'repository', 'http://dev.catalyst.perl.org/svnweb/bast/browse/DBIx-Class/' ],
186   ];
187   Meta->write;
188 }