File Coverage

blib/lib/Apache/Voodoo/Install/Config.pm
Criterion Covered Total %
statement 12 134 8.9
branch 0 42 0.0
condition 0 9 0.0
subroutine 4 18 22.2
pod 0 14 0.0
total 16 217 7.3


line stmt bran cond sub pod time code
1             ################################################################################
2             #
3             # Apache::Voodoo::Install::Config - Apache Voodoo global settings writer
4             #
5             # This object is used by Voodoo internally by "voodoo-control setconfig".
6             #
7             ################################################################################
8             package Apache::Voodoo::Install::Config;
9              
10             $VERSION = "3.0200";
11              
12 1     1   1808 use strict;
  1         2  
  1         43  
13 1     1   6 use warnings;
  1         1  
  1         61  
14              
15             # There doesn't seem to be another "user input prompt" mechanism installed
16             # by default other that this one. Seems kinda strange to have to use an
17             # object designed for make file creation for this...oh well.
18 1     1   7 use ExtUtils::MakeMaker qw{ prompt };
  1         3  
  1         93  
19 1     1   7 use Data::Dumper;
  1         3  
  1         2454  
20              
21             $Data::Dumper::Indent=1;
22             $Data::Dumper::Terse=1;
23             $Data::Dumper::Sortkeys=1;
24              
25             sub new {
26 0     0 0   my $class = shift;
27 0           my %params = @_;
28              
29 0           my $self = {};
30 0 0         if (defined($params{PREFIX})) {
31             # take whatever is supplied
32 0           foreach (keys %params) {
33 0           $self->{$_} = $params{$_};
34             }
35             }
36              
37 0           bless ($self,$class);
38              
39 0           return $self;
40             }
41              
42             sub do_config_setup {
43 0     0 0   my $self = shift;
44              
45             # get settings
46 0           $self->prefix();
47 0           $self->install_path();
48 0           $self->session_path();
49 0           $self->conf_path();
50 0           $self->updates_path();
51 0           $self->conf_file();
52 0           $self->tmpl_path();
53 0           $self->code_path();
54 0           $self->apache_uid();
55 0           $self->apache_gid();
56 0           $self->debug_dbd();
57 0           $self->debug_path();
58              
59 0 0         return if $self->{"pretend"};
60              
61             # save settings
62 0           my %cfg = %{$self};
  0            
63              
64 0   0       my $path = $INC{"Apache/Voodoo/MyConfig.pm"} || $INC{"Apache/Voodoo/Install/Config.pm"};
65 0           $path =~ s/Install\/Config.pm$/MyConfig\.pm/;
66              
67 0 0         open(OUT,">$path") || die "Can't write to $path: $!";
68              
69             # I had this as a print block, but it tripped up the cpan.org formatter
70 0           print OUT "################################################################################\n";
71 0           print OUT "#\n";
72 0           print OUT "# Installation specific settings for Apache Voodoo are stored here.\n";
73 0           print OUT "# Do not edit this file directly. Use the \"voodoo-control\" command instead.\n";
74 0           print OUT "#\n";
75 0           print OUT "################################################################################\n";
76 0           print OUT "package Apache::Voodoo::MyConfig;\n";
77 0           print OUT "\n";
78              
79 0           print OUT '$CONFIG = '. Dumper(\%cfg).";\n";
80              
81 0           print OUT "\n";
82 0           print OUT "1;\n";
83              
84 0           close(OUT);
85 0           print "\n\nSetting saved\n";
86             }
87              
88             sub prefix {
89 0     0 0   my $self = shift;
90              
91 0 0         unless ($self->{PREFIX}) {
92             # test some of the common apache install locations to come up with a sensible default.
93 0           foreach ("/data/apache","/usr/local/apache","/etc/apache/","/etc/apache2") {
94 0 0 0       if (-e $_ && -d $_) {
95 0           $self->{PREFIX} = $_;
96 0           last;
97             }
98             }
99             }
100              
101 0           while (1) {
102 0           my $ans = prompt("Apache Prefix Path",$self->{PREFIX});
103 0           $ans =~ s/\/$//;
104              
105 0 0 0       if (-e $ans && -d $ans) {
106 0           $self->{PREFIX} = $ans;
107 0           last;
108             }
109              
110 0           print "That directory doesn't exist. Please try again.\n";
111             }
112             }
113              
114             sub install_path {
115 0     0 0   my $self = shift;
116              
117 0 0         unless ($self->{INSTALL_PATH}) {
118 0           $self->{INSTALL_PATH} = $self->{PREFIX} . "/sites";
119             }
120              
121 0           $self->{INSTALL_PATH} = prompt("App Install Path",$self->{INSTALL_PATH});
122 0           $self->{INSTALL_PATH} =~ s/\/$//;
123             }
124              
125             sub session_path {
126 0     0 0   my $self = shift;
127              
128 0 0         unless ($self->{SESSION_PATH}) {
129 0           $self->{SESSION_PATH} = $self->{PREFIX} . "/session";
130             }
131              
132 0           $self->{SESSION_PATH} = prompt("Session Path",$self->{SESSION_PATH});
133 0           $self->{SESSION_PATH} =~ s/\/$//;
134             }
135              
136             sub conf_path {
137 0     0 0   my $self = shift;
138              
139 0 0         unless ($self->{CONF_PATH}) {
140 0           $self->{CONF_PATH} = "etc";
141             }
142              
143 0           $self->{CONF_PATH} = prompt("Config File Path (relative to App Install Path)",$self->{CONF_PATH});
144 0           $self->{CONF_PATH} =~ s/\/$//;
145             }
146              
147             sub conf_file {
148 0     0 0   my $self = shift;
149              
150 0 0         unless ($self->{CONF_FILE}) {
151 0           $self->{CONF_FILE} = "etc/voodoo.conf";
152             }
153              
154 0           $self->{CONF_FILE} = prompt("Config File Name (relative to App Install Path)",$self->{CONF_FILE});
155 0           $self->{CONF_FILE} =~ s/\/$//;
156             }
157              
158             sub updates_path {
159 0     0 0   my $self = shift;
160              
161 0 0         unless ($self->{UPDATES_PATH}) {
162 0           $self->{UPDATES_PATH} = "etc/updates";
163             }
164              
165 0           $self->{UPDATES_PATH} = prompt("Update File Path (relative to App Install Path)",$self->{UPDATES_PATH});
166 0           $self->{UPDATES_PATH} =~ s/\/$//;
167             }
168              
169             sub tmpl_path {
170 0     0 0   my $self = shift;
171              
172 0 0         unless ($self->{TMPL_PATH}) {
173 0           $self->{TMPL_PATH} = "html";
174             }
175              
176 0           $self->{TMPL_PATH} = prompt("Template File Path (relative to App Install Path)",$self->{TMPL_PATH});
177 0           $self->{TMPL_PATH} =~ s/\/$//;
178             }
179              
180             sub code_path {
181 0     0 0   my $self = shift;
182              
183 0 0         unless ($self->{CODE_PATH}) {
184 0           $self->{CODE_PATH} = "code";
185             }
186              
187 0           $self->{CODE_PATH} = prompt("Perl Module Path (relative to App Install Path)",$self->{CODE_PATH});
188 0           $self->{CODE_PATH} =~ s/\/$//;
189             }
190              
191             sub apache_uid {
192 0     0 0   my $self = shift;
193              
194 0           my $default = "apache";
195 0 0         if ($self->{'APACHE_UID'}) {
196 0           my $d = (getpwuid($self->{APACHE_UID}))[0];
197 0 0         $default = $d if ($d);
198             }
199              
200 0           while (1) {
201 0           my $apache = prompt("User that Apache runs as",$default);
202 0           my (undef,undef,$uid,undef) = getpwnam($apache);
203 0 0         if ($uid =~ /^\d+$/) {
204 0           $self->{'APACHE_UID'} = $uid;
205 0           last;
206             }
207 0           print "Can't find this user. Please try again.\n";
208             }
209             }
210              
211             sub apache_gid {
212 0     0 0   my $self = shift;
213              
214 0           my $default = "apache";
215 0 0         if ($self->{'APACHE_GID'}) {
216 0           my $d = (getgrgid($self->{APACHE_GID}))[0];
217 0 0         $default = $d if ($d);
218             }
219              
220 0           while (1) {
221 0           my $apache = prompt("Group that Apache runs as",$default);
222 0           my (undef,undef,undef,$gid) = getpwnam($apache);
223 0 0         if ($gid =~ /^\d+$/) {
224 0           $self->{'APACHE_GID'} = $gid;
225 0           last;
226             }
227 0           print "Can't find this group. Please try again.\n";
228             }
229             }
230              
231             sub debug_dbd {
232 0     0 0   my $self = shift;
233              
234 0 0         unless ($self->{DEBUG_DBD}) {
235 0           $self->{DEBUG_DBD} = ['dbi:SQLite:dbname=/tmp/apachevoodoo.db','',''];
236             }
237              
238 0           $self->{DEBUG_DBD}->[0] = prompt("Debug Database Connect", $self->{DEBUG_DBD}->[0]);
239 0           $self->{DEBUG_DBD}->[1] = prompt("Debug Database Username",$self->{DEBUG_DBD}->[1]);
240 0           $self->{DEBUG_DBD}->[2] = prompt("Debug Database Password",$self->{DEBUG_DBD}->[2]);
241             }
242              
243             sub debug_path {
244 0     0 0   my $self = shift;
245              
246 0 0         unless ($self->{DEBUG_PATH}) {
247 0           $self->{DEBUG_PATH} = "/debug";
248             }
249              
250 0           $self->{DEBUG_PATH} = prompt("URL Path to the debug handler",$self->{DEBUG_PATH});
251             }
252              
253             1;
254              
255             ################################################################################
256             # Copyright (c) 2005-2010 Steven Edwards (maverick@smurfbane.org).
257             # All rights reserved.
258             #
259             # You may use and distribute Apache::Voodoo under the terms described in the
260             # LICENSE file include in this package. The summary is it's a legalese version
261             # of the Artistic License :)
262             #
263             ################################################################################