Suppose I have the following Moose package:
package GSM::Cell;
use Moose;
has 'ID' => (is => 'ro', required => 1);
has [qw(BCCH NEIGHBOUR)] => (is => 'rw', default => undef);
no Moose;
__PACKAGE__->meta->make_immutable;
1;
Then I create two objects and add them as the NEIGHBOR attribute of the other:
my $a = GSM::Cell->new(ID => 20021, BCCH => 1);
my $b = GSM::Cell->new(ID => 20022, BCCH => 2);
$a->NEIGHBOUR($b);
Somewhere else, for example. in another procedure, the attribute BCCH $ b can be updated to a different value:
$b->BCCH(3);
Now if i turn to
$a->NEIGHBOUR->BCCH
then I will still return my initial value for the BCCH attribute instead of the updated value.
I think the smart thing is to add a link to $ b instead of $ b itself, which would solve the problem:
$a->NEIGHBOUR(\$b);
, -, , $b ( ), , , .
,
my $somevar = GSM::Cell->new(ID => 20022);
, .
, - :
$id = 20022;
my $somevar = $already_created{$id} || GSM::Cell->new(ID => $id);
?