diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2001-09-03 12:17:30 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-09-03 12:17:30 +0000 |
commit | 55a1c97c34bea81a888ebe7db8a5607b1b7b9a39 (patch) | |
tree | aaa5e306ca29346cdaa4bb179b3d05ff90a6cfc4 /lib/NEXT | |
parent | efec44ca9b235a3617685a4d7c0d5b1e8d8d2fbd (diff) | |
download | perl-55a1c97c34bea81a888ebe7db8a5607b1b7b9a39.tar.gz |
Damian-o-rama: upgrade to Attribute::Handlers 0.75,
Filter::Simple 0.61, NEXT 0.02, Switch 2.05, and
Text::Balanced 1.86.
p4raw-id: //depot/perl@11842
Diffstat (limited to 'lib/NEXT')
-rw-r--r-- | lib/NEXT/Changes | 22 | ||||
-rw-r--r-- | lib/NEXT/README | 71 | ||||
-rw-r--r-- | lib/NEXT/test.pl | 48 |
3 files changed, 118 insertions, 23 deletions
diff --git a/lib/NEXT/Changes b/lib/NEXT/Changes new file mode 100644 index 0000000000..bb5e27a7b8 --- /dev/null +++ b/lib/NEXT/Changes @@ -0,0 +1,22 @@ +Revision history for Perl extension NEXT.pm. + +0.01 Tue Apr 10 18:27:00 EST 2001 + + - original version + + +0.01 Thu Apr 12 17:06:49 2001 + + - Documented the difference between NEXT and SUPER (thanks Ken) + + + +0.01 Thu Apr 12 17:15:42 2001 + + + +0.02 Mon Sep 3 07:52:27 2001 + + - Fixed setting of $AUTOLOAD in NEXT'd AUTOLOADS (thanks Leonid) + + - Changed licence for inclusion in core distribution diff --git a/lib/NEXT/README b/lib/NEXT/README new file mode 100644 index 0000000000..471b2bb796 --- /dev/null +++ b/lib/NEXT/README @@ -0,0 +1,71 @@ +============================================================================== + Release of version 0.02 of NEXT +============================================================================== + + +NAME + + NEXT - Pseudo class for method redispatch + + +DESCRIPTION + + NEXT.pm adds a pseudoclass named C<NEXT> to any program that + uses it. If a method C<m> calls C<$self->NEXT::m()>, the call to + C<m> 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, left-to-right search of parent classes that + resulted in the original call to C<m>. + + Note that this is not the same thing as C<$self->SUPER::m()>, which + begins a new dispatch that is restricted to searching the ancestors + of the current class. C<$self->NEXT::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. + + 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> + (above it, or to its left) might do better. + + Note that it is a fatal error for any method (including C<AUTOLOAD>) + to attempt to redispatch any method except itself. For example: + + sub D::oops { $_[0]->NEXT::other_method() } # BANG! + + +AUTHOR + + Damian Conway (damian@conway.org) + + +COPYRIGHT + + Copyright (c) 2000-2001, Damian Conway. All Rights Reserved. + This module is free software. It may be used, redistributed + and/or modified under the same terms as Perl itself. + + +============================================================================== + +CHANGES IN VERSION 0.02 + + + - Fixed setting of $AUTOLOAD in NEXT'd AUTOLOADS (thanks Leonid) + + - Changed licence for inclusion in core distribution + + +============================================================================== + +AVAILABILITY + +NEXT has been uploaded to the CPAN +and is also available from: + + http://www.csse.monash.edu.au/~damian/CPAN/NEXT.tar.gz + +============================================================================== diff --git a/lib/NEXT/test.pl b/lib/NEXT/test.pl index 6328fd170c..0ba0b663bf 100644 --- a/lib/NEXT/test.pl +++ b/lib/NEXT/test.pl @@ -1,12 +1,6 @@ #! /usr/local/bin/perl -w - -BEGIN { - chdir 't' if -d 't'; - @INC = '../lib'; -} - -BEGIN { print "1..20\n"; } +BEGIN { print "1..25\n"; } use NEXT; @@ -18,29 +12,32 @@ sub A::DESTROY { $_[0]->NEXT::DESTROY() } package B; use base qw( A ); -sub B::AUTOLOAD { return ( 9, $_[0]->NEXT::AUTOLOAD() ) } +sub B::AUTOLOAD { return ( 9, $_[0]->NEXT::AUTOLOAD() ) + if $AUTOLOAD =~ /.*(missing_method|secondary)/ } sub B::DESTROY { $_[0]->NEXT::DESTROY() } package C; -sub C::DESTROY { print "ok 18\n"; $_[0]->NEXT::DESTROY() } +sub C::DESTROY { print "ok 23\n"; $_[0]->NEXT::DESTROY() } package D; @D::ISA = qw( B C E ); sub D::method { return ( 2, $_[0]->NEXT::method() ) } sub D::AUTOLOAD { return ( 8, $_[0]->NEXT::AUTOLOAD() ) } -sub D::DESTROY { print "ok 17\n"; $_[0]->NEXT::DESTROY() } +sub D::DESTROY { print "ok 22\n"; $_[0]->NEXT::DESTROY() } sub D::oops { $_[0]->NEXT::method() } +sub D::secondary { return ( 17, 18, map { $_+10 } $_[0]->NEXT::secondary() ) } package E; @E::ISA = qw( F G ); sub E::method { return ( 4, $_[0]->NEXT::method(), $_[0]->NEXT::method() ) } -sub E::AUTOLOAD { return ( 10, $_[0]->NEXT::AUTOLOAD() ) } -sub E::DESTROY { print "ok 19\n"; $_[0]->NEXT::DESTROY() } +sub E::AUTOLOAD { return ( 10, $_[0]->NEXT::AUTOLOAD() ) + if $AUTOLOAD =~ /.*(missing_method|secondary)/ } +sub E::DESTROY { print "ok 24\n"; $_[0]->NEXT::DESTROY() } package F; sub F::method { return ( 5 ) } -sub F::AUTOLOAD { return ( 11 ) } -sub F::DESTROY { print "ok 20\n" } +sub F::AUTOLOAD { return ( 11 ) if $AUTOLOAD =~ /.*(missing_method|secondary)/ } +sub F::DESTROY { print "ok 25\n" } package G; sub G::method { return ( 6 ) } @@ -71,19 +68,20 @@ eval { $obj->oops() } && print "not "; print "ok 12\n"; # AUTOLOAD'ED METHOD CAN'T REDISPATCH TO NAMED METHOD (ok 13) -eval q{ - package C; - sub AUTOLOAD { $_[0]->NEXT::method() }; + +eval { + local *C::AUTOLOAD = sub { $_[0]->NEXT::method() }; + *C::AUTOLOAD = *C::AUTOLOAD; + eval { $obj->missing_method(); } && print "not "; }; -eval { $obj->missing_method(); } && print "not "; print "ok 13\n"; # NAMED METHOD CAN'T REDISPATCH TO AUTOLOAD'ED METHOD (ok 14) -eval q{ - package C; - sub method { $_[0]->NEXT::AUTOLOAD() }; +eval { + *C::method = sub{ $_[0]->NEXT::AUTOLOAD() }; + *C::method = *C::method; + eval { $obj->method(); } && print "not "; }; -eval { $obj->method(); } && print "not "; print "ok 14\n"; # BASE CLASS METHODS ONLY REDISPATCHED WITHIN HIERARCHY (ok 15..16) @@ -96,4 +94,8 @@ print "ok 15\n"; print "not " unless @val==1 && $val[0]==9; print "ok 16\n"; -# CAN REDISPATCH DESTRUCTORS (ok 17..20) +# TEST SECONDARY AUTOLOAD REDISPATCH (ok 17..21) +@vals = $obj->secondary(); +print map "ok $_\n", @vals; + +# CAN REDISPATCH DESTRUCTORS (ok 22..25) |