installation_check prüft jetzt auch auf Versionen.
[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 => "parent",                              url => "http://search.cpan.org/~corion/" },
12   { name => "Archive::Zip",                        url => "http://search.cpan.org/~adamk/" },
13   { name => "Class::Accessor",                     url => "http://search.cpan.org/~kasei/" },
14   { name => "CGI::Ajax",                           url => "http://search.cpan.org/~bct/" },
15   { name => "DateTime",                            url => "http://search.cpan.org/~drolsky/" },
16   { name => "DBI",                                 url => "http://search.cpan.org/~timb/" },
17   { name => "DBD::Pg",                             url => "http://search.cpan.org/~dbdpg/" },
18   { name => "Email::Address",                      url => "http://search.cpan.org/~rjbs/" },
19   { name => "FCGI",                                url => "http://search.cpan.org/~mstrout/" },
20   { name => "IO::Wrap",                            url => "http://search.cpan.org/~dskoll/" },
21   { name => "List::MoreUtils",                     url => "http://search.cpan.org/~vparseval/" },
22   { name => "PDF::API2",                           url => "http://search.cpan.org/~areibens/" },
23   { name => "Template",        version => '2.18',  url => "http://search.cpan.org/~abw/" },
24   { name => "Text::CSV_XS",                        url => "http://search.cpan.org/~hmbrand/" },
25   { name => "Text::Iconv",                         url => "http://search.cpan.org/~mpiotr/" },
26   { name => "URI",                                 url => "http://search.cpan.org/~gaas/" },
27   { name => "XML::Writer",                         url => "http://search.cpan.org/~josephw/" },
28   { name => "YAML",                                url => "http://search.cpan.org/~ingy/" },
29 );
30
31 @optional_modules = ();
32
33 sub module_available {
34   my $module  = $_[0];
35   my $version = $_[1] || '' ;
36
37   if (!defined(eval("require $module $version;"))) {
38     return 0;
39   } else {
40     return 1;
41   }
42 }
43
44 my %conditional_dependencies;
45
46 sub check_for_conditional_dependencies {
47   if (!$conditional_dependencies{net_ldap}) {
48     $conditional_dependencies{net_ldap} = 1;
49
50     my $in = IO::File->new('config/authentication.pl', 'r');
51     if ($in) {
52       my $self = {};
53       my $code;
54
55       while (my $line = <$in>) {
56         $code .= $line;
57       }
58       $in->close();
59
60       eval $code;
61
62       if (! $EVAL_ERROR) {
63
64         if ($self->{module} && ($self->{module} eq 'LDAP')) {
65           push @required_modules, { 'name' => 'Net::LDAP', 'url' => 'http://search.cpan.org/~gbarr/' };
66         }
67       }
68     }
69   }
70 }
71
72 sub test_all_modules {
73   return grep { !module_available($_->{name}) } @required_modules;
74 }
75
76 1;