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}

In reply to Re: What would you change? by shmem
in thread What would you change? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.