Index: slimserver.pl =================================================================== --- slimserver.pl (revision 7184) +++ slimserver.pl (working copy) @@ -121,29 +121,45 @@ my @failed = (); + my (%oldInc, @newModules); + for my $module (@modules) { - + %oldInc = %INC; eval "use $module"; if ($@) { - Symbol::delete_package($module); - push @failed, $module; - $module =~ s|::|/|g; - $module .= '.pm'; + @newModules = grep { !$oldInc{$_} } keys %INC; - delete $INC{$module}; + for my $newModule(@newModules) { + delete $INC{$newModule}; + + $newModule =~ s|/|::|g; + $newModule =~ s|\.pm$||; + + Symbol::delete_package($newModule); + } + } } return @failed; } + # How should this get set? The command line parameters have not yet been parsed + my $d_startup = 1; + # Here's what we want to try and load. This will need to be updated # when a new XS based module is added to our CPAN tree. my @modules = qw(Time::HiRes DBD::SQLite DBI XML::Parser HTML::Parser Compress::Zlib); + # Bug 3324 + # In some cases, GD wasn't loading even though there was a working installation in + # the user's CPAN path. This is an attempt to use the use the system described above + # to load GD if possible. + my @optional_modules = qw(GD); + if ($] <= 5.007) { push @modules, qw(Storable Digest::MD5); } @@ -167,21 +183,39 @@ ); } + $d_startup && printf("Got @" . "INC containing:\n%s\n\n", join("\n", @INC)); + my %libPaths = map { $_ => 1 } @SlimINC; # This works like 'use lib' # prepend our directories to @INC so we look there first. unshift @INC, @SlimINC; + $d_startup && printf("Extended @" . "INC to contain:\n%s\n\n", join("\n", @INC)); + # Try and load the modules - some will fail if we don't include the # binaries for that version/architecture combo my @failed = tryModuleLoad(@modules); + my @failed_optional = tryModuleLoad(@optional_modules); + if (scalar @failed && $d_startup) { + printf("The following modules failed to load on the first attempt: %s\n\n", join(' ', @failed)); + } + + if (scalar @failed_optional && $d_startup) { + printf("The following optional modules failed to load on the first attempt: %s\n\n", join(' ', @failed_optional)); + } + # Remove our paths so we can try loading the failed modules from the default system @INC @INC = grep { !$libPaths{$_} } @INC; my @reallyFailed = tryModuleLoad(@failed); + my @reallyFailed_optional = tryModuleLoad(@failed_optional); + if (scalar @reallyFailed_optional && $d_startup) { + printf("The following optional modules failed to load: %s\n\n", join(' ', @reallyFailed)); + } + if (scalar @reallyFailed) { printf("The following modules failed to load: %s\n\n", join(' ', @reallyFailed)); @@ -192,9 +226,16 @@ exit; } + # And we're done with the trying - put our CPAN path back on @INC. unshift @INC, @SlimINC; + if ($d_startup) { + print "The following modules are loaded:\n"; + print map {"$_ => $INC{$_}\n"} keys %INC; + print "\n"; + } + # Bug 2659 - maybe. Remove old versions of modules that are now in the $Bin/lib/ tree. if (!Slim::Utils::OSDetect::isDebian()) {