X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FSystem%2FProcess.pm;h=36f1f657f39d207ff8e91252ed4b46eb9cd0bd36;hb=43de7ef11a1fe565968656c24ea0772a60667b3b;hp=0bddfd6b3c9de89ed7dbad1262f9ec1be9522d0f;hpb=36da77056776b6a84470fe7a3665077943f846b9;p=kivitendo-erp.git diff --git a/SL/System/Process.pm b/SL/System/Process.pm index 0bddfd6b3..36f1f657f 100644 --- a/SL/System/Process.pm +++ b/SL/System/Process.pm @@ -5,21 +5,24 @@ use strict; use parent qw(Rose::Object); use English qw(-no_match_vars); +use FindBin; use File::Spec; use File::Basename; +use List::Util qw(first); + +my $cached_exe_dir; sub exe_dir { - my $dir = dirname(File::Spec->rel2abs($PROGRAM_NAME)); - my $system_dir = File::Spec->catdir($dir, 'SL', 'System'); - return $dir if -d $system_dir && -f File::Spec->catfile($system_dir, 'TaskServer.pm'); + return $cached_exe_dir if defined $cached_exe_dir; + + my $bin_dir = File::Spec->rel2abs($FindBin::Bin); + my @dirs = File::Spec->splitdir($bin_dir); - my @dirs = reverse File::Spec->splitdir($dir); - shift @dirs; - $dir = File::Spec->catdir(reverse @dirs); - $system_dir = File::Spec->catdir($dir, 'SL', 'System'); - return File::Spec->curdir unless -d $system_dir && -f File::Spec->catfile($system_dir, 'TaskServer.pm'); + $cached_exe_dir = first { -f File::Spec->catdir(@dirs[0..$_], 'SL', 'System', 'TaskServer.pm') } + reverse(0..scalar(@dirs) - 1); + $cached_exe_dir = defined($cached_exe_dir) ? File::Spec->catdir(@dirs[0..$cached_exe_dir]) : File::Spec->curdir; - return $dir; + return $cached_exe_dir; } 1; @@ -35,7 +38,7 @@ SL::System::Process - assorted system-relevant functions =head1 SYNOPSIS - # Get base path to Kivitendo scripts + # Get base path to kivitendo scripts my $path = SL::System::Process->exe_dir; =head1 FUNCTIONS @@ -44,7 +47,7 @@ SL::System::Process - assorted system-relevant functions =item C -Returns the absolute path to the directory the Kivitendo executables +Returns the absolute path to the directory the kivitendo executables (C etc.) and modules (sub-directory C etc.) are located in.