in reply to juggling multiple CGI::Application subclasses

I use a base class which can check the appropriate permissions/credentials in the cgiapp_prerun phase. Here's an example where I check to see if a user has an admin bit -- all the administration modules in this app inherit from this. If the user doesn't have the right credentials, then the runmode is reset to unauthorized, which just displays a "permission denied" screen. You can use the same technique for interrupting the session with a login screen -- although for this app I use mod_auth_tkt for that purpose instead.
package Alex2::CGI::Admin; use strict; use warnings; use base 'Alex2::CGI'; sub setup { my $self = shift; $self->run_modes( [ 'main' ] ); $self->start_mode( 'main' ); } sub cgiapp_prerun { my $self = shift; $self->SUPER::cgiapp_prerun( @_ ); $self->run_modes( [ 'unauthorized' ] ); unless( $self->user->admin or $self->user->group_admin ) { $self->prerun_mode( 'unauthorized' ); } # group admins can only use certain tools if ( $self->user->group_admin and !$self->allows_group_admin ) { $self->prerun_mode( 'unauthorized' ); } } ....