in reply to RE: Re: OO problems
in thread OO problems

According to Damian Conway (master of most things related to bless and a whole lot of things that aren't), it's legal to bless a tied hash into an object.

However, your method doesn't look quite right. You create an anonymous hash, assign its reference to a scalar, and then dereference and bless it. In theory, that should work, but you'll have to do two layers of indirection when trying to get at the tied hash. I think something like the following is more in line with what you want. (Disclaimer: I haven't tried this, and I've never used Apache::Session, but it's a little cleaner.)

sub new { my $class = shift; my $id = shift; my %h = (); tie %h, 'Apache::Session::MySQL', $id { # whatever goes here }; return bless(\%h, $class); }

Replies are listed 'Best First'.
RE: RE: RE: Re: OO problems
by steveAZ98 (Monk) on Jul 24, 2000 at 06:31 UTC
    Thanks, I see what your saying as far as that code goes. It actually acts the same way, but is probably better the way you wrote it.
    I've written a smaller version for debugging and it seems that the problem is in getting Apache::Session to store the lower level data structures before the object goes away. I timestamp it on creation and in DESTROY before I untie it, but it still isn't working for me.
    I'll keep playing and let you know if I figure anything out. It seems to me to be a error on my part of the implementation of Apache::Session, I just have to figure out what it is! :)
    Thanks Again.
RE: RE: RE: Re: OO problems
by steveAZ98 (Monk) on Jul 25, 2000 at 00:28 UTC
    I discovered my problem was in calling new() on an object that already existed in the tied hash and thus overwrote the stored information. I fixed it with the following very simple code. Damn I've been banging my head over this one. Feel so stupid! :)

    sub set_items { $_[0]->{_items} = $_[0]->{_items} || Order->new() }
    Thanks again everyone!