Add what does moose stand for section back to docs
[gitmo/Moose.git] / t / type_constraints / type_coersion_on_lazy_attributes.t
CommitLineData
3fd955cb 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use 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 30my $attr = SomeClass->meta->get_attribute('foo');
31is($attr->get_value(SomeClass->new()), 'Six');
32is(SomeClass->new()->foo, 'Six');
33
a28e50e4 34done_testing;