package Practice::File; use v5.38; use Cwd; use Scalar::Util qw(weaken); sub new { my $class = shift; my $self = {}; $self->{name} = shift; bless $self, $class; return $self; } sub dir { my $self = shift; return $self->{dir}->{dir}; } sub add_dir { my $self = shift; my $dir = shift; $self->{dir} = $dir; weaken($self->{dir}); # <=============== Is not using weaken here a really bad idea? $self->{dir}->add_file($self); } sub path { my $self = shift; my $path = $self->{name}; if (defined $self->{dir}) { $path = $self->{dir}->path . '/' . $path; } return $path; } 1; package Practice::Dir; use v5.38; use Cwd; sub new { my $class = shift; my $self = {}; $self->{dir} = cwd(); $self->{files} = []; bless $self, $class; return $self; } sub add_file { my $self = shift; my $file = shift; push @{$self->{files}}, $file; } 1;