10 use Moose::Util::TypeConstraints;
12 subtype 'UCHash', as 'HashRef[Str]', where {
13 !grep {/[a-z]/} values %{$_};
16 coerce 'UCHash', from 'HashRef[Str]', via {
17 $_ = uc $_ for values %{$_};
39 default => sub { { x => 'a' } },
43 trigger => sub { @TriggerArgs = @_ },
44 clearer => 'clear_lazy',
51 $foo->hash( { x => 'A', y => 'B' } );
53 $foo->set_key( z => 'c' );
56 $foo->hash, { x => 'A', y => 'B', z => 'C' },
57 'set coerces the hash'
62 $foo->set_lazy( y => 'b' );
65 $foo->lazy, { x => 'A', y => 'B' },
66 'set coerces the hash - lazy'
71 [ $foo, { x => 'A', y => 'B' }, { x => 'A' } ],
72 'trigger receives expected arguments'
89 use Moose::Util::TypeConstraints;
95 => via { Thing->new( thing => $_ ) };
97 subtype 'HashRefOfThings'
98 => as 'HashRef[Thing]';
100 coerce 'HashRefOfThings'
101 => from 'HashRef[Str]'
104 for my $k ( keys %{$_} ) {
105 $new{$k} = Thing->new( thing => $_->{$k} );
110 coerce 'HashRefOfThings'
112 => via { [ Thing->new( thing => $_ ) ] };
117 isa => 'HashRefOfThings',
127 my $bar = Bar->new( hash => { foo => 1, bar => 2 } );
130 $bar->get_hash('foo')->thing, 1,
131 'constructor coerces hash reference'
134 $bar->set_hash( baz => 3, quux => 4 );
137 $bar->get_hash('baz')->thing, 3,
138 'set coerces new hash values'
142 $bar->get_hash('quux')->thing, 4,
143 'set coerces new hash values'