From 8cf49b2fe04a14d7f14ca0eb1a9feb47967028bd Mon Sep 17 00:00:00 2001
From: dms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Date: Sat, 9 Sep 2000 16:28:07 +0000
Subject: [PATCH] forgot to set module age if successfully loaded. split
 reloadModules into reloadAllModules and reloadModule. &reloadModule() now
 called by loadMyModule()

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@80 c11ca15a-4712-0410-83d8-924469b57eb5
---
 src/modules.pl | 76 +++++++++++++++++++++++++-------------------------
 1 file changed, 38 insertions(+), 38 deletions(-)

diff --git a/src/modules.pl b/src/modules.pl
index 33fe0a4..6802e32 100644
--- a/src/modules.pl
+++ b/src/modules.pl
@@ -178,49 +178,49 @@ sub loadMyModulesNow {
     &status("Modules: Loaded/Total [$loaded/$total]");
 }
 
-### rename to modulesReload?
-sub reloadModules {
-##    my @check = map { $myModules{$_} } keys %myModules;
-##    push(@check, map { substr($_,2) } keys %moduleAge);
-    my @check = map { substr($_,2) } keys %moduleAge;
-
-    &DEBUG("rM: moduleAge must be in src/BLAH format?");
-    foreach (keys %moduleAge) {
-	&DEBUG("rM: moduleAge{$_} => '...'.");
+### rename to moduleReloadAll?
+sub reloadAllModules {
+    &status("Modules: reloading all.");
+    foreach (map { substr($_,2) } keys %moduleAge) {
+        &reloadModule($_);
     }
+    &status("Modules: reloading done.");
+}
 
-    foreach (@check) {
-	my $mod = $_;
-	my $file = (grep /\/$mod/, keys %INC)[0];
+### rename to modulesReload?
+sub reloadModule {
+    my ($mod)	= @_;
+    my $file	= (grep /\/$mod/, keys %INC)[0];
 
-	if (!defined $file) {
-	    &DEBUG("rM: mod '$mod' was not found in \%INC.");
-	    next;
-	}
+    if (!defined $file) {
+	&DEBUG("rM: mod '$mod' was not found in \%INC.");
+	return;
+    }
 
-	if (! -f $file) {
-	    &DEBUG("rM: file '$file' does not exist?");
-	    next;
-	}
+    if (! -f $file) {
+	&DEBUG("rM: file '$file' does not exist?");
+	return;
+    }
 
-	my $age = (stat $file)[9];
-	next if ($age == $moduleAge{$file});
+    my $age = (stat $file)[9];
+    return if ($age == $moduleAge{$file});
 
-	if (grep /$mod/, @myModulesReloadNot) {
-	    &DEBUG("rM: SHOULD NOT RELOAD $mod!!!");
-	    next;
-	}
+    if (grep /$mod/, @myModulesReloadNot) {
+	&DEBUG("rM: SHOULD NOT RELOAD $mod!!!");
+	return;
+    }
 
-	&DEBUG("rM: (loading) => '$mod' or ($_).");
-	delete $INC{$file};
-	eval "require \"$file\"";
-	if (@$) {
-	    &DEBUG("rM: failure: @$");
-	} else {
-	    &DEBUG("rM: good! (reloaded)");
-	}
+    &status("Module: Loading $mod...");
+    delete $INC{$file};
+    eval "require \"$file\"";	# require or use?
+    if (@$) {
+	&DEBUG("rM: failure: @$");
+    } else {
+	my $basename = $file;
+	$basename =~ s/^.*\///;
+	&status("Modules: reloaded $basename");
+	$moduleAge{$file} = $age;
     }
-    &DEBUG("rM: Done.");
 }
 
 ###
@@ -234,6 +234,9 @@ sub loadPerlModule {
     return 0 if (exists $perlModulesMissing{$_[0]});
     return 1 if (exists $perlModulesLoaded{$_[0]});
 
+    &DEBUG("lPM: _ => '$_[0]'.");
+    &reloadModule($_[0]);
+
     eval "use $_[0]";
     if ($@) {
 	&WARN("Module: $_[0] is not installed!");
@@ -252,8 +255,6 @@ sub loadMyModule {
     if (!defined $tmp) {
 	&WARN("loadMyModule: module is NULL.");
 	return 0; 
-    } else {
-	&DEBUG("lMM: arg = '$tmp'.");
     }
 
     my ($modulebase, $modulefile);
@@ -293,7 +294,6 @@ sub loadMyModule {
 	exit 1;
     } else {
 	$moduleAge{$modulefile} = (stat $modulefile)[9];
-	&DEBUG("lMM: setting moduleAge{$modulefile} = time();");
 
 	&status("myModule: Loaded $modulebase ...");
 	&showProc(" ($modulebase)");
-- 
2.39.5