comparison mod_reload_modules/mod_reload_modules.lua @ 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 524f22ef2c2b
children 412f62d05a23
comparison
equal deleted inserted replaced
501:e851f386c904 502:aad0b2df9e6b
7 else 7 else
8 module:log("error", "Failed to reload %s: %s", name, err); 8 module:log("error", "Failed to reload %s: %s", name, err);
9 end 9 end
10 end 10 end
11 11
12 prosody.events.add_handler("config-reloaded", function () 12 function reload_all()
13 local modules = module:get_option_array("reload_modules"); 13 local modules = module:get_option_array("reload_modules");
14 if not modules then 14 if not modules then
15 module:log("warn", "No modules listed in the config to reload - set reload_modules to a list"); 15 module:log("warn", "No modules listed in the config to reload - set reload_modules to a list");
16 return; 16 return;
17 end 17 end
18 for _, module in ipairs(modules) do 18 for _, module in ipairs(modules) do
19 reload_module(module); 19 reload_module(module);
20 end 20 end
21 end); 21 end
22
23
24 if module.hook_global then
25 module:hook_global("config-reloaded", reload_all);
26 else -- COMPAT w/pre-0.9
27 function module.load()
28 prosody.events.add_handler("config-reloaded", reload_all);
29 end
30 function module.unload()
31 prosody.events.remove_handler("config-reloaded", reload_all);
32 end
33 end