in reply to How to write effective modules
I don't know that there is really a "right way" to do it. If what you're doing is working and you're comfortable with it (although based on this post I have to assume you're not), then go with that.
What I typically like to do to handle this situation is to pass the database class to the object during construction. So if you've got a session class, then maybe it would look something like my $session = new MySession($db), or better yet pass the parameters to the constructor as a hash reference: my $session = new MySession({db => $db, arg2 => $foo}).
Looking into the future (maybe you'll want to change the database handle during execution...what do I know?), you could also add some accessors and mutators: $session->db retrieves the database object, and $session->set_db($new_db) changes the database the object is using.
|
|---|