in reply to Re^6: Auto-Increment and DBD Agnosticism
in thread Auto-Increment and DBD Agnosticism

Now that I think about it, maybe I have the components of my name spacing all backwards! This all might make a lot more sense if instead of Whatever::Link::Query and Whatever::Object::Query I had Whatever::Query::Link and Whatever::Query::Object. In fact, I think that's perfect... Each of those could probably benefit (though I'm not yet sure how) from a common Whatever::Query base class. Furthermore, I could then use the Object subdirectory strictly for subclasses of Whatever::Object. This fixes all of my quandaries.

I like this the best. Feels good to me :)

Am I crazy for even considering this?

Of course you are, but that shouldnt surprise you, no doubt you have been crazy all your life, otherwise you wouldnt be a perl programmer :)

Is there a more elegant way of doing what I want to do?.

Well, I have had to solve this problem in particular myself, and I always kind of liked the way I did it. I has worked for me quite successfully for a little while now. Here is an example using your namespace:

package Whatever::Object::DBDAgnostic; use strict; use warnings; sub import { # only set this once return if scalar @Whatever::Object::DBDAgnostic::ISA; my (undef, $base_class) = @_; die "You must define a DBD-type" unless $base_class; push @Whatever::Object::DBDAgnostic::ISA => $base_class; } 1;
Then all your users need to do is:
package Foo; use strict; use base qw/Whatever::Object::DBDAgnostic/; # decorator methods go here 1;
Then in order to set what DBD subclass is to be used you, all your user needs to do this:
use Whatever::Object::DBDAgnostic qw(Whatever::Object::MySQL);
Before any other code that uses Whatever::Object::DBDAgnostic is loaded, and your Whatever::Object::DBDAgnostic::ISA should be good. Sure its an extra level of inheritence, but it pays for itself in flexibility. Also keep in mind that perl's method caching will pretty much make a performance cost to null in a long running system like mod_perl.

-stvn