in reply to Re: Moose and BUILD
in thread Moose and BUILD
The type is specified using isa, and you need lazy => 1 to make sure the default isn't calculated too soon.
use Moose; has 'x' => ( is => 'rw' isa => 'Num', ); has 'y' => ( is => 'rw', isa => 'Num', lazy => 1, default => sub { sqrt($_[0])->x) }, );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Moose and BUILD
by tj_thompson (Monk) on Jun 15, 2011 at 21:04 UTC | |
by ikegami (Patriarch) on Jun 15, 2011 at 21:19 UTC |