diff --git a/modules/modperl.cpp b/modules/modperl.cpp index 4a37ae54..a7bbd579 100644 --- a/modules/modperl.cpp +++ b/modules/modperl.cpp @@ -73,44 +73,40 @@ public: return true; } - ELoadPerlMod LoadPerlModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg) { - ELoadPerlMod result = Perl_LoadError; - PSTART; - PUSH_STR(sModule); - PUSH_STR(sArgs); - PUSH_PTR(CUser*, pUser); - PCALL("ZNC::Core::LoadModule"); - - if (SvTRUE(ERRSV)) { - sRetMsg = PString(ERRSV); - } else if (2 == ret) { - result = static_cast(SvUV(ST(0))); - sRetMsg = PString(ST(1)); - } - DEBUG(__PRETTY_FUNCTION__ << " " << sRetMsg); - - PEND; - return result; - } - virtual EModRet OnModuleLoading(const CString& sModName, const CString& sArgs, bool& bSuccess, CString& sRetMsg) { if (!GetUser()) { return CONTINUE; } - switch (LoadPerlModule(sModName, sArgs, GetUser(), sRetMsg)) { - case Perl_NotFound: - return CONTINUE; - case Perl_Loaded: - bSuccess = true; - return HALT; - case Perl_LoadError: - bSuccess = false; - return HALT; + EModRet result = HALT; + PSTART; + PUSH_STR(sModName); + PUSH_STR(sArgs); + PUSH_PTR(CUser*, GetUser()); + PCALL("ZNC::Core::LoadModule"); + + if (SvTRUE(ERRSV)) { + sRetMsg = PString(ERRSV); + bSuccess = false; + result = HALT; + DEBUG("Perl ZNC::Core::LoadModule died: " << sRetMsg); + } else if (ret < 1 || 2 < ret) { + sRetMsg = "Error: Perl ZNC::Core::LoadModule returned " + CString(ret) + " values."; + bSuccess = false; + result = HALT; + } else { + ELoadPerlMod eLPM = static_cast(SvUV(ST(0))); + if (Perl_NotFound == eLPM) { + result = CONTINUE; // Not a Perl module + } else { + sRetMsg = PString(ST(1)); + result = HALT; + bSuccess = eLPM == Perl_Loaded; + } } - sRetMsg = "Something weird happened"; - bSuccess = false; - return HALT; + + PEND; + return result; } virtual EModRet OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg) { diff --git a/modules/modperl/startup.pl b/modules/modperl/startup.pl index 67240f20..ddaa3818 100644 --- a/modules/modperl/startup.pl +++ b/modules/modperl/startup.pl @@ -94,9 +94,9 @@ sub LoadModule { return ($ZNC::Perl_LoadError, "Module [$modname] already loaded.") if defined $user->GetModules->FindModule($modname); my $modpath = ZNC::String->new; my $datapath = ZNC::String->new; - ZNC::CModules::FindModPath("$modname.pm", $modpath, $datapath) or return ($ZNC::Perl_NotFound, "Unable to find module [$modname]"); + ZNC::CModules::FindModPath("$modname.pm", $modpath, $datapath) or return ($ZNC::Perl_NotFound); $modpath = $modpath->GetPerlStr; - return ($ZNC::Perl_LoadError, "Incorrect perl module.") unless IsModule $modpath, $modname; + return ($ZNC::Perl_LoadError, "Incorrect perl module [$modpath]") unless IsModule $modpath, $modname; eval { require $modpath; };