39 use Moose::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 is( exception { DucktypeTest->new( duck => Duck->new ) }, undef, 'the Duck lives okay' );
67 # try giving it a swan which is like a duck, but not close enough
68 like( exception { DucktypeTest->new( duck => Swan->new ) }, qr/Swan is missing methods 'quack'/, "the Swan doesn't quack" );
70 # try giving it a rubber RubberDuckey
71 is( exception { DucktypeTest->new( swan => Swan->new ) }, undef, 'but a Swan can honk' );
73 # try giving it a rubber RubberDuckey
74 is( exception { DucktypeTest->new( duck => RubberDuck->new ) }, undef, 'the RubberDuck lives okay' );
76 # try with the other constraint form
77 is( exception { DucktypeTest->new( other_swan => Swan->new ) }, undef, 'but a Swan can honk' );