1 package SL::LxOfficeConf;
 
   8 my $environment_initialized;
 
  11   my ($class, $file_name) = @_;
 
  13   read_config 'config/lx_office.conf.default' => %::lx_office_conf;
 
  14   _decode_recursively(\%::lx_office_conf);
 
  16   $file_name ||= 'config/lx_office.conf';
 
  19     read_config $file_name => my %local_conf;
 
  20     _decode_recursively(\%local_conf);
 
  21     _flat_merge(\%::lx_office_conf, \%local_conf);
 
  25   _determine_application_paths();
 
  28 sub _decode_recursively {
 
  31   while (my ($key, $value) = each %{ $obj }) {
 
  32     if (ref($value) eq 'HASH') {
 
  33       _decode_recursively($value);
 
  35       $obj->{$key} = decode('UTF-8', $value);
 
  43   while (my ($key, $value) = each %{ $src }) {
 
  44     if (!exists $dst->{$key}) {
 
  45       $dst->{$key} = $value;
 
  48       map { $dst->{$key}->{$_} = $value->{$_} } keys %{ $value };
 
  53 sub _init_environment {
 
  54   return if $environment_initialized;
 
  56   my %key_map = ( lib  => { name => 'PERL5LIB', append_path => 1 },
 
  57                   path => { name => 'PATH',     append_path => 1 },
 
  59   my $cfg     = $::lx_office_conf{environment} || {};
 
  61   while (my ($key, $value) = each %{ $cfg }) {
 
  64     my $info = $key_map{$key} || {};
 
  65     $key     = $info->{name}  || $key;
 
  67     if ($info->{append_path}) {
 
  68       $value = ':' . $value unless $value =~ m/^:/ || !$ENV{$key};
 
  69       $value = $ENV{$key} . $value if $ENV{$key};
 
  75   $environment_initialized = 1;
 
  78 sub _determine_application_paths {
 
  79   my @paths = grep { $_ } split m/:/, $ENV{PATH};
 
  81   foreach my $key (keys %{ $::lx_office_conf{applications} }) {
 
  82     my ($program) = split m/\s+/, $::lx_office_conf{applications}->{$key};
 
  83     next if $program =~ m|/|;
 
  85     foreach my $path (@paths) {
 
  86       next unless -f "${path}/${program}";
 
  87       $::lx_office_conf{applications}->{$key} = "${path}/" . $::lx_office_conf{applications}->{$key};