X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Froles%2Fmethods.t;fp=t%2Froles%2Fmethods.t;h=b401d1cde8ec782eae51a24dd0873b5b7ba4e4bd;hb=b55eada36de96551d2a6eb59c0bd363c9de6e5f2;hp=0000000000000000000000000000000000000000;hpb=8b3c8a92f073be4d107f7c709bcb36d048eff1d4;p=gitmo%2FMoose.git diff --git a/t/roles/methods.t b/t/roles/methods.t new file mode 100644 index 0000000..b401d1c --- /dev/null +++ b/t/roles/methods.t @@ -0,0 +1,46 @@ +use strict; +use warnings; + +use Test::More; +use Moose::Role (); + +my $test1 = Moose::Meta::Role->create_anon_role; +$test1->add_method( 'foo1', sub { } ); + +ok( $test1->has_method('foo1'), 'anon role has a foo1 method' ); + +my $t1_am = $test1->get_method('foo1')->associated_metaclass; + +ok( $t1_am, 'associated_metaclass is defined' ); + +isa_ok( + $t1_am, 'Moose::Meta::Role', + 'associated_metaclass is correct class' +); + +like( $t1_am->name(), qr/::__ANON__::/, + 'associated_metaclass->name looks like an anonymous class' ); + +{ + package Test2; + + use Moose::Role; + + sub foo2 { } +} + +ok( Test2->meta->has_method('foo2'), 'Test2 role has a foo2 method' ); + +my $t2_am = Test2->meta->get_method('foo2')->associated_metaclass; + +ok( $t2_am, 'associated_metaclass is defined' ); + +isa_ok( + $t2_am, 'Moose::Meta::Role', + 'associated_metaclass is correct class' +); + +is( $t2_am->name(), 'Test2', + 'associated_metaclass->name is Test2' ); + +done_testing;