Quick explanation of why that works:
- In Perl, an object is a reference which has been tied to a particular package (class) by blessing it.
- When you call $object->foo, it executes sub foo from the package that $object has been blessed into - package eva if it's an eva object or package person if it's a base person object.
- When you call just plain foo, it executes sub foo from the package in which the calling code was defined. Since myname is defined in package person (and not overridden), it will always call person::name regardless of the object's class.
- If your methods used parameters or $self, you would have also noticed another difference: $object->foo implicitly passed $object as its first parameter (so it can be used to populate $self), but just plain foo does not. This can, obviously, cause issues if your methods use $self or parameters, so you should always call them as either $object->foo if you want them to be polymorphic or class->foo if you want to lock them to a specific class's implementation.
| [reply] [d/l] [select] |