Changeset

4613:27fbc9c69eb5

moduleapi: Add module:provides(), a shortcut to add an item with the current module's name
author Matthew Wild <mwild1@gmail.com>
date Thu, 15 Mar 2012 02:52:31 +0000
parents 4612:8bb93860fe46
children 4614:20940729c1b4
files core/moduleapi.lua
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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;