+sub _init_environment {
+ return if $environment_initialized;
+
+ my %key_map = ( lib => { name => 'PERL5LIB', append_path => 1 },
+ path => { name => 'PATH', append_path => 1 },
+ );
+ my $cfg = $::lx_office_conf{environment} || {};
+
+ while (my ($key, $value) = each %{ $cfg }) {
+ next unless $value;
+
+ my $info = $key_map{$key} || {};
+ $key = $info->{name} || $key;
+
+ if ($info->{append_path}) {
+ $value = ':' . $value unless $value =~ m/^:/ || !$ENV{$key};
+ $value = $ENV{$key} . $value if $ENV{$key};
+ }
+
+ $ENV{$key} = $value;
+ }
+
+ $environment_initialized = 1;
+}
+
+sub _determine_application_paths {
+ my @paths = grep { $_ } split m/:/, $ENV{PATH};
+
+ foreach my $key (keys %{ $::lx_office_conf{applications} }) {
+ my ($program) = split m/\s+/, $::lx_office_conf{applications}->{$key};
+ next if $program =~ m|/|;
+
+ foreach my $path (@paths) {
+ next unless -f "${path}/${program}";
+ $::lx_office_conf{applications}->{$key} = "${path}/" . $::lx_office_conf{applications}->{$key};
+ last;
+ }
+ }
+}
+