in reply to What would you change?
Preferably do not upvote it. (Downvote at your choice.)
Couldn't resist to upvote your post. Downvote mine if you like ;-)
I would change bless() to construct an inside-out object incorporating Alter into the core, so that bless { @_ }, $class provides a real inside-out object with a hidden alter ego for free, which is thread-safe, garbage-collected and accessible only inside this object's package:
package Foo; sub new { my $class = shift; bless { @_ }, $class; # @_ goes into this ref's alter ego } sub bar { my $self = shift; $self->{bar} = shift if @_; # access $self's alter ego $self->{bar}; } package main; my $ref = Foo->new( bar => 'quux'); # empty blessed hashref returned $ref->{bar} = 'blorf'; # used as a normal hashref print $ref->bar, "\n"; # yields 'quux' print $ref->{bar}, "\n"; # yields 'blorf'
That way, an object would behave as a normal perl data type if so treated, but as an object calling one of its methods. Private and public attributes for free.
No, I haven't thought about all the consequences...
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|