1use strict;
2
3use ExtUtils::MakeMaker;
4
5my %required =
6    (
7     'Set::Object' => 1.10,
8     "Test::More" => 0,
9     #"Date::Manip" => 0,
10     "Time::Piece" => 0,
11     "Class::Date" => 0,
12     #"DateTime" => 0,
13     "Scalar::Util" => 1.14,
14     "Data::Lazy" => 0.6,
15     DBI => 0,
16    );
17
18my %required_soft = map{$_=>1} qw( Class::Accessor::Assert Class::Tangram Class::Tangram::Generator YAML Time::Piece Class::Date );
19my %required_hard = map{$_=>1} qw( Set::Object Scalar::Util  DBI Data::Lazy );
20
21my ($skip_tests, $bomb_out);
22while (my ($module, $min_ver) = each %required) {
23
24    my $mod_ver = "$module".($min_ver ? " $min_ver" : "");
25    eval "use $mod_ver;";
26    if($@) {
27	if (exists $required_hard{$module}) {
28	    $bomb_out = 1;
29	    print STDERR ("$mod_ver not found.\n");
30	} elsif ( exists $required_soft{$module} ) {
31	    print STDERR ("$mod_ver not found.  Some tests and/or "
32			  ."functionality may be missing.\n");
33	} else {
34	    $skip_tests = 1;
35	    print STDERR ("$mod_ver not found.  You will not be able "
36			  ."to run the test suite.\n");
37	}
38    }
39}
40
41do { $skip_tests = 1; goto NOTESTS } if $skip_tests or $bomb_out;
42
43use lib '.';
44
45sub yes
46{
47    print ' (Y/n) ';
48    return <STDIN> =~ /^(Y(e(s)?)?|A(YE|II+!*))?\n?$/i;
49}
50
51sub yeah_no  # it's an antipodean thing
52{
53    print ' (N/y) ';
54    return <STDIN> =~ /^(Y(e(s)?)?|A(YE|II+!*))\n?$/i;
55
56}
57
58print q{Do you plan to run the test suite?
59(you will need to set up an *EMPTY* database)};
60
61do { $skip_tests = 1; goto NOTESTS };
62
63my $configured;
64
65if ($ENV{TANGRAM_CONFIG})
66{
67   print qq{
68You have set TANGRAM_CONFIG to $ENV{TANGRAM_CONFIG}.
69Should I use it?};
70   $configured = yes();
71   unless ($ENV{TANGRAM_CONFIG} eq "t/CONFIG") {
72      open TCONF, "$ENV{TANGRAM_CONFIG}"
73	  or die "failed to open $ENV{TANGRAM_CONFIG} for reading; $!";
74      unlink "t/CONFIG";
75      open CONFIG, ">t/CONFIG"
76	  or die "failed to open t/CONFIG for writing; $!";
77      while (<TCONF>) { print CONFIG }
78      close TCONF;
79      close CONFIG;
80   }
81}
82
83if (!$configured && -e 't/CONFIG')
84{
85   print q{
86It looks like there is a 't/CONFIG' file already. It probably contains
87connection information from a previous installation. Should I use it?};
88   $configured = yes();
89}
90
91unless ($configured)
92{
93   print q{
94Please give me the login and password for accessing the test database.
95I must be able to create and drop tables in that database.};
96
97   print "\n1) DBI connect string (omit the \'DBI:\' part): ";
98   my $cs = <STDIN>;
99   chop $cs;
100
101   $cs = "dbi:$cs" unless $cs =~ /^dbi\:/i;
102
103   my ($use_tx, $use_subsel, $table_type) = (1, 1);
104
105   if ($cs =~ m/:mysql:/i) {
106       print q{
107You have selected the MySQL back-end.  Normally, subselects and
108transactions are disabled for this database.  However, if you are
109using MySQL-Max, or some other MySQL version with InnoDB support
110compiled in and configured, you can enable the transaction support for
111the test suite.  If you want to use it in your programs, you'll have
112to set no_tx = 0 in the options to Tangram::Storage->connect() (or
113hope that the auto-detection of the feature works), and table_type =
114InnoDB in the Schema.  See Tangram::Schema and Tangram::Storage for
115more information.
116
117Alternatively, if you are running MySQL 4.1 or later, you can enable
118sub-select tests.  It is not possible to use sub-selects with InnoDB
119table types.
120
121Use InnoDB tables};
122       unless (yeah_no()) {
123	   $use_tx = 0;
124
125	   print "Use sub-selects";
126	   unless (yeah_no()) {
127	       $use_subsel = 0;
128	   }
129       } else {
130	   $table_type = "InnoDB";
131       }
132   }
133
134   my ($user, $passwd);
135   if ( $cs =~ /:sqlite:/i ) {
136       print q{
137You have selected the SQLite back-end.  Sub-selects will be disabled.
138};
139       $use_subsel = 0;
140       $user = $passwd = "";
141   } else {
142
143       print "2) Login: ";
144       $user = <STDIN>;
145       chop $user;
146
147       print "3) Password: ";
148       $passwd = <STDIN>;
149       chop $passwd;
150
151   }
152
153   print <<'MSG';
154
155Thank you. I am going to save this information to 't/CONFIG'.
156If you have given me sensitive information, make sure to destroy
157the file when the tests have been completed.
158MSG
159
160   open CONFIG, '>t/CONFIG' or die "Cannot create 't/CONFIG', reason: $!";
161   print CONFIG "$cs\n$user\n$passwd\ntx_do = $use_tx\nsubselects = $use_subsel\n".($table_type?"table_type = $table_type\n":"");
162   close CONFIG;
163}
164
165NOTESTS:
166my $tests;
167if ( $skip_tests ) {
168    print "TEST SUITE IS DISABLED\n";
169    $tests = "t/no_tests.t";
170} else {
171    eval "use Test::Manifest";
172
173
174    if ( $@ ) {
175	open TESTS, "<t/test_manifest" or die $!;
176	$tests = join " ", map { chomp; "t/$_" } <TESTS>;
177	close TESTS;
178    }
179
180    else {
181	* ExtUtils::MM_Any::test_via_harness = sub
182	    {
183		my($self, $perl, $tests) = @_;
184
185		return (qq|\t$perl "-MTest::Manifest" | .
186			qq|"-e" "run_t_manifest(\$(TEST_VERBOSE), |.
187			qq|'\$(INST_LIB)', | .
188			qq|'\$(INST_ARCHLIB)')"\n|);
189	    };
190    }
191}
192
193# all this ... just to skip delivering one file!
194use File::Find;
195my %PM;
196find(sub {
197       m/\.(pod|pm)$/ && do {
198	 my $src = $File::Find::name;
199	 (my $targ = $src) =~ s{lib}{\$(INST_LIBDIR)};
200         ($PM{$src} = $targ);
201       };
202    }, "lib");
203
204WriteMakefile(
205	      'NAME'	=> 'Tangram',
206	      'VERSION_FROM' => 'lib/Tangram.pm', # finds $VERSION
207	      PREREQ_PM => \%required,
208	      PM => \%PM,
209	      test => { TESTS => $tests },
210);
211