+ my $module = shift;
+ eval("use $module;");
+ return !$@;
+}
+
+sub prompt_bool($$$) {
+ my ($interactive, $question, $default) = @_;
+ my $answer = prompt_string($interactive, $question, $default ? 'y' : 'n');
+ return $answer =~ /y/i;
+}
+
+sub prompt_dir($$$) {
+ my ($interactive, $question, $default) = @_;
+ my ($answer, $create) = (undef, 'y');
+ do {
+ $answer = rel2abs(prompt_string($interactive, $question, $default));
+ $create = prompt_bool($interactive && !-d $answer, "$answer does not exist. Create it?", 'y');
+ my $mkpath = eval {
+ mkpath($answer, 0, 0750);
+ return 1;
+ };
+ unless (defined $mkpath) {
+ print "Error: unable to create $answer!\n\n";
+ $create = 0;
+ }
+ } while (!$create);
+ return $answer;
+}
+
+sub prompt_string($$$) {
+ my ($interactive, $question, $default) = @_;
+ return $default unless $interactive;
+ print $question, "\n";
+ print "[\e[1;32m$default\e[0m] => ";
+ chomp(my $answer = <STDIN>);
+ print "\n";
+ return $answer ? $answer : $default;
+}
+
+sub get_cpu_count {
+ my $count = 1;
+ if ($^O =~ /bsd/) {
+ $count = `sysctl -n hw.ncpu`;
+ } elsif ($^O eq 'darwin') {
+ $count = `sysctl -n hw.activecpu`;
+ } elsif ($^O eq 'linux') {
+ $count = `getconf _NPROCESSORS_ONLN`;
+ } elsif ($^O eq 'solaris') {
+ $count = `psrinfo -p`;
+ }
+ chomp($count);
+ return $count;
+}
+
+sub promptstring($$$$$)
+{
+ my ($prompt, $configitem, $default, $package, $commandlineswitch) = @_;
+ my $var;
+ if (!$main::interactive)
+ {
+ my $opt_commandlineswitch;
+ GetOptions ("$commandlineswitch=s" => \$opt_commandlineswitch);
+ if (defined $opt_commandlineswitch)
+ {
+ print "\e[1;32m$opt_commandlineswitch\e[0m\n";
+ $var = $opt_commandlineswitch;
+ }
+ else
+ {
+ die "Could not detect $package! Please specify the $prompt via the command line option \e[1;32m--$commandlineswitch=\"/path/to/file\"\e[0m";
+ }
+ }
+ else
+ {
+ print "\nPlease enter the $prompt?\n";
+ print "[\e[1;32m$default\e[0m] -> ";
+ chomp($var = <STDIN>);
+ }