in reply to Re^3: Mass Class Confusion - Who calls what how?
in thread Mass Class Confusion - Who calls what how?

This is a much better Perl OO primer than the one I previously linked: https://www.perl.com/article/25/2013/5/20/Old-School-Object-Oriented-Perl/ . (I am glad to see that it sends parameters to functions as a hashtable by reference instead of by value).

But I forgot to mention one important detail. Huge really. If the inherited (child) class has its own constructor (overriding - or more brutally, overwriting - the parent's constructor) then you must call in it the parent's constructor yourself before you do any more initialisation. Like so:

package Child; use parent 'Parent'; sub new { my ($class, $params) = @_; # call parent's constructor first with the given parameters # the parent should ideally filter out the parameters # that do not concern it and ignore them rather than complaining a +bout illegal params my $self = $class->SUPER::new($params); # at this point $self has all Parent's initialisation # (whatever was done and set in its constructor). # Now do local initialisation on $self which is Parent's self (a { +} in most cases) ... $self->{child_extra_property_1} = 12; # for example ... # and bless to Child - actually that's a re-bless because calling # Parent's constructor blessed $self to be an object of class 'Par +ent' # so now make it of class 'Child' bless $self => $class; return $self; }

bw, bliako