File: Makefile.PL

package info (click to toggle)
libdbix-sequence-perl 1.5-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 132 kB
  • sloc: perl: 294; makefile: 2
file content (179 lines) | stat: -rwxr-xr-x 5,210 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
use ExtUtils::MakeMaker;
use Data::Dumper;
use Getopt::Long;

# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.

my $config = {
	extended => 0,
};

my $options = {};
$options->{help} = \&usage;

Getopt::Long::GetOptions($options, "help", "extended_tests", "rootpw=s", "rootuser=s", "oracle_home=s", "state_table=s", "release_table=s", "dsn=s",);

if (-e 't/config.pl')
{
	unlink 't/config.pl';
}

if ($options->{extended_tests})
{
	$config->{extended} = 1;

	eval "use DBI";
	if ($@)
	{
		die "DBI has to be installed in order to install DBIx::Sequence. ($@)\n";
	}

	$config->{dsn}           = $options->{dsn};
	$config->{root}          = $options->{rootuser} || 'root';
	$config->{rootpw}        = $options->{rootpw};
	$config->{user}		 	= $config->{root};
	$config->{userpw} 		= $config->{rootpw};
	$config->{oracle_home}   = $options->{oracle_home};
	$config->{state_table}   = $options->{state_table} || 'dbix_sequence_state';
	$config->{release_table} = $options->{release_table} || 'dbix_sequence_release';

	die "You need to specify a DSN to run extended tests" if not defined $config->{dsn};
	die "You need to specify a user to run extended tests" if not defined $config->{root};

	if ($config->{dsn} =~ /Oracle/ && !$ENV{'ORACLE_HOME'})
	{
		$ENV{'ORACLE_HOME'} = $config->{oracle_home};
	}
	my $dbh = DBI->connect(
	  $config->{dsn}, $config->{root}, $config->{rootpw}, {
		  RaiseError => 0,
		  Warn       => 0,
		  PrintError => 1,
	  }) || &creve("Could not establish a connection to DSN $dsn: $DBI::errstr");

	print "\n\nConnected.\n";
	&creve("User requested to stop.") if (ask("

###########################################################################
#			       WARNING!
###########################################################################
Extended tests require the creation of dbix_sequence_state and dbix_sequence_release tables.
These tables will be dropped (if they exists) and created for the test.

If you have any data to keep in these tables rerun 'perl Makefile.PL' with :
--state_table='state_table_name' 
--release_table='release_table_name'

Do you wish to continue ? (y|n)
  		") =~ /n|no/i);

	if ($config->{dsn} =~ /Oracle/)
	{
		$dbh->do("drop table " . $config->{state_table});
		$dbh->do("drop table " . $config->{release_table});
		print "Using ORACLE_HOME: $ENV{'ORACLE_HOME'}\n";

		$dbh->do("CREATE TABLE 
  				" . $config->{state_table} . " 
				(
					dataset varchar(50), 
					state_id NUMBER, 
					CONSTRAINT pk_dbix_sequence PRIMARY KEY (dataset, state_id)
				)
  				") || &creve("Failure in table creation: $DBI::errstr");

		print $config->{state_table} . " created.\n";
		$dbh->do("CREATE TABLE 
  					" . $config->{release_table} . " 
				(
					dataset varchar(50), 	
					released_id NUMBER, 
					CONSTRAINT pk_dbi_release PRIMARY KEY (dataset, released_id)
				)
  				") || &creve("Failure in table creation: $DBI::errstr");

		print $config->{release_table} . " created.\n";
	}
	else
	{
		$dbh->do("drop table " . $config->{state_table});
		$dbh->do("drop table " . $config->{release_table});
		$dbh->do("create table 
  					" . $config->{state_table} . " 
				(
					dataset varchar(50) NOT NULL, 
					state_id int(11) NOT NULL, PRIMARY KEY (dataset, state_id)
				)
  				") || &creve("Failure in table creation: $DBI::errstr");

		print $config->{state_table} . " created\n";
		$dbh->do("create table 
  					" . $config->{release_table} . " 
				(
					dataset varchar(50) NOT NULL, 
					released_id int(11) NOT NULL, PRIMARY KEY (dataset, released_id)
				)
  				") || &creve("Failure in table creation: $DBI::errstr");

		print $config->{release_table} . " created\n";
	}

	print "Generating t/config.pl\n";
	open(CONFIG, ">t/config.pl") || &creve("Could not write to t/config.pl");
	my $config_dump = Dumper $config;
	$config_dump =~ s/\$VAR1 \=//g;
	print CONFIG $config_dump;
	close CONFIG;
}

WriteMakefile(
  'NAME'         => 'DBIx::Sequence',
  'VERSION_FROM' => 'Sequence.pm',                               # finds $VERSION
  'AUTHOR'       => 'Benoit Beausejour <bbeausej\@pobox.com>',
  'clean'        => { 'FILES' => 'pod2html*', },
  'dist'    => { 'PREOP' => 'pod2text Sequence.pm > README; pod2html Sequence.pm README.html', },
);
exit;

sub creve
{
	my $msg = shift;
	print STDERR $msg . "\n";
	WriteMakefile(
	  'NAME'         => 'DBIx::Sequence',
	  'VERSION_FROM' => 'Sequence.pm',
	  'dist'    => { 'PREOP' => 'pod2text Sequence.pm > README; pod2html Sequence.pm README.html', },
	);
	exit;
}

sub ask
{
	my $question = shift;
	my $cache    = shift;

	print "$question \n[$cache] ";
	my $answer = <STDIN>;
	chomp $answer;
	if (!$answer) {$answer = $cache;}
	return $answer;
}

sub usage
{
	print <<"EOF";
Usage: perl Makefile.PL
--help			Prints this text
--extended_tests	Will run extended tests
--dsn			DSN to use for the tests (dbi:driver:db;host=hostname)
--rootuser		User who has CREATE, DROP, INSERT, DELETE privileges on the dsn
--rootpw		User password
--state_table		State table name for the tests (If data present)
--release_table		Release table name for the tests (If data present)
--oracle_home		If using an Oracle DSN


EOF
	exit;
}