Permalink
Browse files

Allow perl modules to be loaded not by modperl

  • Loading branch information...
1 parent ff755b8 commit 3145c5054caa3f40f669b49e0f84852fcd307218 @DarthGandalf DarthGandalf committed Jul 28, 2012
Showing with 21 additions and 5 deletions.
  1. +14 −3 modules/modperl.cpp
  2. +1 −1 modules/modperl/modperl.i
  3. +6 −1 modules/modperl/startup.pl
View
@@ -115,20 +115,31 @@ class CModPerl: public CModule {
virtual EModRet OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg) {
CPerlModule* pMod = AsPerlModule(pModule);
if (pMod) {
+ EModRet result = HALT;
CString sModName = pMod->GetModName();
PSTART;
XPUSHs(pMod->GetPerlObj());
PCALL("ZNC::Core::UnloadModule");
if (SvTRUE(ERRSV)) {
bSuccess = false;
sRetMsg = PString(ERRSV);
+ } else if (ret < 1 || 2 < ret) {
+ sRetMsg = "Error: Perl ZNC::Core::UnloadModule returned " + CString(ret) + " values.";
+ bSuccess = false;
+ result = HALT;
} else {
- bSuccess = true;
- sRetMsg = "Module [" + sModName + "] unloaded";
+ int bUnloaded = SvUV(ST(0));
+ if (bUnloaded) {
+ bSuccess = true;
+ sRetMsg = "Module [" + sModName + "] unloaded";
+ result = HALT;
+ } else {
+ result = CONTINUE; // module wasn't loaded by modperl. Perhaps a module-provider written in perl did that.
+ }
}
PEND;
DEBUG(__PRETTY_FUNCTION__ << " " << sRetMsg);
- return HALT;
+ return result;
}
return CONTINUE;
}
@@ -264,4 +264,4 @@ typedef std::vector<std::pair<CString, CString> > VPair;
*GetNicks = *_GetNicks_;
%}
-/* vim: set filetype=cpp noexpandtab: */
+/* vim: set filetype=cpp: */
@@ -20,8 +20,12 @@ package ZNC::Core;
sub UnloadModule {
my ($pmod) = @_;
+ my @newallmods = grep {$pmod != $_} @allmods;
+ if ($#allmods == $#newallmods) {
+ return 0
+ }
+ @allmods = @newallmods;
$pmod->OnShutdown;
- @allmods = grep {$pmod != $_} @allmods;
my $cmod = $pmod->{_cmod};
my $modpath = $cmod->GetModPath;
my $modname = $cmod->GetModName;
@@ -43,6 +47,7 @@ sub UnloadModule {
ZNC::_CleanupStash($modname);
delete $INC{$modpath};
}
+ return 1
# here $cmod is deleted by perl (using DESTROY)
}

0 comments on commit 3145c50

Please sign in to comment.