I'm not sure if it is relevant--you may be aware already--but I added a couple of printfs to your code:

SV * _copy( SV * arg_obj, SV * second, SV * third ) { Number * num_obj; SV * obj_ref, * obj; printf( "_copy:%p %p %p\n", arg_obj, second, third ); ... SV * _set_from_existing( SV * arg_obj ) { Number * num_obj; SV * obj_ref, * obj; printf( "_set::%p\n", arg_obj ); ...

And it appears that the overloading is not causing your _copy() function to be called:

Finished Build Compile Stage _set::0185E260 555 113 Destroying ...... destroyed Destroying ...... destroyed

Which (as best I can tell) explains the output completely:

$$num1 = Grief::new( 113 ); $num2 = $num1; # Assign using _copy( ) $num3 = _set_from_existing( $num1 ); # Assign using _set_from_existing +( ) _set_val( $num1, 555 ); print _get_val( $num2 ),"\n", _get_val( $num3 ), "\n"; __END__

$num2, in the absence of the overloading is simply an alias to $num1, whereas $num3 is explicitely as new object with the same value. When you set $num1 to 555, you are also setting $num2, as they are both references to the same object.

All of which is probably not news to you. The only real question as far as I can see is if overload can't or won't allow you to overload assignment, why doesn't use overload '=' => \&_copy; throw an error?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^3: Overloading '=' doesn't DWIM by BrowserUk
in thread Overloading '=' doesn't DWIM by syphilis

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.