Deep cloning an OIO object that contains other OIO objects seems problematic. I would have been fine with the behavior described in the doc ("Note that cloning does not clone internally held objects. For example, if $foo contains a reference to $bar, a clone of $foo will also contain a reference to $bar; not a clone of $bar") but I suspect that's not what's happening here. The code below returns the error "Modification of a read-only value attempted at /u/jroussin/perl/lib/Object/InsideOut/Util.pm line 379". After adding a few debug statements in Util.pm I see that the internally held OIO objects are recognized as SCALAR references and processed as such. That doesn't seem right? The error occurs during blessing of the newly created scalar reference (into class Element in the example below).
package Container;
{
use Object::InsideOut;
my @elements :Field :Name(elements);
sub _init :Init {
my $self = shift;
$elements[$$self] = {};
}
sub set_element {
my ($self,$element) = @_;
$elements[$$self]->{$element->get_key} = $element;
}
}
package Element;
{
use Object::InsideOut;
my @key :Field :Name(key) :Arg(key) :Get(get_key);
}
my $c = Container->new;
my $e = Element->new(key => 1);
$c->set_element($e);
my $cc = $c->clone(1);