Question: is there any hook to catch that an object is shareable (i.e. shared() is called on it) or does the call to CLONE specify that somewhere?

Isn't that done by setting the :shared attribute on an object? i.e. marking an object as shareable is up to the caller using a module which uses Alter. AFAIK the CLONE() special subroutine has to do with package and/or class data only.

I can't seem to find any decent documentation on CLONE().

I don't know if there's much more documentation about that than what perldelta tells:

Support for the "CLONE" special subroutine had been added. With ithreads, when a new thread is created, all Perl data is cloned, however non-Perl data cannot be cloned automatically. In "CLONE" you can do whatever you need to do, like for example handle the cloning of non-Perl data, if necessary. "CLONE" will be executed once for every package that has it defined or inherited. It will be called in the context of the new thread, so all modifications are made in the new area.

See perlmod

Sine the object instance data is attached to an Alter object itself, no special provision for cloning has to be taken by the Alter package; sharing those objects in threads should be as straight forward as sharing simple scalar references. I don't know for shure, but the magicext structure should automatically be cloned as well for shared objects (I haven't done much yet with threads). Whether you shoot yourself into your foot depends on what you pass into the ego() subroutine upon object construction, i.e that could be some class data reference which isn't shared or shareable.

--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^5: Really Writing Object Oriented Perl by shmem
in thread Really Writing Object Oriented Perl by agianni

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.