From be9a85a08af059ee16b242cdaba01b539d14ff32 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 29 Aug 2011 13:09:29 -0400 Subject: modulemanager: Add module:handle_items() to allow a module to more easily handle a list of items on a host --- core/modulemanager.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/modulemanager.lua b/core/modulemanager.lua index d0a0f982..b89c5af3 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -453,4 +453,14 @@ function api:get_host_items(key) return result; end +function api:handle_items(type, added_cb, removed_cb, existing) + self:hook("item-added/"..type, added_cb); + self:hook("item-removed/"..type, removed_cb); + if existing ~= false then + for _, item in ipairs(self:get_host_items(type)) do + added_cb({ item = item }); + end + end +end + return _M; -- cgit v1.2.3