Can't call NEXT::f from B::g

V

Victor Porton

$ perl test.pl
Can't call NEXT::f from B::g at /home/porton/t/test2.pl line 10

Why the error?

#!/usr/bin/perl -w

use NEXT;

package A;
sub f { print "123\n" }

package B;
use base 'A';
sub g { shift->NEXT::f }

B->g;
 
P

Peter Makholm

Victor Porton said:
$ perl test.pl
Can't call NEXT::f from B::g at /home/porton/t/test2.pl line 10

Why the error?

Doesn't the following except from the documentation to NEXT explains
it?

Note that it is a fatal error for any method (including "AUTOLOAD") to
attempt to redispatch any method that does not have the same name. For
example:

sub D::eek:ops { print "oops!\n"; $_[0]->NEXT::eek:ther_method() }

//Makholm
 
V

Victor Porton

Victor Porton said:
$ perl test.pl
Can't call NEXT::f from B::g at /home/porton/t/test2.pl line 10
Why the error?

Doesn't the following except from the documentation to NEXT explains
it?

Note that it is a fatal error for any method (including "AUTOLOAD") to
attempt to redispatch any method that does not have the same name. For
example:

sub D::eek:ops { print "oops!\n"; $_[0]->NEXT::eek:ther_method() }

Yes, that was my error.

New question: Why the below script does not print "123"?

#!/usr/bin/perl -w

use NEXT;

package A;
sub f { print "123\n" }

package B;
use base 'A';

package C;
use base 'B';
sub f { shift->NEXT::f }

C->f;
 
M

Michele Dondi

package A;
sub f { print "123\n" }

package B;
use base 'A';

Incidentally, base.pm does more than you expect. You may want to just
set @ISA manually in this case.

Moreover, base.pm is regarded as buggy by some.

Moreover, do not try to use B as a generic namespace, since it
actually exists. In fact when I stumbled upon your subject, I thought
it had to do with Perl's opcodes...


Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top