I have these two modules :
package G1;
sub new {
my $class = shift;
my $self = {
one => 1,
two => 2,
three => 3
};
bless $self,$class;
return $self;
}
sub three {
my $self = shift;
print "G1 green is ",$self->{three};
}
1;
package G2;
our @ISA = qw(G1);
#use base qw(G1);
sub new {
my $class = shift;
my $self = $class->SUPER::new();
$self->{three} = 90;
bless $self,$class;
return $self;
}
sub three {
my $self = shift;
print "G2 rox!\n";
$self->SUPER::three();
}
1;
and the following script:
use G2;
my $ob = G2->new();
$ob->three();
When I run the script, it produces the following error :
Can't locate object method "new" via package "G2" at G2.pm line 8.
If I replace the @ISA
line with use base
, the script works. I'm trying to override some methods and call the original ones after. What am I doing wrong?