I did a little testing, and got contradictary results.
From this I discover that blessing a hash before its assigned to "sticks", and assigning to it doesn't lose its blessing. I'm supposing %hash was actually defined upon first use, where the reference was taken.package C1; sub foo { my $self= shift; print "C1::foo called @_ :", join (',', keys %$self), "\n"; } package C2; sub foo { my $self= shift; print "C2::foo called @_ :", join (',', keys %$self), "\n"; } package main; my $x= bless \%hash, "C1"; my $y= bless \%hash, "C2"; $x->foo ("before"); $y->foo ("before"); %hash= ( key=>'value'); $x->foo ("after"); $y->foo ("after");
So if the blessing is a property of the reference, not the object, then I should be able to have two different references with different blessings. But I cannot. One affects the other.
If the blessing is a property of the object, then why doesn't assigning to the object as a whole lose it?
I think what's going on is that blessing is a property of the object's identity, not its value. Assignment changes the value, but not the container that holds that value. So where it said the blessing is a property of the reference, it really meant THE reference of that object, which is itself the (same) value in two reference variables (if you think if reference vars as pointers).
Am I on the right track?
In reply to Where is blessing magic located? by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |