# HG changeset patch # User Matthew Wild # Date 1331779951 0 # Node ID 27fbc9c69eb5f980607212797d9a01b1828db3c2 # Parent 8bb93860fe463b59277299b3f941daca7e0f8a21 moduleapi: Add module:provides(), a shortcut to add an item with the current module's name diff -r 8bb93860fe46 -r 27fbc9c69eb5 core/moduleapi.lua --- a/core/moduleapi.lua Wed Mar 14 23:44:24 2012 +0000 +++ b/core/moduleapi.lua Thu Mar 15 02:52:31 2012 +0000 @@ -292,4 +292,18 @@ end end +function api:provides(name, item) + if not item then item = self.environment; end + if not item.name then + local item_name = module.name; + -- Strip a provider prefix to find the item name + -- (e.g. "auth_foo" -> "foo" for an auth provider) + if item_name:find(name.."_", 1, true) == 1 then + item_name = item_name:sub(#name+2); + end + item.name = item_name; + end + self:add_item(name, item); +end + return api;