Commit | Line | Data |
6cbf4a23 |
1 | #!/usr/bin/perl |
2 | use strict; |
3 | use warnings; |
4 | |
a28e50e4 |
5 | use Test::More; |
6cbf4a23 |
6 | |
7 | my @phonograph; |
8 | { |
9 | package Duck; |
10 | use Moose; |
11 | |
12 | sub walk { |
13 | push @phonograph, 'footsteps', |
14 | } |
15 | |
16 | sub quack { |
17 | push @phonograph, 'quack'; |
18 | } |
19 | |
20 | package Swan; |
21 | use Moose; |
22 | |
23 | sub honk { |
24 | push @phonograph, 'honk'; |
25 | } |
26 | |
27 | package DucktypeTest; |
28 | use Moose; |
29 | use Moose::Util::TypeConstraints; |
30 | |
31 | my $ducktype = duck_type 'DuckType' => qw(walk quack); |
32 | |
33 | has duck => ( |
34 | isa => $ducktype, |
35 | handles => $ducktype, |
36 | ); |
37 | } |
38 | |
39 | my $t = DucktypeTest->new(duck => Duck->new); |
40 | $t->quack; |
41 | is_deeply([splice @phonograph], ['quack']); |
42 | |
43 | $t->walk; |
44 | is_deeply([splice @phonograph], ['footsteps']); |
45 | |
a28e50e4 |
46 | done_testing; |