This could seem like an obviously hopeless case, but is there a trick to create a cyclic graph of immutable objects in Perl? Something like this:
package Node;
use Moose;
has [qw/parent child/] => (is => 'ro', isa => 'Node');
package main;
my $a = Node->new;
my $b = Node->new(parent => $a);
Now if I wanted $a->child to point to $b, what can I do?
I had to go and look at how really immutable languages do something like
this, and I think the following is probably a reasonable attempt.
Basically instead of trying to build the objects separately, you have
the parent auto-vivify the child based on passing in it’s arguments. The
output for this is, which is I believe the structure you were wanting.