== this is the "base module shared by all - I use base *it* instead of CGI::App directly. package YPTP::App; use strict; use base 'CGI::Application'; use base 'YPTP::DataBase'; use base 'YPTP::Email'; use CGI::Application::Plugin::TT; # TemplateToolkit use CGI::Application::Plugin::Session; # CGI::Session use CGI::Application::Plugin::AutoRunmode; sub cgiapp_init { my $self = shift; .... ussual setup stuff ... } # In case most of pages are public - if not I set it to return 0 sub authorize { my $self = shift; return 1; } sub cgiapp_prerun { my ($self, $run_mode) = @_; # CGI::APP doesn't alow you to change runmode at init stage - say if there is an error with # DB connection ... So I set it there and catch it here. if( $self->param('error') ){ $self->prerun_mode('ERROR'); } # Maybe only some runmodes need to be protected - so we send the runmode name to decide unless( $self->authorize($run_mode) ){ # Error $self->prerun_mode('NOT_AUTHORIZED'); } } === some module containing runmodes connected logically package YPTP::Runmodes::Admin; use strict; use base 'YPTP::App'; sub authorize { my $self = shift; my $runmode = shift; my $type = $self->session->param('type'); return 1 if($type eq 'admin'); # admin can do anything return 0; # everyone else can't do a thing }