Ask a Question related to PERL Beginners, Design and Development.
-
Jan Eden #1
Method invocation arrow (LPORM)
Hi all,
I just work my way through "Learning Perl Objects, References & Modules". Now at one point, I am stuck: Randal introduces classes and methods in Chapter 8.
He gives the following example for overriding methods:
{ package Mouse
@ISA = qw{Animal};
...
sub speak {
my $class = shift;
...
Animal::speak($class);
...
}
}
Since there is a method speak in Mouse, it would override the parent's classes method Animal::speak if the latter were not called explicitly.
But, as Randal points out, this forces Perl to look for speak in Animal andnowhere else - without the method invocation arrow, it cannot check @ISA for ancestor classes.
So far, I get the point. But then he introduces the following solution:
$class->Animal::speak(@_);
Apart from the fact that @_ should be unnecessary here (or did I get something wrong), this should expand to:
Mouse::Animal::speak("Mouse");
And when Perl does not find Animal::speak in Mouse, to:
Animal::Animal::speak("Mouse";
and to higher classes if speak is not found there. Now my question:
Does Perl reduce Animal::Animal::speak("Mouse") automatically to Animal::speak("Mouse"). And, if speak is not in Animal, how does it handle an expression like:
LivingCreature::Animal::speak("Mouse");
It seems to me that the hard-coded package name we got rid of by using method calls just got back into our syntax. At the same time, I am sure the code works (have not tried it yet) and Perl does as it should.
But how does this work?
Thanks for any explanations,
Jan
--
There's no place like ~/
Jan Eden Guest
-
AxisFault errors in Web Service Invocation
I've got a web service set up for consumption but the only returnType that I can get to work is numeric. All other returnTypes in the cffunction tag... -
Web Service invocation from behind proxy behind firewall
hi, i have a webservice and it's client in dotnet. the client is coded to assign the proxy property to the service object, with the proxy url and... -
Replacement for PerlCOM.Script invocation
According to ActivateState tech support, the latest versions of Perl and PDK no longer support the ability to create an instance of a Perl... -
Is there any Web Services Invocation Framework for .NET
Is there any .NET equivalent of the Web Services Invocation Framework for java ??? (Web Services Invocation Framework (WSIF) is a Java API that... -
Help with left arrow down & right arrow down
Hi all, I am creating a presentation in Director MX, and need to program the right arrow key to advance to next marker, and the left arrow key to... -
Jeff 'Japhy' Pinyan #2
Re: Method invocation arrow (LPORM)
On Feb 7, Jan Eden said:
Hopefully I'll answer before Randal. ;)>I just work my way through "Learning Perl Objects, References & Modules".
>Now at one point, I am stuck: Randal introduces classes and methods in
>Chapter 8.
I was about to ask why it's written this way, but upon checking the>{ package Mouse
> @ISA = qw{Animal};
> ...
> sub speak {
> my $class = shift;
> ...
> Animal::speak($class);
> ...
> }
>}
source, I see that this is the way the first example on overriding a
method looks.
Right. I was about to say "why is it written this way?" but then I saw>Since there is a method speak in Mouse, it would override the parent's
>classes method Animal::speak if the latter were not called explicitly.
>
>But, as Randal points out, this forces Perl to look for speak in Animal
>and nowhere else - without the method invocation arrow, it cannot check
>@ISA for ancestor classes.
the rest of the examples (and read the rest of your email).
No, it does not. If $class is 'Mouse', then>So far, I get the point. But then he introduces the following solution:
>
>$class->Animal::speak(@_);
>
>Apart from the fact that @_ should be unnecessary here (or did I get
>something wrong), this should expand to:
>
>Mouse::Animal::speak("Mouse");
$class->method(@_);
will try looking for Mouse::method(), and if not, it will look through
Mouse's @ISA for a class that DOES supply method(). BUT HERE, we're using
$class->OtherClass::method(@_);
which says explicitly to start looking for method() in OtherClass (and if
it fails there, look in OtherClass's @ISA). So
$class->Animal::speak();
in your case becomes
Animal::speak($class);
except that it becomes that DYNAMICALLY.
Ah, here's the confusion. This isn't looking for a method named>And when Perl does not find Animal::speak in Mouse, to:
'Animal::speak' in 'Mouse'; it's looking for a method named 'speak' in
'Animal'.
Only the right-most part of a Thing::Like::this denotes the name of a
method.
--
Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
Jeff 'Japhy' Pinyan Guest
-
Jan Eden #3
Re: Method invocation arrow (LPORM)
Jeff 'japhy' Pinyan wrote:
I see. So Animal just marks the starting point for the search, and it mightbecome LivingCreature::speak($class) later on if speak is not found in Animal.>BUT HERE, we're using
>
>$class->OtherClass::method(@_);
>
>which says explicitly to start looking for method() in OtherClass
>(and if it fails there, look in OtherClass's @ISA). So
>
>$class->Animal::speak();
>
>in your case becomes
>
>Animal::speak($class);
>
>except that it becomes that DYNAMICALLY.That's exactly the information I was looking for. Thank you, Japhy.>>>>And when Perl does not find Animal::speak in Mouse, to:
>Ah, here's the confusion. This isn't looking for a method named
>'Animal::speak' in 'Mouse'; it's looking for a method named 'speak'
>in 'Animal'.
>
>Only the right-most part of a Thing::Like::this denotes the name of
>a method.
- Jan
--
These are my principles and if you don't like them... well, I have others. - Groucho Marx
Jan Eden Guest
-
James Edward Gray II #4
Re: Method invocation arrow (LPORM)
On Feb 7, 2004, at 10:02 AM, Jeff 'japhy' Pinyan wrote:
I was going to ask this too. I'm glad I finished reading the email.> On Feb 7, Jan Eden said:
>>>> { package Mouse
>> @ISA = qw{Animal};
>> ...
>> sub speak {
>> my $class = shift;
>> ...
>> Animal::speak($class);
>> ...
>> }
>> }
> I was about to ask why it's written this way, but upon checking the
> source, I see that this is the way the first example on overriding a
> method looks.
I'm not familiar with the book though, so I will ask this? Does it
eventually go on to introduce SUPER::? That's what I would prefer here
and I just want to make sure you're aware of the option.
James
James Edward Gray II Guest
-
Jan Eden #5
Re: Method invocation arrow (LPORM)
James Edward Gray II wrote:
Yes, SUPER:: is introduced just two paragraphs later. I read on, but the uncertainty about $class->Animal::speak kept bugging me. ;)>On Feb 7, 2004, at 10:02 AM, Jeff 'japhy' Pinyan wrote:
>>>> On Feb 7, Jan Eden said:
>>>>>>> { package Mouse
>>> @ISA = qw{Animal};
>>> ...
>>> sub speak {
>>> my $class = shift;
>>> ...
>>> Animal::speak($class);
>>> ...
>>> }
>>> }
>> I was about to ask why it's written this way, but upon checking the
>> source, I see that this is the way the first example on overriding a
>> method looks.
>I was going to ask this too. I'm glad I finished reading the email.
>
>I'm not familiar with the book though, so I will ask this? Does it
>eventually go on to introduce SUPER::? That's what I would prefer here
>and I just want to make sure you're aware of the option.
- Jan
--
These are my principles and if you don't like them... well, I have others. - Groucho Marx
Jan Eden Guest
-
Jan Eden #6
Re: Method invocation arrow (LPORM)
James Edward Gray II wrote:
Yes, SUPER:: is introduced just two paragraphs later. I read on, but the uncertainty about $class->Animal::speak kept bugging me. ;)>On Feb 7, 2004, at 10:02 AM, Jeff 'japhy' Pinyan wrote:
>>>> On Feb 7, Jan Eden said:
>>>>>>> { package Mouse
>>> @ISA = qw{Animal};
>>> ...
>>> sub speak {
>>> my $class = shift;
>>> ...
>>> Animal::speak($class);
>>> ...
>>> }
>>> }
>> I was about to ask why it's written this way, but upon checking the
>> source, I see that this is the way the first example on overriding a
>> method looks.
>I was going to ask this too. I'm glad I finished reading the email.
>
>I'm not familiar with the book though, so I will ask this? Does it
>eventually go on to introduce SUPER::? That's what I would prefer here
>and I just want to make sure you're aware of the option.
- Jan
--
These are my principles and if you don't like them... well, I have others. - Groucho Marx
Jan Eden Guest
-
James Edward Gray II #7
Re: Method invocation arrow (LPORM)
On Feb 7, 2004, at 2:20 PM, Jan Eden wrote:
Excellent. I figured that was the case, but I was just making sure.> Yes, SUPER:: is introduced just two paragraphs later. I read on, but
> the uncertainty about $class->Animal::speak kept bugging me. ;)
James
James Edward Gray II Guest
-
Randy W. Sims #8
Re: Method invocation arrow (LPORM)
On 2/7/2004 1:23 PM, James Edward Gray II wrote:
Hmm, I think a good exercise would be to write code snippets to> On Feb 7, 2004, at 10:02 AM, Jeff 'japhy' Pinyan wrote:
>>>> On Feb 7, Jan Eden said:
>>>>>>> { package Mouse
>>> @ISA = qw{Animal};
>>> ...
>>> sub speak {
>>> my $class = shift;
>>> ...
>>> Animal::speak($class);
>>> ...
>>> }
>>> }
>>
>> I was about to ask why it's written this way, but upon checking the
>> source, I see that this is the way the first example on overriding a
>> method looks.
>
> I was going to ask this too. I'm glad I finished reading the email.
>
> I'm not familiar with the book though, so I will ask this? Does it
> eventually go on to introduce SUPER::? That's what I would prefer here
> and I just want to make sure you're aware of the option.
demonstrate the differences between the four method calls:
Package::method()
$class->method()
$class->Package::method()
$class->SUPER::method()
or five if you count:
method Package ...
Randy W. Sims Guest
-
James Edward Gray II #9
Re: Method invocation arrow (LPORM)
On Feb 8, 2004, at 6:51 AM, Randy W. Sims wrote:
Is this really a "method call"? I think of it as a package qualified> Hmm, I think a good exercise would be to write code snippets to
> demonstrate the differences between the four method calls:
>
> Package::method()
subroutine call.
This one should only be used inside an overriden method, I think.> $class->method()
> $class->Package::method()
> $class->SUPER::method()
Let's not. <laughs>> or five if you count:
>
> method Package ...
James
James Edward Gray II Guest
-
Randal L. Schwartz #10
Re: Method invocation arrow (LPORM)
>>>>> "Jan" == Jan Eden <lists@jan-eden.de> writes:
Jan> Yes, SUPER:: is introduced just two paragraphs later. I read on, but the uncertainty about $class->Animal::speak kept bugging me. ;)
Thank you for the feedback. I'll note that for a future edition of the book.
That's also very similar to the way I have it in "perlboot", but nobody
noted it there yet. :(
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Randal L. Schwartz Guest
-
Jeff 'Japhy' Pinyan #11
Re: Method invocation arrow (LPORM)
On Feb 9, Randal L. Schwartz said:
I would have, but I didn't think it necessary. When the question was>>>>>>> "Jan" == Jan Eden <lists@jan-eden.de> writes:
>Jan> Yes, SUPER:: is introduced just two paragraphs later. I read on, but the uncertainty about $class->Animal::speak kept bugging me. ;)
>
>Thank you for the feedback. I'll note that for a future edition of the book.
>That's also very similar to the way I have it in "perlboot", but nobody
>noted it there yet. :(
asked, I went to the perlboot doc since I figured that was where the
chapter originated.
--
Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
Jeff 'Japhy' Pinyan Guest



Reply With Quote

