I understand that using builder
enables subclasses to override attribute defaults easily and roles can require
them. This can also be accomplished using default
like so:
has 'foo' =>
is => 'rw',
isa => 'Str',
default => sub { $_[0]->_build_foo };
I'm wondering if there are further advantages to using builder
I'm not aware of? I've come up with some myself:
builder
is declarative so you can introspect thatfoo
is built by_build_foo
builder
eliminates a subroutine wrapper making it a bit fasterbuilder
allows the use of the helpfullazy_build
.
UPDATE To clarify, this isn't about default
vs builder
in general but default => sub { $_[0]->_build_foo }
vs builder => '_build_foo'
.
default => \&builder
doesn't do every one of those things? – Adapt