# HG changeset patch # User Matthew Wild # Date 1314637769 14400 # Node ID 35ebd8e5747a1933bf1346d24e1053e05391ec67 # Parent 851885cb332d98ab1806b7d1d2e11dc481c1d019 modulemanager: Add module:handle_items() to allow a module to more easily handle a list of items on a host diff -r 851885cb332d -r 35ebd8e5747a core/modulemanager.lua --- a/core/modulemanager.lua Mon Aug 29 13:00:33 2011 -0400 +++ b/core/modulemanager.lua Mon Aug 29 13:09:29 2011 -0400 @@ -453,4 +453,14 @@ 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;