diff options
author | Neil Bowers <neil@bowers.com> | 2016-08-05 19:42:15 -0400 |
---|---|---|
committer | James E Keenan <jkeenan@cpan.org> | 2016-08-05 19:42:15 -0400 |
commit | c8321e06185aa02d661de31e6bb8bf811e513fab (patch) | |
tree | 9166d32883e156834706b5e7aabd325474700438 | |
parent | ce4eed6e1984031febd07595f263c245cb51c951 (diff) | |
download | perl-c8321e06185aa02d661de31e6bb8bf811e513fab.tar.gz |
Update NEXT to CPAN version 0.67.
-rwxr-xr-x | Porting/Maintainers.pl | 2 | ||||
-rw-r--r-- | cpan/NEXT/lib/NEXT.pm | 78 |
2 files changed, 47 insertions, 33 deletions
diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl index 66c630ace1..dde2d5bc10 100755 --- a/Porting/Maintainers.pl +++ b/Porting/Maintainers.pl @@ -955,7 +955,7 @@ use File::Glob qw(:case); }, 'NEXT' => { - 'DISTRIBUTION' => 'FLORA/NEXT-0.65.tar.gz', + 'DISTRIBUTION' => 'NEILB/NEXT-0.67.tar.gz', 'FILES' => q[cpan/NEXT], 'EXCLUDED' => [qr{^demo/}], }, diff --git a/cpan/NEXT/lib/NEXT.pm b/cpan/NEXT/lib/NEXT.pm index a77bb38743..cb87fb659b 100644 --- a/cpan/NEXT/lib/NEXT.pm +++ b/cpan/NEXT/lib/NEXT.pm @@ -1,9 +1,12 @@ package NEXT; -$VERSION = '0.65'; + use Carp; use strict; +use warnings; use overload (); +our $VERSION = '0.67'; + sub NEXT::ELSEWHERE::ancestors { my @inlist = shift; @@ -108,7 +111,8 @@ package NEXT::ACTUAL::DISTINCT; @ISA = 'NEXT'; NEXT::ELSEWHERE::buildAUTOLOAD(); package NEXT::UNSEEN::ACTUAL; @ISA = 'NEXT'; NEXT::ELSEWHERE::buildAUTOLOAD(); package NEXT::DISTINCT::ACTUAL; @ISA = 'NEXT'; NEXT::ELSEWHERE::buildAUTOLOAD(); -package EVERY; +package + EVERY; sub EVERY::ELSEWHERE::buildAUTOLOAD { my $autoload_name = caller() . '::AUTOLOAD'; @@ -182,7 +186,8 @@ sub EVERY::ELSEWHERE::buildAUTOLOAD { } package EVERY::LAST; @ISA = 'EVERY'; EVERY::ELSEWHERE::buildAUTOLOAD(); -package EVERY; @ISA = 'NEXT'; EVERY::ELSEWHERE::buildAUTOLOAD(); +package + EVERY; @ISA = 'NEXT'; EVERY::ELSEWHERE::buildAUTOLOAD(); 1; @@ -190,50 +195,54 @@ __END__ =head1 NAME -NEXT.pm - Provide a pseudo-class NEXT (et al) that allows method redispatch - +NEXT - Provide a pseudo-class NEXT (et al) that allows method redispatch =head1 SYNOPSIS use NEXT; - package A; - sub A::method { print "$_[0]: A method\n"; $_[0]->NEXT::method() } - sub A::DESTROY { print "$_[0]: A dtor\n"; $_[0]->NEXT::DESTROY() } + package P; + sub P::method { print "$_[0]: P method\n"; $_[0]->NEXT::method() } + sub P::DESTROY { print "$_[0]: P dtor\n"; $_[0]->NEXT::DESTROY() } - package B; - use base qw( A ); - sub B::AUTOLOAD { print "$_[0]: B AUTOLOAD\n"; $_[0]->NEXT::AUTOLOAD() } - sub B::DESTROY { print "$_[0]: B dtor\n"; $_[0]->NEXT::DESTROY() } + package Q; + use base qw( P ); + sub Q::AUTOLOAD { print "$_[0]: Q AUTOLOAD\n"; $_[0]->NEXT::AUTOLOAD() } + sub Q::DESTROY { print "$_[0]: Q dtor\n"; $_[0]->NEXT::DESTROY() } - package C; - sub C::method { print "$_[0]: C method\n"; $_[0]->NEXT::method() } - sub C::AUTOLOAD { print "$_[0]: C AUTOLOAD\n"; $_[0]->NEXT::AUTOLOAD() } - sub C::DESTROY { print "$_[0]: C dtor\n"; $_[0]->NEXT::DESTROY() } + package R; + sub R::method { print "$_[0]: R method\n"; $_[0]->NEXT::method() } + sub R::AUTOLOAD { print "$_[0]: R AUTOLOAD\n"; $_[0]->NEXT::AUTOLOAD() } + sub R::DESTROY { print "$_[0]: R dtor\n"; $_[0]->NEXT::DESTROY() } - package D; - use base qw( B C ); - sub D::method { print "$_[0]: D method\n"; $_[0]->NEXT::method() } - sub D::AUTOLOAD { print "$_[0]: D AUTOLOAD\n"; $_[0]->NEXT::AUTOLOAD() } - sub D::DESTROY { print "$_[0]: D dtor\n"; $_[0]->NEXT::DESTROY() } + package S; + use base qw( Q R ); + sub S::method { print "$_[0]: S method\n"; $_[0]->NEXT::method() } + sub S::AUTOLOAD { print "$_[0]: S AUTOLOAD\n"; $_[0]->NEXT::AUTOLOAD() } + sub S::DESTROY { print "$_[0]: S dtor\n"; $_[0]->NEXT::DESTROY() } package main; - my $obj = bless {}, "D"; + my $obj = bless {}, "S"; - $obj->method(); # Calls D::method, A::method, C::method - $obj->missing_method(); # Calls D::AUTOLOAD, B::AUTOLOAD, C::AUTOLOAD + $obj->method(); # Calls S::method, P::method, R::method + $obj->missing_method(); # Calls S::AUTOLOAD, Q::AUTOLOAD, R::AUTOLOAD - # Clean-up calls D::DESTROY, B::DESTROY, A::DESTROY, C::DESTROY + # Clean-up calls S::DESTROY, Q::DESTROY, P::DESTROY, R::DESTROY =head1 DESCRIPTION -NEXT.pm adds a pseudoclass named C<NEXT> to any program +The C<NEXT> module adds a pseudoclass named C<NEXT> to any program that uses it. If a method C<m> calls C<$self-E<gt>NEXT::m()>, the call to C<m> is redispatched as if the calling method had not originally been found. +B<Note:> before using this module, +you should look at L<next::method|https://metacpan.org/pod/mro#next::method> +in the core L<mro> module. +C<mro> has been a core module since Perl 5.9.5. + In other words, a call to C<$self-E<gt>NEXT::m()> resumes the depth-first, left-to-right search of C<$self>'s class hierarchy that resulted in the original call to C<m>. @@ -245,10 +254,10 @@ past the current class -- to look for a suitable method in other ancestors of C<$self> -- whereas C<$self-E<gt>SUPER::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 +as illustrated in the SYNOPSIS above. Each class in the hierarchy has a DESTROY method that performs some class-specific action and then redispatches the call up the hierarchy. As a result, -when an object of class D is destroyed, the destructors of I<all> +when an object of class S is destroyed, the destructors of I<all> its parent classes are called (in depth-first, left-to-right order). Another typical use of redispatch would be in C<AUTOLOAD>'ed methods. @@ -267,7 +276,7 @@ Note that it is a fatal error for any method (including C<AUTOLOAD>) to attempt to redispatch any method that does not have the same name. For example: - sub D::oops { print "oops!\n"; $_[0]->NEXT::other_method() } + sub S::oops { print "oops!\n"; $_[0]->NEXT::other_method() } =head2 Enforcing redispatch @@ -384,7 +393,7 @@ previous example were rewritten: E->foo(); then it would print: - + called E::foo called C::foo called A::foo @@ -410,7 +419,7 @@ C<NEXT::UNSEEN> instead of C<NEXT::DISTINCT>. =head2 Invoking all versions of a method with a single call -Yet another pseudo-class that NEXT.pm provides is C<EVERY>. +Yet another pseudo-class that C<NEXT> provides is C<EVERY>. Its behaviour is considerably simpler than that of the C<NEXT> family. A call to: @@ -540,6 +549,11 @@ behaviour simply adds its own C<Init> method (I<not> a C<new> method), which the call to C<EVERY::LAST::Init> in the inherited constructor then correctly picks up. +=head1 SEE ALSO + +L<mro> +(in particular L<next::method|https://metacpan.org/pod/mro#next::method>), +which has been a core module since Perl 5.9.5. =head1 AUTHOR @@ -547,7 +561,7 @@ Damian Conway (damian@conway.org) =head1 BUGS AND IRRITATIONS -Because it's a module, not an integral part of the interpreter, NEXT.pm +Because it's a module, not an integral part of the interpreter, C<NEXT> has to guess where the surrounding call was found in the method look-up sequence. In the presence of diamond inheritance patterns it occasionally guesses wrong. |