Commit | Line | Data |
b55eada3 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Moose::Role (); |
6 | |
7 | my $test1 = Moose::Meta::Role->create_anon_role; |
8 | $test1->add_method( 'foo1', sub { } ); |
9 | |
10 | ok( $test1->has_method('foo1'), 'anon role has a foo1 method' ); |
11 | |
12 | my $t1_am = $test1->get_method('foo1')->associated_metaclass; |
13 | |
14 | ok( $t1_am, 'associated_metaclass is defined' ); |
15 | |
16 | isa_ok( |
17 | $t1_am, 'Moose::Meta::Role', |
18 | 'associated_metaclass is correct class' |
19 | ); |
20 | |
21 | like( $t1_am->name(), qr/::__ANON__::/, |
22 | 'associated_metaclass->name looks like an anonymous class' ); |
23 | |
24 | { |
25 | package Test2; |
26 | |
27 | use Moose::Role; |
28 | |
29 | sub foo2 { } |
30 | } |
31 | |
32 | ok( Test2->meta->has_method('foo2'), 'Test2 role has a foo2 method' ); |
33 | |
34 | my $t2_am = Test2->meta->get_method('foo2')->associated_metaclass; |
35 | |
36 | ok( $t2_am, 'associated_metaclass is defined' ); |
37 | |
38 | isa_ok( |
39 | $t2_am, 'Moose::Meta::Role', |
40 | 'associated_metaclass is correct class' |
41 | ); |
42 | |
43 | is( $t2_am->name(), 'Test2', |
44 | 'associated_metaclass->name is Test2' ); |
45 | |
46 | done_testing; |