I am using CGI::Application and find it quite useful, but sometimes I have the feeling that I must be too stupid to properly use it as what I do just looks silly to me, yet I cannot find a better solution - which is why I hope for some enlightenment here.
One of my problems is exception-handling in cgi_prerun.
Assume I have a error-runmode configured that gets called whenever an exception occurs in a normal runmode. Very handy.
But now I also have a cgiapp_prerun method that handles some generic stuff that also may throw an exception.
Unfortunately CGI::App does not do exception handling for you in the prerun so you have to catch any possible exception yourself and the question is now how to transfer control to the error-runmode and how to pass the exception on.
Calling the error-runmode directly does not work so my workaround looks something like this (I am also using CGI::Application::Plugin::Stash):
This works but it looks ridiculous...sub cgiapp_prerun { my($this, $rm)=@_; eval { ... }; if($@) { $this->stash->{exception} = $@; $this->prerun_mode("prerun_error") } } sub prerun_error { my($this)=@_; $this->error($this->stash->{exception}); } sub error { # error-runmode my($this, $exception)=@_; ... }
I pass the exception via the stash (basically creating a global variable) and need the prerun_error runmode only to pass control on the error-runmode, because the only way out from cgiapp_prerun seems to be via prerun_mode How would you do this?
Many thanks!
In reply to CGI::Application cgi_prerun exception handling by morgon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |