Types::Const - Types that coerce references to read-only
version v0.4.0
use Moo; use Types::Const -types; use Types::Standard -types; ... has bar => ( is => 'ro', isa => Const[ArrayRef[Str]], coerce => 1, );
This is a type library that provides types to coerce read-only hash and array reference attributes to be deeply read-only.
See the known issues below for a discussion of side-effects.
Const[`a]
Any defined reference value that is read-only.
If parameterized, then the referred value must also pass the type constraint, for example Const[HashRef[Int]] must a a hash reference with integer values.
Const[HashRef[Int]]
It supports coercions to read-only.
This was added in v0.3.0.
Const::Fast
Type::Tiny
Types::Standard
Types::ReadOnly
MooX::Const
A side-effect of read-only data structures is that an exception will be thrown if you attempt to fetch the value of a non-existent key:
Attempt to access disallowed key 'foo' in a restricted hash
The work around for this is to check that a key exists beforehand.
Validating that a complex data-structure is read-only can affect performance. If this is an issue, one workaround is to use Devel::StrictMode and only validate data structures during tests:
has bar => ( is => 'ro', isa => STRICT ? Const[ArrayRef[Str]] : ArrayRef, coerce => 1, );
Another means of improving performance is to only check the type once. (Since it is read-only, there is no need to re-check it.)
There may be an issue with regexp references. See RT#127635.
Please report any bugs or feature requests on the bugtracker website https://github.com/robrwo/Types-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.
The development version is on github at https://github.com/robrwo/Types-Const and may be cloned from git://github.com/robrwo/Types-Const.git
Robert Rothenberg <rrwo@cpan.org>
Mohammad S Anwar <mohammad.anwar@yahoo.com>
This software is Copyright (c) 2018 by Robert Rothenberg.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Types::Const, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Types::Const
CPAN shell
perl -MCPAN -e shell install Types::Const
For more information on module installation, please visit the detailed CPAN module installation guide.