Modifying Foo::Bar to this:
package Foo::Bar;
use Moose;
extends 'Foo';
use Data::Dumper;
around 'BUILDARGS' => sub {
my ($orig, $class, %args) = @_;
print STDERR "Foo::Bar::BUILDARGS running.\n";
$args{x} = 25;
return $class->$orig(%args);
};
1;
Seems to do what I want. Foo::BUILD is only executed once and it receives the updated 'x' value prior to BUILD execution, so 'y' is only calculated once. Here is the output in this case:
plxc16479> ex.pl
Foo::Bar::BUILDARGS running.
Foo::BUILD running
$VAR1 = bless( {
'y' => '5',
'x' => 25
}, 'Foo::Bar' );
|