| Public Scratchpad | Download, Select Code To D/L |
Here is some (very slightly modified) code directly from the NEXT module perldoc. Note I commented out sub foo in package E:
package A; sub foo { print "called A::foo\n"; shift->NEXT::UNSEEN::foo() } package B; sub foo { print "called B::foo\n"; shift->NEXT::UNSEEN::foo() } package C; use vars qw( @ISA ); @ISA = qw( A ); sub foo { print "called C::foo\n"; shift->NEXT::UNSEEN::foo() } package D; use vars qw( @ISA ); @ISA = qw(A B); sub foo { print "called D::foo\n"; shift->NEXT::UNSEEN::foo() } package E; use vars qw( @ISA ); @ISA = qw(C D); #sub foo { print "called E::foo\n"; shift->NEXT::UNSEEN::foo() } package ::; E->foo();
And here is its output:
called C::foo called A::foo called D::foo called B::foo
Now, here is my code that does almost the exact same thing:
#!/usr/local/bin/perl use NEXT; use strict; package ROOT; sub traverse { print __PACKAGE__, "\n"; } package LEFT_CHILD; #use base 'ROOT'; use vars qw( @ISA ); @ISA = qw( ROOT ); sub traverse { my $package = shift; print __PACKAGE__, "\n"; $package->NEXT::UNSEEN::traverse(); } package RIGHT_CHILD; #use base 'ROOT'; use vars qw( @ISA ); @ISA = qw( ROOT ); sub traverse { my $package = shift; print __PACKAGE__, "\n"; $package->NEXT::UNSEEN::traverse(); } package GRANDCHILD; #use base 'LEFT_CHILD'; #use base 'RIGHT_CHILD'; use vars qw( @ISA ); @ISA = qw( LEFT_CHILD RIGHT_CHILD ); package ::; GRANDCHILD->traverse();
Here is the output:
LEFT_CHILD ROOT<demerphq> Incidentally to those who say XP means nothing: The abscence of XP doesnt mean you arent a good programmer, but the prescence of it doessuggest hat you arent a crap programmer. my $0.02. :-)
Nodes relating to XP:
(humor) The first rule of The XP club is...