in reply to Re: Solving the SUPER problem in Mixins with a Dispatch Method
in thread Solving the SUPER problem in Mixins with a Dispatch Method

At the risk of breaking ranks here, I will attempt to help actually answer your question ...

*grin*

Does anyone know how to reliably extract the name of the calling method, so that I can ommit that from the calls to the NEXT method?
While I understand your hesitancy with AUTOLOAD, it would remove this entire problem.

Perhaps we're not talking about the same "problem."

The built-in syntax for an empty wrapper is:

sub compile { (shift)->SUPER::compile(@_) }

The syntax I'm currently using is:

sub compile { (shift)->NEXT('compile', @_) }

What I'm hoping for is to omit the method name and have it picked up from context:

sub compile { (shift)->NEXT(@_) }

All of the AUTOLOADed solutions seem like they'll still require the current method name to be specified:

sub compile { (shift)->SUPER::DISPATCH::compile(@_) }

Admittedly, it's a minor point, but if you're going to have a rule that says that you can't redispatch to a different method name, it seems gauche to make the caller write out the method name again.

Replies are listed 'Best First'.
Re^3: Solving the SUPER problem in Mixins with a Dispatch Method
by stvn (Monsignor) on Oct 14, 2004 at 18:20 UTC
    Perhaps we're not talking about the same "problem."

    You are right, we were not. Sorry, only had one cup of coffee when I wrote that (hence the sarcasm and bitterness). However, I have now had more than one cup of coffee and I think this might help you.

    #!/usr/bin/perl use strict; use warnings; { package MyObject::Base; sub NEXT { my ($self, @args) = @_; my ($package, $filename, $subroutine); my $i = 1; ($package, $filename, undef, $subroutine) = caller($i); while ($subroutine eq '(eval)' || $filename eq '(eval)') { ($package, $filename, undef, $subroutine) = caller(++$i); } print "NEXT was called from : $subroutine\n"; } package MyObject; our @ISA = ('MyObject::Base'); sub compile1 { (shift)->NEXT(@_) } sub compile2 { eval { (shift)->NEXT(@_) } } sub compile3 { eval { eval { (shift)->NEXT(@_) } } } sub compile4 { my $self = shift; eval '$self->NEXT(@_)' } sub compile5 { my $self = shift; eval 'eval "$self->NEXT(\@_)"' } + sub compile6 { my $self = shift; eval { eval { eval { eval 'eval { eval "\$self->NEXT(\@_)" }' } } } } } MyObject->compile1(); MyObject->compile2(); MyObject->compile3(); MyObject->compile4(); MyObject->compile5(); MyObject->compile6(); __OUTPUT__ NEXT was called from : MyObject::compile1 NEXT was called from : MyObject::compile2 NEXT was called from : MyObject::compile3 NEXT was called from : MyObject::compile4 NEXT was called from : MyObject::compile5 NEXT was called from : MyObject::compile6

    -stvn