in reply to Two argument bless sometimes ignores 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:
There's no reason why it wouldn't print "Bar" for the class, no? Yet, this is the result I get:{ package Foo; sub foo { bless {}, "Bar" } } *Bar:: = \*Foo::; use Data::Dumper; print Dumper(Foo->foo);
$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:
and it still behaves as expected, yielding:*Bar::foo = \*Foo::foo;
whether you call it like either of:$VAR1 = bless( {}, 'Bar' );
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 |