web_root + - index.cgi + lib - App.pm - Account.pm - ... + templates - welcome.tmpl - login.tmpl - ... # in index.cgi ########################## use lib "lib"; use App; my $c = App->new( TMPL_PATH => "templates", PARAMS => { .. } ); $c->run(); ##################################### # in App.pm ########################### use base "CGI::Application"; use Account; sub setup { my $self = shift; $self->start_mode("view"); $self->mode_param("a"); $self->run_modes( "view" => "view", "edit" => "edit", .. "verify" => "Account::verify", "login" => "Account::login", "logout" => "Account::logout", "create account" => "Account::create", ); } sub view { my $self = shift; if ($self->session->param("~logged_in")) { # View stuff } else { $self->login; } } ##################################### # in Account.pm ######################## package Account; sub login { my ($self, %args) = @_; # login stuff $self->view; } sub logout { my ($self, %args) = @_; # logout stuff $self->view; } #####################################