in reply to Combined tied-array / object problem

sub test2 { my $self = shift; print tied(@$self)->{ test }, "\n"; # LINE 22 }
BTW a recommendation. It is tempting to think in terms of "This class is X. My object is in the class. Anything I tie is tied to X." This is a trap. You will quickly find great confusion arising from the fact that sometimes you are getting a tied thing, and sometimes you are getting the object behind the tie. Therefore I recommend that you have two classes. One for the object, and a different one to tie it to.

Replies are listed 'Best First'.
Re: Re (tilly) 1: Combined tied-array / object problem
by TheDamian (Vicar) on Nov 12, 2001 at 02:00 UTC
    I would strongly second tilly's recommendation, and not merely so as to avoid confusion.

    There are also bugs in some versions of perl that cause objects that are blessed and tied to the same class not to behave correctly. In some versions destructors are not called consistently on such objects; in others, operator overloading of tied-and-blessed objects is broken.

    The problems seem to vary both from version to version, and from platform to platform. So even if your particular usage works on your particular version of perl on your particular machine, it's unlikely to be temporally or spatially portable.

    I ran into this problem when I was writing Regexp::Common, and quickly decided that the three extra lines needed to implement separate tieable and blessable classes were a very small price to pay to retain my sanity. ;-)