in reply to Using DBI handle in several packages

I think you're wrong about your cleanliness assesment.

I think it will be cleaner to pass them a DB handle, because then they don't care what DB they're operating on, and if the main code changes it so that 2 of them use one DB and 3 use another, you only have to change the main program. in short, think of the modules as "doing stuff to a database" rather than "doing stuff to database X", and think of main as "calling the modules on database X" -- because a different main could then use those same modules on a different database.

.

update: yes, but are they also passed what type of DB it is? it is perhaps better to pass them handles, so that one can use a BerkeleyDB and another use DBD::CSV ... and yes, you can pass that information, too, but a handle sums it all up, doesn't it?

that's my take, anyway.

.
  • Comment on Re: Using DBI handle in several packages

Replies are listed 'Best First'.
Re: Re: Using DBI handle in several packages
by Beatnik (Parson) on Jun 03, 2001 at 01:47 UTC
    That data is passed to the modules by the main code anyway. The modules connect, fetch data and close up. :)

    Update: All data required for a clean connect is either passed along in constructor (User, Password, DB Type, DB Name, Port) or are Module vars (table name).

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.