On Tue, Aug 18, 2009 at 12:07 PM, Yuri Shtil<[email protected]> wrote:
> Hi,
>
> Is there a way to change access to a lazy attribute to read-only once the
> value has been set in the builder?
This question doesn't exactly make sense. Builder / Default have
nothing to do with the access of the attribute:
package Example;
use Moose;
has name => ( is => 'ro', lazy => 1, builder => '_build_foo' );
sub _build_foo { __PACKAGE__ }
say Example->new->name; # prints __PACKAGE__ from _build_foo
say Example->new->name('bar') # this will blow up even though
_build_foo was never called
my $ex = Example->new;
say $ex->name; # prints __PACKAGE__
$ex->name('bar') # blows up
Is this the behavior you want? This works by default.
-Chris