Your skill will accomplish what the force of many cannot |
|
PerlMonks |
[SOLVED]: Trying to understand method calling in OOPby Perl300 (Friar) |
on May 07, 2018 at 15:37 UTC ( [id://1214157]=perlquestion: print w/replies, xml ) | Need Help?? |
Perl300 has asked for the wisdom of the Perl Monks concerning the following question: I am going through book "Intermediate Perl" and started with Object Oriented section. I have created a distribution Animal and inside it: bin/pasture
lib/Animal.pm
lib/Cow.pm
lib/Sheep.pm
lib/Horse.pm
When I run ~/localperl/bin/perl -Ilib bin/pasture I get following output:
As per book, explanation of this behavior is: What happens when we invoke Cow−>speak now? First, Perl constructs the argument list. Here, it’s just Cow. Then Perl looks for Cow::speak. That’s not there, so Perl checks for the inheritance array @Cow::ISA. It finds @Cow::ISA contains the single name Animal. Perl next looks for speak inside Animal instead, as in Animal::speak. That found, Perl invokes that method with the already frozen argument list, as if we had said: Animal::speak('Cow'); #This is the part I am having trouble understanding. How did "Cow" become an argument when I didn't specify it anywhere?As I mentioned in comment, I am unable to understand: How did "Cow" become an argument when I didn't specify it anywhere? Can someone please help me understand this behavior? (Forgive me for the long post.)
Back to
Seekers of Perl Wisdom
|
|