I got it to produce the desired results, after a few tweaks.
Mainly, allow 'changing_data' to be a code-ref, and change child's calling syntax appropriately.
use strict;
use warnings;
{
package parent 0.000001;
use Moose;
has 'changing_data' => (is => 'rw', 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(sub{$p->changing_data()});
print $child->changing_data->();
$p->changing_data('bar bar bar');
print "\n";
print $child->changing_data->();
Once it hits the fan, the only rational choice is to sweep it up, package it, and sell it as fertilizer.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.