File: Makefile.PL

package info (click to toggle)
libdbix-password-perl 1.9-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 152 kB
  • sloc: perl: 152; makefile: 3
file content (189 lines) | stat: -rwxr-xr-x 4,675 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
180
181
182
183
184
185
186
187
188
189
use ExtUtils::MakeMaker;
use Data::Dumper;
use strict;

# Let's ask some questions

my $virtuals = {};
my $dumped;

#if (-e '.cache') {
if (0) {
	print "Oh, I can see that you have run me before, should I reuse these?(y or n)\n";
	my $answer  = getLine();
	if($answer eq 'y') {
		open(FILEHANDLE, "<.cache");
		my @file = <FILEHANDLE>;
		$dumped = join ('', @file);
		goto JUMPOINT;
	}
}

my %driver_methods = (
		'mysql' => \&createMySQL,
		'Pg' => \&createPostgreSQL,
);

print "What is the name of the Virtual User?\n";
#my $virtual  = getLine();
my $virtual;
while ($virtual) {
	print "What is the dbi driver? (AKA mysql)\n";
	my $driver  = getLine();
	if($driver_methods{$driver}) {
		$driver_methods{$driver}->($virtual, $driver);
	} else {
		print "Unsupported driver, send mail to brian\@tangent.org about supporting it. \n";
		print "For now we will let you just enter the connect string by hand. \n";
		createDefault($driver);
	}
	$virtual = undef;
	print "What is the name of the Virtual User?\n";
	print "(Enter nothing if you are finished adding users.)\n";
	$virtual  = getLine();
}

#Now, lets build up our data structure
my $data = Data::Dumper->new([$virtuals]);
$data->Purity(1);
$data->Indent(3);
$data->Varname('virtual');
$dumped = $data->Dump();
JUMPOINT:
makeFile();
makeTest();
makeCache();

#Now, lets grab the version
open (FILEHANDLE, "VERSION");
my $version = <FILEHANDLE>;
close (FILEHANDLE);
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
    'NAME'	=> 'DBIx::Password',
    'VERSION' => $version, # finds $VERSION
);

sub getLine {
	my $data = <STDIN>;
	chomp($data);
	return $data;
}

sub makeFile {
	return 0;
	open(FILEHANDLE, "Password.pm-orig"); 
	my @file = <FILEHANDLE>;
	close (FILEHANDLE);
	open(FILEHANDLE, ">Password.pm"); 
	for (@file) {
		chomp($_);
		if(/#PASSWORD_INSERT/) {
			print FILEHANDLE ("my $dumped\n");
		} else {
			print FILEHANDLE ("$_\n");
		}
	}
	close (FILEHANDLE);
}

sub makeTest {
	open(FILEHANDLE, "test.pl-orig"); 
	my @file = <FILEHANDLE>;
	close (FILEHANDLE);
	open(FILEHANDLE, ">test.pl"); 
	for (@file) {
		chomp($_);
		if(/#PASSWORD_INSERT/) {
			print FILEHANDLE ("my $dumped\n");
		} else {
			print FILEHANDLE ("$_\n");
		}
	}
	close (FILEHANDLE);
}

sub makeCache {
	open(FILEHANDLE, ">.cache"); 
	print FILEHANDLE $dumped;
	close (FILEHANDLE);
}

sub createMySQL {
	my %attributes;
	my $driver = 'mysql';
	print "What is the name of the database?\n";
	my $database  = getLine();
	print "What is the name of the machine that the database is on?\n";
	my $hostname  = getLine();
	my $connect = "DBI:$driver:database=$database;host=$hostname";
	print "Is the database on any special port(you should probably just hit return)?\n";
	my $port  = getLine();
	$connect .= ";port=$port" if $port;
	print "What is the username?\n";
	my $username  = getLine();
	print "What is the password?\n";
	my $password  = getLine();
	print "What attributes would you like to add?\n";
	print "(Enter nothing to skip or finish)\n";
	my $attr  = getLine();
	while($attr) {
		print "What is the value of the attribute?\n";
		my $value  = getLine();
		$attributes{$attr} = $value;
		print "What attributes would you like to add?\n";
		print "(Enter nothing to skip or finish)\n";
		$attr  = getLine();
	}
	$virtuals->{$virtual} = {
			connect => $connect,
			driver => $driver,
			database => $database,
			host => $hostname,
			port => $port,
			username => $username,
			password => $password,
			attributes => \%attributes
			};
}
sub createPostgreSQL {
	my $driver = 'Pg';
	print "What is the name of the database?\n";
	my $database  = getLine();
	print "What is the name of the machine that the database is on?\n";
	my $hostname  = getLine();
	my $connect = "DBI:$driver:dbname=$database;host=$hostname";
	print "Is the database on any special port(you should probably just hit return)?\n";
	my $port  = getLine();
	$connect .= ";port=$port" if $port; 
	print "What is the username?\n";
	my $username  = getLine();
	print "What is the password?\n";
	my $password  = getLine();
	$virtuals->{$virtual} = {
			connect => $connect,
			driver => $driver,
			database => $database,
			host => $hostname,
			port => $port,
			username => $username,
			password => $password,
			};
}

sub createDefault{
	my ($driver) = @_;
	print "What is the connect string?\n";
	my $connect  = getLine();
	print "What is the username?\n";
	my $username  = getLine();
	print "What is the password?\n";
	my $password  = getLine();
	$virtuals->{$virtual} = {
			connect => $connect,
			driver => $driver,
			username => $username,
			password => $password,
			};
}