From f87baaa40bcc86b62759df6bf884ff53548f348c Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 24 Apr 2008 13:43:11 +0000 Subject: Added destroy and on_unload functions. Moved saving of session from post_exec to on_unload. git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1036 ab2d0c66-481e-0410-8bed-d214d4d58bed --- www/cgi-bin/mvc.lua | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'www/cgi-bin/mvc.lua') diff --git a/www/cgi-bin/mvc.lua b/www/cgi-bin/mvc.lua index 1fa88da..c64fa08 100755 --- a/www/cgi-bin/mvc.lua +++ b/www/cgi-bin/mvc.lua @@ -96,9 +96,16 @@ new = function (self, modname) return c, worker_loaded, model_loaded end +destroy = function (self) + if type(rawget(self.worker.mvc, "on_unload")) == "function" then + self.worker.mvc.on_unload(self) + self.worker.mvc.on_unload = nil + end +end + -- This is a sample front controller/dispatch. dispatch = function (self, userprefix, userctlr, useraction) - local controller + local controller = nil local success, err = xpcall ( function () if userprefix == nil then @@ -112,7 +119,6 @@ dispatch = function (self, userprefix, userctlr, useraction) -- Find the proper controller/action combo local origconf = {controller = self.conf.controller, action = self.conf.action} - local controller = nil local action = "" self.conf.default_controller = self.conf.default_controller or "" self.conf.default_prefix = self.conf.default_prefix or "" @@ -161,7 +167,10 @@ dispatch = function (self, userprefix, userctlr, useraction) end if "" ~= action then break end end - controller = nil + if controller then + controller:destroy() + controller = nil + end self.conf.action = "" if self.conf.controller ~= self.conf.default_controller then self.conf.prefix = self.conf.default_prefix @@ -192,15 +201,17 @@ dispatch = function (self, userprefix, userctlr, useraction) -- run the action local viewtable = controller.worker[action](controller) - -- run the post_exec code if type(controller.worker.mvc.post_exec) == "function" then controller.worker.mvc.post_exec ( controller ) end - local viewfunc = controller.worker:view_resolver(viewtable) + -- we're done with the controller, destroy it + controller:destroy() + controller = nil + viewfunc (viewtable) end, self:soft_traceback(message) @@ -210,9 +221,14 @@ dispatch = function (self, userprefix, userctlr, useraction) local handler if controller then handler = controller.worker or controller + if handler then handler:exception_handler(err) end + controller:destroy() + controller = nil + end + if nil == handler then + handler = self.worker or mvc + handler:exception_handler(err) end - handler = handler or self.worker or mvc - handler:exception_handler(err) end end -- cgit v1.2.3