我希望构建器方法可以访问调用者提供的所有其他属性。但它似乎只能访问那些名字按字母顺序小于当前属性的人。例如。为什么b
的构建器可以看到a
但不是c
的值? (最终对象中都包含' a'' c&#39>)
代码:
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
{
package P;
use Moo;
printf "Moo version: %s\n", $Moo::VERSION;
# a and c are defined in the same way
has a => ( is => 'ro' );
has c => ( is => 'ro' );
has b => (
is => 'ro',
builder => '_build_b',
);
sub _build_b {
my ($self) = @_;
print Data::Dumper->new(
[ $self ], [ 'self_during_build_b' ]
)->Indent(1)->Sortkeys(1)->Dump;
return "somebuiltvalue";
}
}
my $p = P->new({ a => 1, c => 3 });
print Data::Dumper->new([$p],['p'])->Indent(1)->Sortkeys(1)->Dump;
输出:
Moo version: 2.003004
$self_during_build_b = bless( {
'a' => 1
}, 'P' );
$p = bless( {
'a' => 1,
'b' => 'somebuiltvalue',
'c' => 3
}, 'P' );