5 use Test::More tests => 5;
39 use Mouse::Util::TypeConstraints;
41 duck_type 'DuckType' => qw(quack);
42 duck_type 'SwanType' => [qw(honk)];
50 sub _build_duck { Duck->new }
53 isa => duck_type( [qw(honk)] ),
64 # try giving it a duck
65 lives_ok { DucktypeTest->new( duck => Duck->new ) } 'the Duck lives okay';
67 # try giving it a swan which is like a duck, but not close enough
68 throws_ok { DucktypeTest->new( duck => Swan->new ) }
69 qr/Swan is missing methods 'quack'/,
70 "the Swan doesn't quack";
72 # try giving it a rubber RubberDuckey
73 lives_ok { DucktypeTest->new( swan => Swan->new ) } 'but a Swan can honk';
75 # try giving it a rubber RubberDuckey
76 lives_ok { DucktypeTest->new( duck => RubberDuck->new ) }
77 'the RubberDuck lives okay';
79 # try with the other constraint form
80 lives_ok { DucktypeTest->new( other_swan => Swan->new ) } 'but a Swan can honk';