Changeset

502:aad0b2df9e6b

mod_reload_modules: Use module:hook_global() if available
author Matthew Wild <mwild1@gmail.com>
date Sat, 10 Dec 2011 22:48:59 +0000
parents 501:e851f386c904
children 503:db32236d7682
files mod_reload_modules/mod_reload_modules.lua
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mod_reload_modules/mod_reload_modules.lua	Thu Dec 08 22:01:54 2011 +0000
+++ b/mod_reload_modules/mod_reload_modules.lua	Sat Dec 10 22:48:59 2011 +0000
@@ -9,7 +9,7 @@
 	end
 end
 
-prosody.events.add_handler("config-reloaded", function ()
+function reload_all()
 	local modules = module:get_option_array("reload_modules");
 	if not modules then
 		module:log("warn", "No modules listed in the config to reload - set reload_modules to a list");
@@ -18,4 +18,16 @@
 	for _, module in ipairs(modules) do
 		reload_module(module);
 	end
-end);
+end
+
+
+if module.hook_global then
+	module:hook_global("config-reloaded", reload_all);
+else -- COMPAT w/pre-0.9
+	function module.load()
+		prosody.events.add_handler("config-reloaded", reload_all);
+	end
+	function module.unload()
+		prosody.events.remove_handler("config-reloaded", reload_all);
+	end
+end