MooseX::Types::Ro - Moose type constraints for read-only containers
package Foo; use Moose; use MooseX::Types::Ro qw(RoArrayRef RoHashRef); has array => ( is => 'ro', isa => RoArrayRef, coerce => 1 ); has hash => ( is => 'ro', isa => RoHashRef, coerce => 1 ); my $foo = Foo->new(array => [1, 2, 3], hash => { foo => 1, bar => 2 }); # These all throw exceptions now: $foo->array->[0] = 42; $foo->array->[3] = 42; push @{$foo->array}, 69; $foo->hash->{bar} = 3; delete $foo->hash->{bar};p $foo->hash->{baz} = 4;
MooseX::Types::Ro provides Moose type constraints for read-only array and hash references. Attempting to modify the values in any way, including adding or deleting from the arrays and hashes will throw an exception.
A subtype of ArrayRef in which the array itself and all the elements are read-only. Coerces from ArrayRef by making a shallow copy and marking it read-only.
ArrayRef
A subtype of HashRef in which the hash itself and all the values are read-only. Coerces from HashRef by making a shallow copy and marking it read-only.
HashRef
MooseX::Types, MooseX::Types::Moose, Moose::Util::TypeConstraints, Internals
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>.
Copyright (c) 2010 Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>.
This program is free software; you can redistribute and/or modify it under the same terms as perl itself.
To install MooseX::Types::Ro, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Types::Ro
CPAN shell
perl -MCPAN -e shell install MooseX::Types::Ro
For more information on module installation, please visit the detailed CPAN module installation guide.