cf523be2a3b468ae0803518ff00578089e92092c
[kivitendo-erp.git] / SL / InstallationCheck.pm
1 package SL::InstallationCheck;
2
3 use English '-no_match_vars';
4 use IO::File;
5
6 use vars qw(@required_modules @optional_modules);
7
8 use strict;
9
10 @required_modules = (
11   { name => "Archive::Zip",    url => "http://search.cpan.org/~adamk/" },
12   { name => "Class::Accessor", url => "http://search.cpan.org/~kasei/" },
13   { name => "CGI::Ajax",       url => "http://search.cpan.org/~bct/" },
14   { name => "DBI",             url => "http://search.cpan.org/~timb/" },
15   { name => "DBD::Pg",         url => "http://search.cpan.org/~dbdpg/" },
16   { name => "Email::Address",  url => "http://search.cpan.org/~rjbs/" },
17   { name => "FCGI",            url => "http://search.cpan.org/~mstrout/" },
18   { name => "IO::Wrap",        url => "http://search.cpan.org/~dskoll/" },
19   { name => "List::MoreUtils", url => "http://search.cpan.org/~vparseval/" },
20   { name => "PDF::API2",       url => "http://search.cpan.org/~areibens/" },
21   { name => "Template",        url => "http://search.cpan.org/~abw/" },
22   { name => "Text::CSV_XS",    url => "http://search.cpan.org/~hmbrand/" },
23   { name => "Text::Iconv",     url => "http://search.cpan.org/~mpiotr/" },
24   { name => "URI",             url => "http://search.cpan.org/~gaas/" },
25   { name => "XML::Writer",     url => "http://search.cpan.org/~josephw/" },
26   { name => "YAML",            url => "http://search.cpan.org/~ingy/" },
27 );
28
29 @optional_modules = ();
30
31 sub module_available {
32   my ($module) = @_;
33
34   if (!defined(eval("require $module;"))) {
35     return 0;
36   } else {
37     return 1;
38   }
39 }
40
41 my %conditional_dependencies;
42
43 sub check_for_conditional_dependencies {
44   if (!$conditional_dependencies{net_ldap}) {
45     $conditional_dependencies{net_ldap} = 1;
46
47     my $in = IO::File->new('config/authentication.pl', 'r');
48     if ($in) {
49       my $self = {};
50       my $code;
51
52       while (my $line = <$in>) {
53         $code .= $line;
54       }
55       $in->close();
56
57       eval $code;
58
59       if (! $EVAL_ERROR) {
60
61         if ($self->{module} && ($self->{module} eq 'LDAP')) {
62           push @required_modules, { 'name' => 'Net::LDAP', 'url' => 'http://search.cpan.org/~gbarr/' };
63         }
64       }
65     }
66   }
67 }
68
69 sub test_all_modules {
70   return grep { !module_available($_->{name}) } @required_modules;
71 }
72
73 1;