in reply to Reverse Inheritance Irritance
Without that bless, any attempts in call member functions would cause the search for that function to begin at the parent (overridden) class. Not what you want if you're going to be adding your own behavior in a subclass.... preamble as before use strict; my $_count = 0; # count of instances created sub new { my $package = shift; my $self = SUPER::new(@_); # The class we inherit from counts its instances. # Since we're really creating one of us, adjust # its count downward, then point the object at # our counter. ${$self->{_count}}--; $_count++; $self->{_count} = \$_count; bless $self, $package; }
(I assume that you've examined the class you're overridding, and that swaping out $self->{_count} won't have any unfortunate side-effects.)
|
|---|