1 package SL::LxOfficeConf;
 
   5 my $environment_initialized;
 
   8   my ($class, $may_fail);
 
  31   my ($class, $file_name, $may_fail) = @_;
 
  33   return unless $class->safe_require($may_fail);
 
  35   read_config('config/lx_office.conf.default' => \%::lx_office_conf);
 
  36   _decode_recursively(\%::lx_office_conf);
 
  38   $file_name ||= 'config/lx_office.conf';
 
  41     read_config($file_name => \ my %local_conf);
 
  42     _decode_recursively(\%local_conf);
 
  43     _flat_merge(\%::lx_office_conf, \%local_conf);
 
  47   _determine_application_paths();
 
  52 sub _decode_recursively {
 
  55   while (my ($key, $value) = each %{ $obj }) {
 
  56     if (ref($value) eq 'HASH') {
 
  57       _decode_recursively($value);
 
  59       $obj->{$key} = decode('UTF-8', $value);
 
  67   while (my ($key, $value) = each %{ $src }) {
 
  68     if (!exists $dst->{$key}) {
 
  69       $dst->{$key} = $value;
 
  72       map { $dst->{$key}->{$_} = $value->{$_} } keys %{ $value };
 
  77 sub _init_environment {
 
  78   return if $environment_initialized;
 
  80   my %key_map = ( lib  => { name => 'PERL5LIB', append_path => 1 },
 
  81                   path => { name => 'PATH',     append_path => 1 },
 
  83   my $cfg     = $::lx_office_conf{environment} || {};
 
  85   while (my ($key, $value) = each %{ $cfg }) {
 
  88     my $info = $key_map{$key} || {};
 
  89     $key     = $info->{name}  || $key;
 
  91     if ($info->{append_path}) {
 
  92       $value = ':' . $value unless $value =~ m/^:/ || !$ENV{$key};
 
  93       $value = $ENV{$key} . $value if $ENV{$key};
 
  99   $environment_initialized = 1;
 
 102 sub _determine_application_paths {
 
 103   my @paths = grep { $_ } split m/:/, $ENV{PATH};
 
 105   foreach my $key (keys %{ $::lx_office_conf{applications} }) {
 
 106     my ($program) = split m/\s+/, $::lx_office_conf{applications}->{$key};
 
 107     next if $program =~ m|/|;
 
 109     foreach my $path (@paths) {
 
 110       next unless -f "${path}/${program}";
 
 111       $::lx_office_conf{applications}->{$key} = "${path}/" . $::lx_office_conf{applications}->{$key};