in reply to inheritance problems
You are using the single-argument form of bless, which does not bless $bob into the class Manager:
my $bob = Manager->new_worker(name => "Bob", age => 40); print $bob,"\n"; # Worker=HASH(0x15debec)
To properly enable inheritance, you must also properly bless every object into the right class. I don't know where you copied your constructor from, but you shouldn't throw away the package name to use (you put it into $invocant), but pass it to bless as the second argument:
sub new_worker { ## Constructor. my $invocant = shift; # my $class = ref($invocant); my $self = { name => "Jhon Do", age => 32, @_ , }; bless $self, $invocant; return $self; };
Also, you should consider renaming your new_worker method to new, as is customary with constructors.
|
|---|