John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Where is blessing magic located?
by perrin (Chancellor) on Nov 06, 2002 at 04:44 UTC | |
by BrowserUk (Patriarch) on Nov 06, 2002 at 04:52 UTC | |
|
Re: Where is blessing magic located?
by bart (Canon) on Nov 06, 2002 at 08:54 UTC | |
|
Re: Where is blessing magic located?
by chromatic (Archbishop) on Nov 06, 2002 at 06:58 UTC | |
by John M. Dlugosz (Monsignor) on Nov 06, 2002 at 16:19 UTC | |
by chromatic (Archbishop) on Nov 06, 2002 at 17:38 UTC | |
by John M. Dlugosz (Monsignor) on Nov 06, 2002 at 19:00 UTC | |
|
Re: Where is blessing magic located?
by Elian (Parson) on Nov 07, 2002 at 05:16 UTC |