Here's my short test code which demonstrates the data structure prior to returning and how it instamagically turned into a self-ref afterward.

Here's the data before returning and after returning it from the -= method.

$expected = bless( \bless( \1, 'T' ), 'T' ); $got = bless( \$got, 'T' );

And here's the sample code.

package T; use Data::Dump::Streamer; sub D { my ( $name, $val ) = @_; Dump() ->Purity( 0 ) ->Names( $name ) ->Data( $val ) ->Out(); return; } use overload( '-=' => sub { my $new = bless \ $_[0], "T"; D( new => $new ); return $new; }, '""' => sub { my $self = shift; D( self => $self ); return $$self } ); sub new { my ( $class, $val ) = @_; bless \ $val, $class; } package main; $o = T->new( 1 ); $o -= 2; "$o";

In reply to Re^2: A warning about overloading assignment methods by diotalevi
in thread A warning about overloading assignment methods by diotalevi

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.