in reply to Re: Module RFC: Yet another object-persistence interface
in thread Module RFC: Yet another object-persistence interface
There seem to be a few problems with the tied hash approach. For inflating foreign keys and other functions, Tie::Table is forced to mix OO/hashref metaphors (Tie::DBI doesn't seem to support foreign key inflation which really limits the comparison). From its POD:
Its POD goes on to scare/confuse me with this:%company_14_users = %{ $company->{14}->user }; ## [blokhead: it's not clear whether %company_14_users is magical or + not...] $company->{14}->{tax_num} = "111-22-3333"; $company->{14}->write;
I've never extensively used tied objects, but I'm wondering if this strange behavior is somehow related to the difficulty of nesting, returning tied objects? It's also not clear whether I can add other non-persistent attributes and methods to these objects. With OO, I can always add subclass data, helper methods, etc.$company_14 = $company->{14}; $company_14->{tax_num} = "123456"; # Wrong example: # $company->{14}->{tax_num} = "123456" # This doesn't work, because it always create a new Row object,
The only thing I can see in favor of having objects as hashes is for quicker glueing with HTML::Template. Of course, I could always add a ->to_hash method to my objects as well ;)
Also, one of my key reasons for doing this module is so that I never have to tell some interface about how my tables are related. With those modules, you have to set up a tied hash for each table, telling it about your primary key and foreign keys. Obviously you could make a wrapper to scan your database and build the appropriate tied hashes, but if my module can do it out of the box, why not? I know there's nothing earth-shattering about this idea, but it's saved me a lot of time along the way.
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Module RFC: Yet another object-persistence interface
by BrowserUk (Patriarch) on Sep 21, 2003 at 04:57 UTC |