From bc6c812ba80f26b8445e8dbd35c79a2b8f2f3da9 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sat, 24 May 2008 22:40:33 +0000 Subject: * fixed problem in module loading code that under some circumstances led to modules being loaded several times (which in turn produced warnings about functions being redefined) git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1800 95ad53e4-c205-0410-b2fa-d234c58c8868 --- lib/OpenSLX/Basics.pm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/OpenSLX/Basics.pm b/lib/OpenSLX/Basics.pm index 679b9acb..07ab364b 100644 --- a/lib/OpenSLX/Basics.pm +++ b/lib/OpenSLX/Basics.pm @@ -605,9 +605,11 @@ sub instantiateClass $moduleName .= '.pm'; vlog(3, "trying to load $moduleName..."); - my @originalINC = @INC; - if (!eval { unshift @INC, @$incPaths; require $moduleName; 1 } ) { - @INC = @originalINC; + foreach my $incPath (@$incPaths) { + next if grep { $_ eq $incPath } @INC; + unshift @INC, $incPath; + } + if (!eval { require $moduleName; 1 } ) { # check if module does not exists anywhere in search path if (!-e $moduleName) { return if $flags->{acceptMissing}; @@ -616,7 +618,6 @@ sub instantiateClass # some other error (probably compilation problems) die _tr("Unable to load module '%s' (%s)\n", $moduleName, $@); } - @INC = @originalINC; if (defined $requestedVersion) { my $classVersion = $class->VERSION; if ($classVersion < $requestedVersion) { @@ -682,7 +683,6 @@ you can specify that base path via the I<$pathToClass> param. =cut - sub loadDistroModule { my $params = shift; @@ -724,8 +724,7 @@ sub loadDistroModule vlog(1, "trying ${distroScope}::$distroModule ..."); my $flags = { acceptMissing => 1 }; if ($pathToClass) { - $flags->{pathToClass} = $pathToClass; - $flags->{incPaths} = [ $pathToClass ]; + $flags->{incPaths} = [ $pathToClass ]; } $distro = instantiateClass("${distroScope}::$distroModule", $flags); return 0 if !$distro; # module does not exist, try next -- cgit v1.2.3-55-g7522