Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Is Conway's NEXT.pm broken?

by !1 (Hermit)
on Jan 14, 2005 at 19:49 UTC ( [id://422365]=note: print w/replies, xml ) Need Help??


in reply to Is Conway's NEXT.pm broken?

Rename your B package to anything else and it works perfectly.

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 Ba; use base qw( A ); sub Ba::AUTOLOAD { print "$_[0]: B AUTOLOAD\n"; $_[0]->NEXT::AUTOLOAD() } sub Ba::DESTROY { print "$_[0]: B 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 D; use base qw( Ba 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 main; my $obj = bless {}, "D"; $obj->method(); # Calls D::method, A::method, C::method $obj->missing_method(); # Calls D::AUTOLOAD, B::AUTOLOAD, C::AUTOLO +AD # Clean-up calls D::DESTROY, B::DESTROY, A::DESTROY, C::DESTROY --- D=HASH(0x811b15c): D method D=HASH(0x811b15c): A method D=HASH(0x811b15c): C method D=HASH(0x811b15c): D AUTOLOAD D=HASH(0x811b15c): B AUTOLOAD D=HASH(0x811b15c): C AUTOLOAD D=HASH(0x811b15c): D dtor D=HASH(0x811b15c): B dtor D=HASH(0x811b15c): A dtor D=HASH(0x811b15c): C dtor

B has special meaning to perl and you shouldn't name any package as such.

Update: Fooled myself. Basically, what really happens is that use base qw(B C) loads up B.pm which resets @ISA to Exporter. Note that merely changing the use base qw( A ); line to @ISA = "A"; will make the code work the way you want. Of course, base will still load up B.pm and B.pm's loading will set @B::ISA but since @ISA is defined at runtime, everything will work as expected. So there you have it, base is loading up B. If you wish to not touch B.pm at all, you can switch all use base statements to just set @ISA directly or you can create a BEGIN block in which you define either $INC{"B.pm"} or $B::VERSION.

Replies are listed 'Best First'.
Re^2: Is Conway's NEXT.pm broken?
by jkeenan1 (Deacon) on Jan 15, 2005 at 01:58 UTC
Re^2: Is Conway's NEXT.pm broken?
by dragonchild (Archbishop) on Jan 14, 2005 at 19:51 UTC
    Submit a documentation bug to TheDamian?

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re^2: Is Conway's NEXT.pm broken?
by Anonymous Monk on Jan 15, 2005 at 04:33 UTC
    I'm sure if I proposed a module named A.pm, it would never make it into the Perl core. No matter how wonderful it was, I'd be forced to rename it before such a patch would be applied. This is a good thing. Letting such a terrible module name slip through was a bad thing.
Re^2: Is Conway's NEXT.pm broken?
by demerphq (Chancellor) on Jan 17, 2005 at 12:10 UTC

    B has special meaning to perl and you shouldn't name any package as such.

    This is an interesting comment, I know that the B modules are used for Backend stuff, but i dont recall ever reading that they have any special meaning beyond that (unlike say the DB package). Can you expand a bit more on this?

    ---
    demerphq

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://422365]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-19 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found