P
Piet
Hello,
I just started with OO Programming in Perl and stumbled over some
behaviour that I would like to understand.
When running the following code:
use strict;
print Cow->sound."\n";
Cow->speak;
{package Cow;
use vars qw(@ISA);
@ISA = qw(Animal);
sub sound {"moooh"};
}
{package Animal;
sub sound {"some undefined noise"};
sub speak {
my $class = $_[0];
print "A $class makes ",$class->sound," !\n";
};
}
it turns out that the class method is correctly invoked, but the class
method of the superclass is not found. However, when I put
"Cow->speak" at the end (i. e. after the package definitions), I get
the expected output. Normally, I would put any code after the package
imports and definitions, in which case the behaviour described above
would not have shown up. But I am still interested in your
explanations: Why is the class method found, while the inheritance
tree is NOT climbed up?
Thanks for any hints.
Piet
I just started with OO Programming in Perl and stumbled over some
behaviour that I would like to understand.
When running the following code:
use strict;
print Cow->sound."\n";
Cow->speak;
{package Cow;
use vars qw(@ISA);
@ISA = qw(Animal);
sub sound {"moooh"};
}
{package Animal;
sub sound {"some undefined noise"};
sub speak {
my $class = $_[0];
print "A $class makes ",$class->sound," !\n";
};
}
it turns out that the class method is correctly invoked, but the class
method of the superclass is not found. However, when I put
"Cow->speak" at the end (i. e. after the package definitions), I get
the expected output. Normally, I would put any code after the package
imports and definitions, in which case the behaviour described above
would not have shown up. But I am still interested in your
explanations: Why is the class method found, while the inheritance
tree is NOT climbed up?
Thanks for any hints.
Piet