Take look at
CGI::Application (and its associated plugins) - it uses an object-oriented approach. The code you actually write simply uses $self->session to access the session object, $self->query to access the cgi object, $self->dbh to access the database object, etc.