in reply to Moose: Giving objects access to data of class that created it
Is something like this what you want?
use strict; use warnings; use feature 'say'; { package Tree; use Moose; has health_level => ( is => 'rw', isa => 'Int', ); sub grow_leaf { my $self = shift; Leaf->new(tree => $self); # pass $self on to child } } { package Leaf; use Moose; has tree => ( is => 'bare', handles => ['health_level'], ); } my $t = Tree->new(health_level => 100); my $l = $t->grow_leaf; say $l->health_level; # 100 $t->health_level(90); say $l->health_level; # 90
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Moose: Giving objects access to data of class that created it
by nysus (Parson) on May 27, 2017 at 17:45 UTC |