package NEXT;
-$VERSION = '0.51';
+$VERSION = '0.52';
use Carp;
use strict;
-sub ancestors
+sub NEXT::ELSEWHERE::ancestors
{
my @inlist = shift;
my @outlist = ();
unless ($NEXT::NEXT{$self,$wanted_method}) {
my @forebears =
- ancestors ref $self || $self, $wanted_class;
+ NEXT::ELSEWHERE::ancestors ref $self || $self,
+ $wanted_class;
while (@forebears) {
last if shift @forebears eq $caller_class
}
@{$NEXT::NEXT{$self,$wanted_method}} =
map { (*{"${_}::AUTOLOAD"}{CODE}) ? "${_}::AUTOLOAD" : ()} @forebears
unless @{$NEXT::NEXT{$self,$wanted_method}||[]};
- $NEXT::SEEN->{$self,*{$caller}{CODE}}++;
+ $NEXT::SEEN->{$self,*{$caller}{CODE}}++;
}
my $call_method = shift @{$NEXT::NEXT{$self,$wanted_method}};
- while ($wanted_class =~ /^NEXT:.*:UNSEEN/ && defined $call_method
+ while ($wanted_class =~ /^NEXT:.*:(UNSEEN|DISTINCT):/ && defined $call_method
&& $NEXT::SEEN->{$self,$call_method}++) {
$call_method = shift @{$NEXT::NEXT{$self,$wanted_method}};
}
croak qq(Can't locate object method "$wanted_method" ),
qq(via package "$caller_class");
};
- return shift()->$call_method(@_) if ref $call_method eq 'CODE';
+ return $self->$call_method(@_[1..$#_]) if ref $call_method eq 'CODE';
no strict 'refs';
($wanted_method=${$caller_class."::AUTOLOAD"}) =~ s/.*:://
if $wanted_method eq 'AUTOLOAD';
no strict 'vars';
package NEXT::UNSEEN; @ISA = 'NEXT';
+package NEXT::DISTINCT; @ISA = 'NEXT';
package NEXT::ACTUAL; @ISA = 'NEXT';
package NEXT::ACTUAL::UNSEEN; @ISA = 'NEXT';
+package NEXT::ACTUAL::DISTINCT; @ISA = 'NEXT';
package NEXT::UNSEEN::ACTUAL; @ISA = 'NEXT';
+package NEXT::DISTINCT::ACTUAL; @ISA = 'NEXT';
+package EVERY; @ISA = 'NEXT';
1;
To cover such cases, you can redispatch methods via:
- $self->NEXT::UNSEEN::method();
+ $self->NEXT::DISTINCT::method();
rather than:
$self->NEXT::method();
-This causes the redispatcher to skip any classes in the hierarchy that it has
-already visited in an earlier redispatch. So, for example, if the
+This causes the redispatcher to only visit each distinct C<method> method
+once. That is, to skip any classes in the hierarchy that it has
+already visited during redispatch. So, for example, if the
previous example were rewritten:
package A;
- sub foo { print "called A::foo\n"; shift->NEXT::UNSEEN::foo() }
+ sub foo { print "called A::foo\n"; shift->NEXT::DISTINCT::foo() }
package B;
- sub foo { print "called B::foo\n"; shift->NEXT::UNSEEN::foo() }
+ sub foo { print "called B::foo\n"; shift->NEXT::DISTINCT::foo() }
package C; @ISA = qw( A );
- sub foo { print "called C::foo\n"; shift->NEXT::UNSEEN::foo() }
+ sub foo { print "called C::foo\n"; shift->NEXT::DISTINCT::foo() }
package D; @ISA = qw(A B);
- sub foo { print "called D::foo\n"; shift->NEXT::UNSEEN::foo() }
+ sub foo { print "called D::foo\n"; shift->NEXT::DISTINCT::foo() }
package E; @ISA = qw(C D);
- sub foo { print "called E::foo\n"; shift->NEXT::UNSEEN::foo() }
+ sub foo { print "called E::foo\n"; shift->NEXT::DISTINCT::foo() }
E->foo();
called D::foo
called B::foo
-and omit the second call to C<A::foo>.
+and omit the second call to C<A::foo> (since it would not be distinct
+from the first call to C<A::foo>).
Note that you can also use:
- $self->NEXT::UNSEEN::ACTUAL::method();
+ $self->NEXT::DISTINCT::ACTUAL::method();
or:
- $self->NEXT::ACTUAL::UNSEEN::method();
+ $self->NEXT::ACTUAL::DISTINCT::method();
to get both unique invocation I<and> exception-on-failure.
+Note that, for historical compatibility, you can also use
+C<NEXT::UNSEEN> instead of C<NEXT::DISTINCT>.
=head1 AUTHOR
==============================================================================
- Release of version 0.50 of NEXT
+ Release of version 0.52 of NEXT
==============================================================================
the current class -- to look for a suitable method in other
ancestors of C<$self> -- whereas C<$self->SUPER::m()> cannot.
- A particularly interesting use of redispatch is in
+ An particularly interesting use of redispatch is in
C<AUTOLOAD>'ed methods. If such a method determines that it is
not able to handle a particular call, it may choose to
redispatch that call, in the hope that some other C<AUTOLOAD>
==============================================================================
-CHANGES IN VERSION 0.50
+CHANGES IN VERSION 0.52
- - Added a $VERSION (oops!)
-
- - Fixed handling of diamond patterns (thanks Paul)
-
- - Added NEXT::ACTUAL to require existence of next method (thanks Paul)
-
- - Added NEXT::UNSEEN to avoid calling multiply inherited
- methods twice (thanks Paul)
-
- - Re-fixed setting of $AUTOLOAD in NEXT'd AUTOLOADS to be
- consistent with more useful SUPER:: behaviour
-
- - Corified tests
==============================================================================
AVAILABILITY
NEXT has been uploaded to the CPAN
-and is also available from:
-
- http://www.csse.monash.edu.au/~damian/CPAN/NEXT.tar.gz
==============================================================================