X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FNEXT.pm;h=51dec919640d9692d13de015990e19b7b8f1fa37;hb=50109ad0d28b27abe5ee82def070e14b4526321c;hp=5738f5cfe22f6b362e04f4e4d2b1820c5e45d7a2;hpb=bf5734d48cfc03fbca4e85c5e0afdb1758ace04f;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/NEXT.pm b/lib/NEXT.pm index 5738f5c..51dec91 100644 --- a/lib/NEXT.pm +++ b/lib/NEXT.pm @@ -1,5 +1,5 @@ package NEXT; -$VERSION = '0.60'; +$VERSION = '0.60_01'; use Carp; use strict; @@ -32,7 +32,9 @@ sub NEXT::ELSEWHERE::ordered_ancestors sub AUTOLOAD { my ($self) = @_; - my $caller = (caller(1))[3]; + my $depth = 1; + until ((caller($depth))[3] !~ /^\(eval\)$/) { $depth++ } + my $caller = (caller($depth))[3]; my $wanted = $NEXT::AUTOLOAD || 'NEXT::AUTOLOAD'; undef $NEXT::AUTOLOAD; my ($caller_class, $caller_method) = $caller =~ m{(.*)::(.*)}g; @@ -94,7 +96,9 @@ package EVERY; @ISA = 'NEXT'; sub AUTOLOAD { my ($self) = @_; - my $caller = (caller(1))[3]; + my $depth = 1; + until ((caller($depth))[3] !~ /^\(eval\)$/) { $depth++ } + my $caller = (caller($depth))[3]; my $wanted = $EVERY::AUTOLOAD || 'EVERY::AUTOLOAD'; undef $EVERY::AUTOLOAD; my ($wanted_class, $wanted_method) = $wanted =~ m{(.*)::(.*)}g; @@ -201,18 +205,18 @@ NEXT.pm - Provide a pseudo-class NEXT (et al) that allows method redispatch =head1 DESCRIPTION NEXT.pm adds a pseudoclass named C to any program -that uses it. If a method C calls C<$self->NEXT::m()>, the call to +that uses it. If a method C calls C<$self-ENEXT::m()>, the call to C is redispatched as if the calling method had not originally been found. -In other words, a call to C<$self->NEXT::m()> resumes the depth-first, +In other words, a call to C<$self-ENEXT::m()> resumes the depth-first, left-to-right search of C<$self>'s class hierarchy that resulted in the original call to C. -Note that this is not the same thing as C<$self->SUPER::m()>, which +Note that this is not the same thing as C<$self-ESUPER::m()>, which begins a new dispatch that is restricted to searching the ancestors -of the current class. C<$self->NEXT::m()> can backtrack +of the current class. C<$self-ENEXT::m()> can backtrack past the current class -- to look for a suitable method in other -ancestors of C<$self> -- whereas C<$self->SUPER::m()> cannot. +ancestors of C<$self> -- whereas C<$self-ESUPER::m()> cannot. A typical use would be in the destructors of a class hierarchy, as illustrated in the synopsis above. Each class in the hierarchy @@ -229,7 +233,7 @@ do better. By default, if a redispatch attempt fails to find another method elsewhere in the objects class hierarchy, it quietly gives up and does -nothing (but see L<"Enforcing redispatch">). This gracious acquiesence +nothing (but see L<"Enforcing redispatch">). This gracious acquiescence is also unlike the (generally annoying) behaviour of C, which throws an exception if it cannot redispatch. @@ -416,7 +420,7 @@ order. Instead, they are called "breadth-first-dependency-wise". That means that the inheritance tree of the object is traversed breadth-first and the resulting order of classes is used as the sequence in which methods are called. However, that sequence is modified by imposing a rule that the -appropritae method of a derived class must be called before the same method of +appropriate method of a derived class must be called before the same method of any ancestral class. That's why, in the above example, C is called before C, even though C comes before C in C<@B::ISA>.