package Foo;
use Moose;
has 'y' => (
is => 'Num',
is => 'rw'
);
has 'x' => (
is => 'Num',
is => 'rw'
);
sub init_y {
my ($self, $value) = @_;
$self->y(sqrt($self->x));
}
sub BUILD {
my ($self) = @_;
print STDERR "Foo::BUILD running\n";
$self->init_y;
}
1;
####
package Foo::Bar;
use Moose;
extends 'Foo';
before 'BUILD' => sub {
my $self = shift;
print STDERR "Foo::Bar before BUILD running\n";
$self->x(25);
};
1;
####
use lib '.';
use Foo::Bar;
use Data::Dumper;
my $o = Foo::Bar->new;
print STDERR Dumper($o);
####
plxc16479> ex.pl
Foo::BUILD running
Use of uninitialized value in sqrt at Foo.pm line 17.
Foo::Bar before BUILD running
Foo::BUILD running
$VAR1 = bless( {
'y' => '5',
'x' => 25
}, 'Foo::Bar' );