On this list there was just a thread which brought to light how people access databases through CGI::Application. There were three primary
groups of answers:
1. Custom SQL called directly from the CGI::Application project. 2. Using custom "Data Access Objects" to abstract the issue 3. Using Class::DBI as a standard solution.
I'd like to discuss this issue a little more broadly: What's an
effective way to to structure your application once you realize it makes sense to move some logic into helper modules? Munging data as it comes in and out of the database is probably the most common need for this.
Here are some approaches I can think of:
1. A purely orthogonal module
Here, the helper module has no dependency or relation to CGI::Application. Most other modules you might employ from CPAN would fall into this category. For example, using CGI::Simple, SQL::Abstract or Data::Grouper.
In many ways, this is the ideal setup, because the lack of
interdependence reduces the overall complexity of your application.
I think this is the cleanest way to implement database access in CGI::App, and I would think that Class::DBI falls into this category as well.
Unfortunately, writing this of module for a custom solution can tedious
if there /are/ a lot of interdependencies you want to consider, such as
sharing configuration data, a database handle, session information or
CGI query parameters.
Of the dependancies you list, I believe only configuration data should be shared between your CGIApp modules and your database modules. And that can be handled by sharing the same configuration files (I usually just use a perl module that defines all the variables that are needed and 'use' it in all my modules).
CGI parameters and session info should not need to be accessed directly by the database modules. The Database modules shouldn't even care that you are working in a CGI environment or on the command line, or even a SOAP app.
As for the database handle, that should be managed by the database module, not by the CGI::Application module. I guess this isn't an issue for me, since Class::DBI manages the database handle for me. I usually do add a helper method to my CGIApp super class that retrieves the database handle from Class::DBI in case I need to pass an open dbh to a Session module or something like that. But I never use it directly myself, it is only there for third party modules that require database access.
This method works very well for me, but I doubt it is a panacea. There are just too many ways of doing this stuff. What is important is to find a system that works well for you.
Cheers,
Cees
--------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
