in reply to classic OO Perl: naming instance variables

In cases where I need to re-bless a hashref from a parent class constructor, I just use a second level hash for my instance data, e.g. $self->{ThisClass}{foo}. I find this easier, because if I have any complicated initialization stuff or just a lot of instance data, I can fiddle around with a separate %data hash and then do $self->{ThisClass} = \%data; when I'm done.

Replies are listed 'Best First'.
Re^2: classic OO Perl: naming instance variables
by j3 (Friar) on Apr 11, 2007 at 16:49 UTC
    In cases where I need to re-bless a hashref from a parent class constructor, {snip}

    Just curious, why would you ever need to re-bless a hashref? I've always figured you bless once, using the 2-arg form, in your base class. Inherited classes use $class->SUPER::new(...) to reach back and have the parent do it.

      You're right, you shouldn't normally have to re-bless; I misspoke. On rare occasions, however, I have had to write a class derived from one that used the incorrect form of bless, in which case re-blessing was required.