Re: Method invocation arrow (LPORM)

2004-02-09 Thread Randal L. Schwartz
 Jan == Jan Eden [EMAIL PROTECTED] 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
[EMAIL PROTECTED] 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!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Method invocation arrow (LPORM)

2004-02-09 Thread Jeff 'japhy' Pinyan
On Feb 9, Randal L. Schwartz said:

 Jan == Jan Eden [EMAIL PROTECTED] 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. :(

I would have, but I didn't think it necessary.  When the question was
asked, I went to the perlboot doc since I figured that was where the
chapter originated.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
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.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Method invocation arrow (LPORM)

2004-02-08 Thread Randy W. Sims
On 2/7/2004 1:23 PM, James Edward Gray II wrote:

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.
Hmm, I think a good exercise would be to write code snippets to 
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 ...



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Method invocation arrow (LPORM)

2004-02-08 Thread James Edward Gray II
On Feb 8, 2004, at 6:51 AM, Randy W. Sims wrote:

Hmm, I think a good exercise would be to write code snippets to 
demonstrate the differences between the four method calls:

Package::method()
Is this really a method call?  I think of it as a package qualified 
subroutine call.

$class-method()
$class-Package::method()
$class-SUPER::method()
This one should only be used inside an overriden method, I think.

or five if you count:

method Package ...
Let's not.  laughs

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Method invocation arrow (LPORM)

2004-02-07 Thread Jan Eden
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 and nowhere 
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 ~/

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Method invocation arrow (LPORM)

2004-02-07 Thread Jeff 'japhy' Pinyan
On Feb 7, Jan Eden said:

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.

Hopefully I'll answer before Randal. ;)

{   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.

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.

Right.  I was about to say why is it written this way? but then I saw
the rest of the examples (and read the rest of your email).

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);

No, it does not.  If $class is 'Mouse', then

  $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.

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.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
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.  ]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Method invocation arrow (LPORM)

2004-02-07 Thread Jan Eden

Jeff 'japhy' Pinyan wrote:

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.

I see. So Animal just marks the starting point for the search, and it might become 
LivingCreature::speak($class) later on if speak is not found in Animal.

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.

That's exactly the information I was looking for. Thank you, Japhy.

- Jan
-- 
These are my principles and if you don't like them... well, I have others. - Groucho 
Marx

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Method invocation arrow (LPORM)

2004-02-07 Thread James Edward Gray II
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.

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Method invocation arrow (LPORM)

2004-02-07 Thread Jan Eden
James Edward Gray II wrote:

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.

Yes, SUPER:: is introduced just two paragraphs later. I read on, but the uncertainty 
about $class-Animal::speak kept bugging me. ;)

- Jan
-- 
These are my principles and if you don't like them... well, I have others. - Groucho 
Marx

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Method invocation arrow (LPORM)

2004-02-07 Thread Jan Eden
James Edward Gray II wrote:

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.

Yes, SUPER:: is introduced just two paragraphs later. I read on, but the uncertainty 
about $class-Animal::speak kept bugging me. ;)

- Jan
-- 
These are my principles and if you don't like them... well, I have others. - Groucho 
Marx

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Method invocation arrow (LPORM)

2004-02-07 Thread James Edward Gray II
On Feb 7, 2004, at 2:20 PM, Jan Eden wrote:

Yes, SUPER:: is introduced just two paragraphs later. I read on, but 
the uncertainty about $class-Animal::speak kept bugging me. ;)
Excellent.  I figured that was the case, but I was just making sure.

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response