in reply to Two argument bless sometimes ignores the class name?

It doesn't ignore the class name.

Instead, it appears to me by overwriting the namespace of Bar, you're overwriting everything in Bar::, including it's "identity". So class Bar is from now on, identified as class Foo.

Check out this similar, but even more reduced code:

{ package Foo; sub foo { bless {}, "Bar" } } *Bar:: = \*Foo::; use Data::Dumper; print Dumper(Foo->foo);
There's no reason why it wouldn't print "Bar" for the class, no? Yet, this is the result I get:
$VAR1 = bless( {}, 'Foo' );

Drop the assignment of the stash, and it behaves as you and I expect.

I have no idea where the identity of the class is stored in the stash, but it must be somewhere — and you're overwriting it.

update: Replace the assignment of the stash with the less rigorous:

*Bar::foo = \*Foo::foo;
and it still behaves as expected, yielding:
$VAR1 = bless( {}, 'Bar' );
whether you call it like either of:
print Dumper(Foo->foo); print Dumper(Bar->foo);

Replies are listed 'Best First'.
Re^2: Two argument bless sometimes ignores the class name?
by duff (Parson) on Jan 07, 2005 at 15:19 UTC

    This has got to be a bug and quite possibly the most bizarre behavior I've ever seen from perl.