One more cdbi-compat author req
[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.49;
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
30 # Perl 5.8.0 doesn't have utf8::is_utf8()
31 requires 'Encode'                   => 0 if ($] <= 5.008000);  
32
33 # configure_requires so the sanity check below can run
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 recommends 'SQL::Translator'        => 0.09004;
42
43 install_script 'script/dbicadmin';
44
45 tests_recursive 't';
46
47 # re-build README and require extra modules for testing if we're in a checkout
48
49 my %force_requires_if_author = (
50   'Test::Pod::Coverage'       => 1.04,
51   'SQL::Translator'           => 0.09004,
52
53   # CDBI-compat related
54   'DBIx::ContextualFetch'     => 0,
55   'Class::DBI::Plugin::DeepAbstractSearch' => 0,
56   'Class::Trigger'            => 0,
57   'Time::Piece'               => 0,
58   'Clone'                     => 0,
59
60   # t/52cycle.t
61   'Test::Memory::Cycle'       => 0,
62
63   # t/60core.t
64   'DateTime::Format::MySQL'   => 0,
65
66   # t/93storage_replication.t
67   'Moose',                    => 0,
68   'MooseX::AttributeHelpers'  => 0.12,
69
70   # t/96_is_deteministic_value.t
71   'DateTime::Format::Strptime' => 0,
72 );
73
74 if ($Module::Install::AUTHOR) {
75
76   foreach my $module (keys %force_requires_if_author) {
77     requires ($module => $force_requires_if_author{$module});
78   }
79
80   system('pod2text lib/DBIx/Class.pm > README');
81 }
82
83 auto_provides;
84
85 auto_install;
86
87 # Have all prerequisites, check DBD::SQLite sanity
88 if (! $ENV{DBICTEST_NO_SQLITE_CHECK} ) {
89
90   my $pid = fork();
91   if (not defined $pid) {
92       die "Unable to fork(): $!";
93   }
94   elsif (! $pid) {
95
96       # Win32 does not have real fork()s so a segfault will bring
97       # everything down. Warn about it.
98       if ($^O eq 'MSWin32') {
99         print <<'EOW';
100
101 ######################################################################
102 #                                                                    #
103 # A short stress-testing of DBD::SQLite will follow. If you have a   #
104 # buggy library this might very well be the last text you will see   #
105 # before the installation silently terminates. If this happens it    #
106 # would mean that you are running a buggy version of DBD::SQLite     #
107 # known to randomly segfault on errors. Even if you have the latest  #
108 # CPAN module version, the system sqlite3 dynamic library might have #
109 # been compiled against an older buggy sqlite3 dev library (oddly    #
110 # DBD::SQLite will prefer the system library against the one bundled #
111 # with it). You are strongly advised to resolve this issue before    #
112 # proceeding.                                                        #
113 #                                                                    #
114 # If this happens to you (this text is the last thing you see), and  #
115 # you just want to install this module without worrying about the    #
116 # tests (which will almost certainly fail) - set the environment     #
117 # variable DBICTEST_NO_SQLITE_CHECK to a true value and try again.   #
118 #                                                                    #
119 ######################################################################
120
121 EOW
122       }
123
124       require DBI;
125       for (1 .. 100) {
126           my $dbh;
127           $dbh = DBI->connect ('dbi:SQLite::memory:', undef, undef, {
128               AutoCommit => 1,
129               RaiseError => 0,
130               PrintError => 0,
131           })
132               or die "Unable to connect to database: $@";
133           $dbh->do ('CREATE TABLE name_with_no_columns');   # a subtle syntax error
134           $dbh->do ('COMMIT');                              # followed by commit
135           $dbh->disconnect;
136       }
137
138       exit 0;
139   }
140   else {
141       eval {
142           local $SIG{ALRM} = sub { die "timeout\n" };
143           alarm 5;
144           wait();
145           alarm 0;
146       };
147       my $exception = $@;
148
149       my $sig = $? & 127;
150
151 # make sure process actually dies
152       $exception && kill POSIX::SIGKILL(), $pid;
153
154       if ($exception || $sig == POSIX::SIGSEGV() || $sig == POSIX::SIGABRT()
155         || $sig == 7) { # 7 == SIGBUS, haven't seen it but just in case
156           warn (<<EOE);
157
158 ############################### WARNING #################################
159 #                                                                       #
160 # You are running a buggy version of DBD::SQLite known to randomly      #
161 # segfault on errors.  Even if you have the latest CPAN module version, #
162 # the sqlite3 dynamic library on this system might have been compiled   #
163 # against an older buggy sqlite3 dev library (oddly DBD::SQLite will    #
164 # prefer the system library against the one bundled with it). You are   #
165 # strongly advised to resolve this issue before proceeding.             #
166 #                                                                       #
167 #########################################################################
168
169 EOE
170           my $ans = prompt (
171             "The test suite of this module is almost certain to fail.\n"
172             . 'Do you really want to continue?',
173             'no',
174           );
175           exit 0 unless ($ans =~ /^y(es)?$/i);
176       }
177   }
178 }
179
180
181 WriteAll();
182
183
184 if ($Module::Install::AUTHOR) {
185   # Need to do this _after_ WriteAll else it looses track of them
186   Meta->{values}{build_requires} = [ grep {
187     my $ok = 1;
188     foreach my $module (keys %force_requires_if_author) {
189       if ($_->[0] =~ /$module/) {
190         $ok = 0;
191         last;
192       }
193     }
194     $ok;
195   } @{Meta->{values}{build_requires}} ];
196
197   my @scalar_keys = Module::Install::Metadata::Meta_TupleKeys();
198   my $cr = Module::Install::Metadata->can("Meta_TupleKeys");
199   {
200     no warnings 'redefine';
201     *Module::Install::Metadata::Meta_TupleKeys = sub {
202       return $cr->(@_), 'resources';
203     };
204   }
205   Meta->{values}{resources} = [ 
206     [ 'MailingList', 'http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class' ],
207     [ 'IRC', 'irc://irc.perl.org/#dbix-class' ],
208     [ 'license', 'http://dev.perl.org/licenses/' ],
209     [ 'repository', 'http://dev.catalyst.perl.org/svnweb/bast/browse/DBIx-Class/' ],
210   ];
211   Meta->write;
212 }