- SEE ALSO
- COPYRIGHT AND LICENSE
MooX::Const - Syntactic sugar for constant and write-once Moo attributes
use Moo; use MooX::Const; use Types::Standard -types; has thing => ( is => 'const', isa => ArrayRef[HashRef], );
use Types::Const -types; has thing => ( is => 'ro', isa => Const[ArrayRef[HashRef]], coerce => 1, );
It modifies the
has function to support "const" attributes. These are read-only ("ro") attributes for references, where the underlying data structure has been set as read-only.
This will return an error if there is no "isa", the "isa" is not a Type::Tiny type, if it is not a reference, or if it is blessed object.
Simple value types such as
Str are silently converted to read-only attributes.
As of v0.2.0, it also supports write-once ("wo") attributes for references:
has setting => ( is => 'wo', isa => HashRef, );
This allows you to set the attribute once. The value is coerced into a constant, and cannot be changed again.
Support for Perl versions earlier than 5.10 will be removed sometime in 2019.
Please report any bugs or feature requests on the bugtracker website https://github.com/robrwo/MooX-Const/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Robert Rothenberg <email@example.com>
This module was inspired by suggestions from Kang-min Liu 劉康民 <firstname.lastname@example.org> in a blog post.
Kang-min Liu 劉康民 <email@example.com>
This software is Copyright (c) 2018 by Robert Rothenberg.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)