in reply to Re: Exporting constants from a Moo role
in thread Exporting constants from a Moo role
You'd probably also want to prevent people from overriding the constant using:
my $obj = MyClass->new(INDEX_FOO => 43);
To do this, use:
has 'INDEX_FOO'=> ( is => 'ro', default => 42 init_arg => undef, );
But by that point, you have to ask, why not just do this?
sub INDEX_FOO () { 42 }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Exporting constants from a Moo role
by 1nickt (Canon) on Aug 02, 2018 at 21:40 UTC | |
by tobyink (Canon) on Aug 03, 2018 at 11:49 UTC |