Apache-Voodoo

 view release on metacpan or  search on metacpan

lib/Apache/Voodoo/Install/Config.pm  view on Meta::CPAN

use warnings;

# There doesn't seem to be another "user input prompt" mechanism installed
# by default other that this one.  Seems kinda strange to have to use an
# object designed for make file creation for this...oh well.
use ExtUtils::MakeMaker qw{ prompt };
use Data::Dumper;

$Data::Dumper::Indent=1;
$Data::Dumper::Terse=1;
$Data::Dumper::Sortkeys=1;

sub new {
	my $class = shift;
	my %params = @_;

	my $self = {};
	if (defined($params{PREFIX})) {
		# take whatever is supplied
		foreach (keys %params) {
			$self->{$_} = $params{$_};
		}
	}

	bless ($self,$class);

	return $self;
}

sub do_config_setup {
	my $self = shift;

	# get settings
	$self->prefix();
	$self->install_path();
	$self->session_path();
	$self->conf_path();
	$self->updates_path();
	$self->conf_file();
	$self->tmpl_path();
	$self->code_path();
	$self->apache_uid();
	$self->apache_gid();
	$self->debug_dbd();
	$self->debug_path();

	return if $self->{"pretend"};

	# save settings
	my %cfg = %{$self};

	my $path = $INC{"Apache/Voodoo/MyConfig.pm"} || $INC{"Apache/Voodoo/Install/Config.pm"};
	$path =~ s/Install\/Config.pm$/MyConfig\.pm/;

	open(OUT,">$path") || die "Can't write to $path: $!";

	# I had this as a print block, but it tripped up the cpan.org formatter
	print OUT "################################################################################\n";
	print OUT "#\n";
	print OUT "# Installation specific settings for Apache Voodoo are stored here.\n";
	print OUT "# Do not edit this file directly.  Use the \"voodoo-control\" command instead.\n";
	print OUT "#\n";
	print OUT "################################################################################\n";
	print OUT "package Apache::Voodoo::MyConfig;\n";
	print OUT "\n";

	print OUT '$CONFIG = '. Dumper(\%cfg).";\n";

	print OUT "\n";
	print OUT "1;\n";

	close(OUT);
	print "\n\nSetting saved\n";
}

sub prefix {
	my $self = shift;

	unless ($self->{PREFIX}) {
		# test some of the common apache install locations to come up with a sensible default.
		foreach ("/data/apache","/usr/local/apache","/etc/apache/","/etc/apache2") {
			if (-e $_ && -d $_) {
				$self->{PREFIX} = $_;
				last;
			}
		}
	}

	while (1) {
		my $ans = prompt("Apache Prefix Path",$self->{PREFIX});
		$ans =~ s/\/$//;

		if (-e $ans && -d $ans) {
			$self->{PREFIX} = $ans;
			last;
		}

		print "That directory doesn't exist.  Please try again.\n";
	}
}

sub install_path {
	my $self = shift;

	unless ($self->{INSTALL_PATH}) {
		$self->{INSTALL_PATH} = $self->{PREFIX} . "/sites";
	}

	$self->{INSTALL_PATH} = prompt("App Install Path",$self->{INSTALL_PATH});
	$self->{INSTALL_PATH} =~ s/\/$//;
}

sub session_path {
	my $self = shift;

	unless ($self->{SESSION_PATH}) {
		$self->{SESSION_PATH} = $self->{PREFIX} . "/session";
	}

	$self->{SESSION_PATH} = prompt("Session Path",$self->{SESSION_PATH});
	$self->{SESSION_PATH} =~ s/\/$//;



( run in 1.535 second using v1.01-cache-2.11-cpan-39bf76dae61 )