Import tc tests
[gitmo/Mouse.git] / t / 040_type_constraints / failing / 025_type_coersion_on_lazy_attributes.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 2;
7
8 {
9     package SomeClass;
10     use Mouse;
11     use Mouse::Util::TypeConstraints;
12
13     subtype 'DigitSix' => as 'Num'
14         => where { /^6$/ };
15     subtype 'TextSix' => as 'Str'
16         => where { /Six/i };
17     coerce 'TextSix'
18         => from 'DigitSix'
19         => via { confess("Cannot live without 6 ($_)") unless /^6$/; 'Six' };
20
21     has foo => (
22         is      => 'ro',
23         isa     => 'TextSix',
24         coerce  => 1,
25         default => 6,
26         lazy    => 1
27     );
28 }
29
30 my $attr = SomeClass->meta->get_attribute('foo');
31 is($attr->get_value(SomeClass->new()), 'Six');
32 is(SomeClass->new()->foo, 'Six');
33