use Config::General;
use File::Basename;
use Cwd qw( abs_path );
+use Data::Dumper;
+use Getopt::Long;
use DBI;
$| = 1;
+my $verbose = 0;
my $basename = basename($0);
$basename =~ s/\.pl$//i;
my $postfix_dir = abs_path( catfile( '', 'etc', 'postfix' ) );
-my $conf = abs_path( catfile( $postfix_dir, $basename . ".conf" ) );
+my $cfg_file = abs_path( catfile( $postfix_dir, $basename . ".conf" ) );
+
+GetOptions(
+ "verbose+" => \$verbose,
+ "conf-file|conf|c=s" => \$cfg_file,
+);
unless ( -d $postfix_dir ) {
- die "Verzeichnis '$postfix_dir' existiert nicht.\n";
+ fatal( "Verzeichnis '$postfix_dir' existiert nicht." );
+}
+
+fatal( "Datei '$cfg_file' existiert nicht." ) unless -f $cfg_file;
+my $config = read_config($cfg_file);
+
+
+
+
+#--------------------------------------------------------------------------------------
+
+=head2 read_config( $file )
+
+=cut
+
+sub read_config {
+
+ my $cfg_file = shift;
+
+ debug( 2, "Lese Config-Datei '" . $cfg_file . "' ..." );
+
+ my $config = {};
+
+ eval {
+ my $conf = new Config::General(
+ '-ConfigFile' => $cfg_file,
+ '-ApacheCompatible' => 1,
+ );
+ %$config = $conf->getall();
+ };
+ if ( $@ ) {
+ fatal( "Fehler beim Lesen der Konfigurationsdatei '" . $cfg_file . "': ", $@ );
+ }
+
+ debug( 2, "Gelesene Konfiguration: ", $config );
+
+ return $config;
}
-die "Datei '$conf' existiert nicht.\n" unless -f $conf;
+#--------------------------------------------------------------------------------------
+
+=head2 msg_line( $text1, [$text2, ... ] )
+
+=cut
+
+sub msg_line {
+
+ my $out = '';
+
+ for my $p ( @_ ) {
+ my $text = ' <undef>';
+ if ( defined $p ) {
+ if ( ref($p) ) {
+ {
+ local $Data::Dumper::Purity = 1;
+ local $Data::Dumper::Indent = 1;
+ local $Data::Dumper::Sortkeys = 1;
+ $text = Dumper($p);
+ $text =~ s/^\s*\$[a-zA-Z][a-zA-Z0-9]*\s*=\s*//;
+ }
+ }
+ else {
+ $text = $p;
+ }
+ }
+ $out .= $text;
+ }
+
+ $out =~ s/^\s+//;
+ $out =~ s/\s+$//;
+ return $out;
+}
+
+#--------------------------------------------------------------------------------------
+
+=head2 debug( $debug_level, $text1, [$text2, ... ] )
+
+=cut
+
+sub debug {
+
+ my $debug_level = shift;
+ return undef unless $verbose >= $debug_level;
+
+ my $out = msg_line(@_);
+
+ my @C0 = caller(0);
+ my @C1 = caller(1);
+ my $k = sprintf( "%s() Zeile %d: ", ( @C1 ? $C1[3] : 'main' ), $C0[2] );
+
+ warn $k . $out . "\n";
+
+}
+
+#--------------------------------------------------------------------------------------
+
+=head2 error( $error_level, $text1, [$text2, ... ] )
+
+=cut
+
+sub error {
+
+ my $error_level = shift;
+ my $out = msg_line(@_);
+
+ my @C0 = caller(0);
+ my @C1 = caller(1);
+ my $k = sprintf( "%s() Zeile %d %s: ", ( @C1 ? $C1[3] : 'main' ), $C0[2], $error_level );
+ $k = $error_level . ": " unless $verbose;
+
+ warn $k . $out . "\n";
+
+}
+
+#--------------------------------------------------------------------------------------
+
+=head2 notice( $text1, [$text2, ... ] )
+
+=cut
+
+sub notice {
+
+ my $out = msg_line(@_);
+
+ my @C0 = caller(0);
+ my @C1 = caller(1);
+ my $k = sprintf( "%s() Zeile %d: ", ( @C1 ? $C1[3] : 'main' ), $C0[2] );
+ $k = "" unless $verbose;
+
+ warn $k . $out . "\n";
+
+}
+
+#--------------------------------------------------------------------------------------
+
+=head2 fatal( $text1, [$text2, ... ] )
+
+=cut
+
+sub fatal {
+
+ my $out = msg_line(@_);
+
+ my @C0 = caller(0);
+ my @C1 = caller(1);
+ my $k = sprintf( "%s() Zeile %d: ", ( @C1 ? $C1[3] : 'main' ), $C0[2] );
+ $k = "" unless $verbose;
+
+ warn $k . $out . "\n";
+ exit 88;
+
+}
+#--------------------------------------------------------------------------------------
__END__