Leslie said:
Thank-you so much for the help!
To carry on...
Using the term 'our variable' to mean 'package variable' is slang.
There's nothing (IMHO) wrong with using it so long as when you introduce
the slang term you also proint out the proper term.
You use the term 'constructor' where you mean 'class method' in the
phrase 'when a method is not a constructor, the first parameter given to
it is not the class, but the blessed object'.
Calling a constuctor on an existing object is generally considered a BAD
THING. Having a constuctor that can be called on an existing object and
does something other than act as a (copy) constructor is an even worse
thing. [...] I now see that that you go on to talk about copy
constructors. IMNSHO you should not mention the idea that a constructor
could also be a instance method until you get to talking about copy
constructors.
print "address: ".$objectref->{address}."\n";
is more idiomatically
print "address: $objectref->{address}\n";
"If we don't want a copy constructor, we can make simple constructors
that can be called from both packages and objects like this"... but it's
bad form to do so, so don't do it.
Using the name super_animal of a subclass of animal is confusing.
(Since SUPER is also used to mean parent class).
The constuct base an rebless paradigm is usually the wrong one.
# 'Wrong'
$objref = animal->new ($name); # Construct base
return bless ($objref, $class);
# 'Right'
$objref = $class->SUPER::new($name)
return $objref;
The difference is that if animal::new internally calls any instance
methods that are overridden in super_animal then in the 'Wrong' example
animal::new will call the methods in animal:: rather than in
super_animal::. Usually this is the wrong thing. Occasionally it is
the right thing in which case the explict construct base and rebless
becomes the right thing.
You say of DESTROY 'If we define it, it will be called when an object
goes out of scope.' This is wrong - it is when there are nolonger any
references to the object. This may be when the variable holding the
last serviving reference goes out of scope, then again it may not.