When you dosub new { my $class = shift; my $self = $class->SUPER::new(); $self->{SALARY} = undef; $self->{ID} = undef; $self->{START_DATE} = undef; bless ($self, $class); # reconsecrate return $self; }
the $self returned bymy $emp = Employee->new;
will be blessed into the Person package, so to be able to call the methods that Employee has beyond those in Person, $self needs to be reblessed into the class that Employee::new was invoked on (i.e. Employee or a subclass of it).my $self = $class->SUPER::new();
Update
The answer above would apply if the first version of Person::new() in perltoot (i.e. the one that doesn't bless $self into $class) were being used. As ikegami points out, the rebless isn't needed if Person::new() does bless $self into $class.In reply to Re: To bless or not to bless
by Arunbear
in thread To bless or not to bless
by LesleyB
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |