I have the following code :-
package A;
sub new{
//constructor for A
}
sub hello{
print "Hello A";
}
1;
package B;
use base qw(A);
sub hello{
print "Hello B";
}
1;
My question is how can I instantiate B i.e. my $b = B->new(), without giving a constructor to B, what changes do I need to do in A to achieve this. Is this possible ?
Thanks.
Yes. Use this as
A‘snewmethod:The key is that when using
B->new, the first argument isB(which I bound to$clsin my example). So if you callblessusing$cls, the object will be blessed with the correct package.