[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cgiapp] DAO, DBIx::Abstract and other DBH musings (was: Re: [cgiapp] CGI::App::DAO) (fwd)


> > Relating to what's been mentioned here about the P5EE standards, I'm
> > tinkering with a DAO base object for CGI::App.  I've given it a
> > preliminary name of CGI::Application::DAO.
> ...snip...
> > I've successfully used basic implementation of CGI::Application::DAO in
> > one of my existing web projects based on CGI-App.  For that project, I
> > simply had to extend the base CGI-App dao and add extra functionality as
> > was needed. ;-)
>
> I looked into DBIx::Abstract and DBIx::Recordset as DBI wrappers, among other.

I use DBIx::Abstract regularly and find it works well for me. Mostly I
use the "insert" and "update" functions which allow me to supply my data
in the more natural form of a Perl hash. Most of the rest of module I
ignore.

Beyond that I prefer to minimize abstraction by using the DBI module
directly. I've found it has many good documented for error handling and
returning data in various formats.

You can see DBIx::Abstract used in my Cascade CGI::App:
http://summersault.com/software/cascade

I do struggle some with the best way to make the "$DBH" handle
available. One method is make it a global variable. This makes
functions as brief as possible, because $DBH is everywhere you want it
to be. However, you have to jump through some subtle hoops to make sure
the namespace/package/module issues work out to make sure it
appears everywhere it should. Some scalablity is probably lost here.

Another method would be to put the $DBH in a CGI::App "param".
This makes the handle available everywhere you have a sub-class of
your CGI Application with:

sub foo {
	my $self = shift;
	my $dbh = $self->param('dbh');
}

####

That seems like an elegant way to address package/namespace issues at
the expense of coding in this line in a lot of places:

	my $dbh = $self->param('dbh');

But that could also be called "Clarity", which could be a Good Thing.

  Mark

http://mark.stosberg.com/

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.