How to set Moose read-only attribute attribute?
package AttrTrait;
use Moose::Role;
has 'ext' => ( isa => 'Str', is => 'ro' );
package Class;
has 'foo' => ( isa => 'Str', is => 'ro', traits => [qw/AttrTrait/] );
package main;
my $c = Class->new( foo => 'ok' );
$c->meta->get_attribute('foo')->ext('die')
What is the purpose of Read Only attribute attributes if you cannot set it in the constructor or at run time? Is there something missing in Moose :: Meta :: Attribute ? Is there any way to install it using meta?
$c->meta->get_attr('ext')->set_value('foo')
source
share