X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FLxOfficeConf.pm;h=4e26c4e25335f1587c53be56d5b91ddaa087fab6;hb=1fd3b7370bb8d9000229b34b989f5e2eacbebf04;hp=c1331867729d51ef0406e3b9fec0a71371a4b48f;hpb=5aaa3c621371557ed9fde80ef6a07e2b7959c0cb;p=kivitendo-erp.git diff --git a/SL/LxOfficeConf.pm b/SL/LxOfficeConf.pm index c13318677..4e26c4e25 100644 --- a/SL/LxOfficeConf.pm +++ b/SL/LxOfficeConf.pm @@ -2,27 +2,52 @@ package SL::LxOfficeConf; use strict; -use Config::Std; use Encode; my $environment_initialized; +sub safe_require { + my ($class, $may_fail); + + my $failed = !eval { require Config::Std; }; + + if ($failed) { + if ($may_fail) { + warn $@; + return 0; + } else { + die $@; + } + } + + Config::Std->import; + + return 1; +} + sub read { - my ($class, $file_name) = @_; + my ($class, $file_name, $may_fail) = @_; - read_config 'config/lx_office.conf.default' => %::lx_office_conf; + return unless $class->safe_require($may_fail); + + # Backwards compatibility: read lx_office.conf.default if + # kivitendo.conf.default does't exist. + my $default_config = -f "config/kivitendo.conf.default" ? 'kivitendo' : 'lx_office'; + read_config("config/${default_config}.conf.default" => \%::lx_office_conf); _decode_recursively(\%::lx_office_conf); - $file_name ||= 'config/lx_office.conf'; + $file_name ||= -f 'config/kivitendo.conf' ? 'config/kivitendo.conf' : 'config/lx_office.conf'; if (-f $file_name) { - read_config $file_name => my %local_conf; + read_config($file_name => \ my %local_conf); _decode_recursively(\%local_conf); _flat_merge(\%::lx_office_conf, \%local_conf); } _init_environment(); _determine_application_paths(); + + return 1; } sub _decode_recursively { @@ -66,7 +91,7 @@ sub _init_environment { if ($info->{append_path}) { $value = ':' . $value unless $value =~ m/^:/ || !$ENV{$key}; - $value = $ENV{$key} . $value; + $value = $ENV{$key} . $value if $ENV{$key}; } $ENV{$key} = $value;