5f11fb6dfc610a4c9be68e83b7dcb7cc796b3598
[gitmo/Moose.git] / t / 040_type_constraints / 025_type_coersion_on_lazy_attributes.t
1 {
2     package SomeClass;
3     use Moose;
4     use Moose::Util::TypeConstraints;
5
6     subtype 'DigitSix' => as 'Num'
7         => where { /^6$/ };
8     subtype 'TextSix' => as 'Str'
9         => where { /Six/i };
10     coerce 'TextSix' 
11         => from 'DigitSix' 
12         => via { confess("Cannot live without 6 ($_)") unless /^6$/; 'Six' };
13
14     has foo => ( isa => 'TextSix', coerce => 1, is => 'ro', default => 6,
15         lazy => 1
16     ); 
17 }
18
19 use Test::More tests => 2;
20 my $attr = SomeClass->meta->get_attribute('foo');
21 is($attr->get_value(SomeClass->new()), 'Six');
22 is(SomeClass->new()->foo, 'Six');
23