package Top;
sub new {
my $class = shift;
my $s = bless { }, $class;
$s->{bottom} = Bottom->new( $s );
return $s;
}
#=====================================
package Bottom;
sub new {
my ($class, $top) = @_;
return bless { top => $top }, $class;
}
#=====================================
package main;
use strict;
use warnings 'all';
use Devel::Cycle;
my $top = Top->new();
find_cycle( $top );
####
Cycle (1):
$Top::A->{'bottom'} => \%Bottom::B
$Bottom::B->{'top'} => \%Top::A
####
local $| = 1;
for( 1...1_000_000 )
{
print "\r$_/1000000";
my $top = Top->new();
}
####
package Top;
use Scalar::Util 'weaken';
sub new {
my $class = shift;
my $s = bless { }, $class;
weaken($s);
$s->{bottom} = Bottom->new( $s );
return $s;
}
#=====================================
package Bottom;
use Scalar::Util 'weaken';
sub new {
my ($class, $top) = @_;
my $s = bless { top => $top }, $class;
weaken($s);
return $s;
}
#=====================================
package main;
use strict;
use warnings 'all';
my $top = Top->new();
my $bottom = $top->{bottom} or die "NO BOTTOM!";