in reply to Strategies for exiting early for CGI::Application based webapp.

If the 'login' page is also part of your CGI::Application module, then you can use the 'prerun_mode' method to change the current runmode to another. That is how I handle authentication is some of my apps.

unless ( defined $user ) { $self->prerun_mode('login'); return; }

If your login script is not part of the CGI::App, then you can do the redirect using CGI::Apps method for redirection, and then change the runmode to a null runmode.

# If the user is not logged in, redirect to the login page unless ( defined $user ) { $self->prerun_mode('null_mode'); $self->header_props({-location => '/login.pl'}); $self->header_type('redirect'); return; } # A runmode that doesn't do anything sub null_mode { }

One of the most important things to remember about CGI::Application is that you never ever use the print command to send output to the browser. If you ever catch yourself using print, then step back and figure out why you really need to use it. Chances are there is a better way to do it.