in reply to Moose and BUILD
Maybe you should start with what you want to achieve in the end.
If y always depends on x, don't make it an attribute, but rather a method that calculates the value of y.
If you want to make it a default, use Moose's default facility:
use Moose; has 'y' => ( is => 'Num', is => 'rw' ); has 'x' => ( is => 'Num', is => 'rw', default => sub { sqrt(shift->x) }, );
I'm not a Moose specialist, but I guess that one reason the code does not do what you want is that you try to call methods on objects that haven't been constructed yet.
I also don't see why you want to call a derived BUILD method before the parent BUILD method. Just let the parent construct the parent part of the object, and then do whatever you want in the child.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Moose and BUILD
by ikegami (Patriarch) on Jun 15, 2011 at 20:56 UTC | |
by tj_thompson (Monk) on Jun 15, 2011 at 21:04 UTC | |
by ikegami (Patriarch) on Jun 15, 2011 at 21:19 UTC | |
|
Re^2: Moose and BUILD
by tj_thompson (Monk) on Jun 15, 2011 at 20:49 UTC | |
by tj_thompson (Monk) on Jun 15, 2011 at 20:58 UTC | |
|
Re^2: Moose and BUILD
by tj_thompson (Monk) on Jun 15, 2011 at 20:37 UTC |