in reply to OOP design related question.

I would use Class::DBI to build a module MyApp::Db whose sole job is handling all database work (your add/delete/update logic).
package MyApp::Db; use base Class::DBI; __PACKAGE__->connection('dbi:mysql:dbname', 'username', 'password'); 1; package MyApp::Db::User; use base MyApp::Db; __PACKAGE__->table('user'); __PACKAGE__->columns(All => qw/id username password/); ...
Then your RunModes:: only need to use MyApp::Db objects to do database operations, and there is no need to pass a $dbh around.
package RunModes::User; use MyApp::Db::User; ... sub validate_user { my $self = shift; my $q = $self->query; my $user = MyApp::Db::User->search( username => $q->param('username '), password => $q->param('password') ); if($user) { # laugh } else { # cry } }

Replies are listed 'Best First'.
Re^2: OOP design related question.
by techcode (Hermit) on Sep 09, 2005 at 20:07 UTC
    Already using sort of abstraction. It's a module that I'm working on - mentioned it on this node > 487823.

    Anyway correct me if I'm wrong, but in case I wouldn't pass this object "around", every time I need DB access, new connection would be made?

    I mean, CGI::Session would connect on itself, then once again my code to check the data and add user? Who knows how many connections would be made latter on when I add all sorts of things ... Obvisoly I'm using plain CGI, Apache::DBI (or whichever) is not available ...

      No, Class::DBI is built on top of Ima::DBI which does database connection caching, so you wouldn't be re-connecting each time you use the Class::DBI objects.