MooseX-Types-Ro
view release on metacpan or search on metacpan
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;
MooseX::Types::Ro - Moose type constraints for read-only containers
=head1 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;
lib/MooseX/Types/Ro.pm view on Meta::CPAN
MooseX::Types::Ro - Moose type constraints for read-only containers
=head1 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;
t/modification.t view on Meta::CPAN
#!perl
use strict;
use warnings;
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 );
package main;
use Test::More;
use Test::Exception;
my $foo = Foo->new(array => [1, 2, 3], hash => { foo => 1, bar => 2 });
foreach my $test (
sub { $foo->array->[0] = 42 },
( run in 2.217 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )