nysus has asked for the wisdom of the Perl Monks concerning the following question:
I'm curious to know how I might give objects created by a parent class access to the data in the parent class:
{ package parent 0.000001; use Moose; has 'changing_data' => (is => 'rw', isa => 'Str', default => ''); sub set_data { my $s = shift; $s->changing_data('foo foo foo'); } sub create_child { my $s = shift; my $data = shift; return child->new(changing_data => $data); } } { package child 0.00001; use Moose; extends 'parent'; } my $p = parent->new(); $p->set_data; my $child = $p->create_child($p->changing_data()); print $child->changing_data; $p->changing_data('bar bar bar'); print "\n"; print $child->changing_data; # desired output foo foo foo bar bar bar # actual output foo foo foo foo foo foo
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose: Giving objects access to data of class that created it
by tobyink (Canon) on May 25, 2017 at 20:25 UTC | |
by nysus (Parson) on May 27, 2017 at 17:45 UTC | |
|
Re: Moose: Giving objects access to data of class that created it
by Anonymous Monk on May 25, 2017 at 19:51 UTC | |
by nysus (Parson) on May 25, 2017 at 20:13 UTC | |
|
Re: Moose: Giving objects access to data of class that created it
by NetWallah (Canon) on May 26, 2017 at 19:08 UTC | |
|
Re: Moose: Giving objects access to data of class that created it
by Anonymous Monk on May 25, 2017 at 20:23 UTC |