The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MooseX::Types::Ro - Moose type constraints for read-only containers

SYNOPSIS

    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;

DESCRIPTION

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.

TYPES

RoArrayRef

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.

RoHashRef

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.

SEE ALSO

MooseX::Types, MooseX::Types::Moose, Moose::Util::TypeConstraints, Internals

AUTHOR

Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>.

COPYRIGHT & LICENSE

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.