First, since the DBI object ($dbh) is already a reference, there is no problem returning this instead of a reference to it. In fact, I would think this preferable since there is no need to return a reference to a reference. Generally (though not always), one returns a reference to data due to the overhead of passing the data itself. Since you already have a reference, that overhead is avoided.
As for your actual question, I understood you to ask whether using the exported function or using the returned database handle is preferable. My opinion is that you should not even return a database handle. Isolate your code from the database.
As an example, I am currently working on a Web site administrative package for a company that allows them to manage most of the content of their Web site through a convenient Web interface. Naturally, this relies heavily on a database. However, you will not see a single line of SQL in any of the programs that my coworkers are writing. There is absolutely nothing database dependant in any of them (the programs, not the coworkers :). Instead, I have created some modules that interact with the database and all programmers writing the programs use the objects (in your case, functions) that are made available. Why is this important? Because if we need to make changes to the database, we there are only three modules that contain all database dependant code (one for information retrieval, one for modifications, and the other for security, all with an appropriate level of permissions).
At last count, excluding the modules, we had about 30 different programs on this system. Can you imagine the havoc caused by updating the database and having to search through 30 programs for anything that touches the database?
Cheers,
Ovid
Vote for paco!
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to (Ovid) Re: Using DBI: handlers or references to handlers?
by Ovid
in thread Using DBI: handlers or references to handlers?
by fx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |