in reply to constraining the keys of a HashRef in Moose
package Test::HashK; use Moose; use Types::Standard qw( Dict Optional Int ); use Types::ReadOnly qw( Locked ); my $colour_hash = Locked[ Dict[ red => Optional[Int], blue => Optional[Int], green => Optional[Int], ], ]; has scores => ( is => 'rw', isa => $colour_hash, default => sub{ {} }, coerce => 1, ); __PACKAGE__->meta->make_immutable; package main; my $thk = Test::HashK->new(scores => { green => 0 }); $thk->scores->{red} = 2000; $thk->scores->{bloo} = 'tobyink'; # dies
PS: this is my 2000th post to PerlMonks!
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: constraining the keys of a HashRef in Moose
by Your Mother (Archbishop) on Aug 29, 2013 at 23:04 UTC | |
by tomgracey (Scribe) on Aug 30, 2013 at 08:03 UTC | |
by kennethk (Abbot) on Aug 30, 2013 at 15:33 UTC | |
Re^2: constraining the keys of a HashRef in Moose
by tomgracey (Scribe) on Sep 02, 2013 at 08:53 UTC | |
by tobyink (Canon) on Sep 03, 2013 at 08:09 UTC | |
by tomgracey (Scribe) on Sep 04, 2013 at 11:13 UTC |
In Section
Seekers of Perl Wisdom