Commit | Line | Data |
3fd955cb |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
a28e50e4 |
6 | use Test::More; |
3fd955cb |
7 | |
f92cd300 |
8 | { |
9 | package SomeClass; |
10 | use Moose; |
11 | use Moose::Util::TypeConstraints; |
12 | |
13 | subtype 'DigitSix' => as 'Num' |
14 | => where { /^6$/ }; |
15 | subtype 'TextSix' => as 'Str' |
16 | => where { /Six/i }; |
d03bd989 |
17 | coerce 'TextSix' |
18 | => from 'DigitSix' |
f92cd300 |
19 | => via { confess("Cannot live without 6 ($_)") unless /^6$/; 'Six' }; |
20 | |
3fd955cb |
21 | has foo => ( |
22 | is => 'ro', |
23 | isa => 'TextSix', |
24 | coerce => 1, |
25 | default => 6, |
26 | lazy => 1 |
27 | ); |
f92cd300 |
28 | } |
29 | |
f92cd300 |
30 | my $attr = SomeClass->meta->get_attribute('foo'); |
31 | is($attr->get_value(SomeClass->new()), 'Six'); |
32 | is(SomeClass->new()->foo, 'Six'); |
33 | |
a28e50e4 |
34 | done_testing; |