36f1f657f39d207ff8e91252ed4b46eb9cd0bd36
[kivitendo-erp.git] / SL / System / Process.pm
1 package SL::System::Process;
2
3 use strict;
4
5 use parent qw(Rose::Object);
6
7 use English qw(-no_match_vars);
8 use FindBin;
9 use File::Spec;
10 use File::Basename;
11 use List::Util qw(first);
12
13 my $cached_exe_dir;
14
15 sub exe_dir {
16   return $cached_exe_dir if defined $cached_exe_dir;
17
18   my $bin_dir       = File::Spec->rel2abs($FindBin::Bin);
19   my @dirs          = File::Spec->splitdir($bin_dir);
20
21   $cached_exe_dir   = first { -f File::Spec->catdir(@dirs[0..$_], 'SL', 'System', 'TaskServer.pm') }
22                       reverse(0..scalar(@dirs) - 1);
23   $cached_exe_dir   = defined($cached_exe_dir) ? File::Spec->catdir(@dirs[0..$cached_exe_dir]) : File::Spec->curdir;
24
25   return $cached_exe_dir;
26 }
27
28 1;
29 __END__
30
31 =pod
32
33 =encoding utf8
34
35 =head1 NAME
36
37 SL::System::Process - assorted system-relevant functions
38
39 =head1 SYNOPSIS
40
41   # Get base path to kivitendo scripts
42   my $path = SL::System::Process->exe_dir;
43
44 =head1 FUNCTIONS
45
46 =over 4
47
48 =item C<exe_dir>
49
50 Returns the absolute path to the directory the kivitendo executables
51 (C<login.pl> etc.) and modules (sub-directory C<SL/> etc.) are located
52 in.
53
54 =back
55
56 =head1 BUGS
57
58 Nothing here yet.
59
60 =head1 AUTHOR
61
62 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
63
64 =cut