Add a few more tests for ->associated_metaclass on methods
[gitmo/Moose.git] / t / 010_basics / 018_methods.t
CommitLineData
96245b5a 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
19f02ab1 6use Test::More tests => 6;
96245b5a 7
8
9my $test1 = Moose::Meta::Class->create_anon_class;
10$test1->add_method( 'foo1', sub { } );
11
12my $t1 = $test1->new_object;
13my $t1_am = $t1->meta->get_method('foo1')->associated_metaclass;
19f02ab1 14
96245b5a 15ok( $t1_am, 'associated_metaclass is defined' );
19f02ab1 16
96245b5a 17isa_ok(
18 $t1_am, 'Moose::Meta::Class',
19 'associated_metaclass is correct class'
20);
21
19f02ab1 22like( $t1_am->name(), qr/::__ANON__::/,
23 'associated_metaclass->name looks like an anonymous class' );
24
96245b5a 25{
26
27 package Test2;
28
29 use Moose;
30
31 sub foo2 { }
32}
33
34my $t2 = Test2->new;
35my $t2_am = $t2->meta->get_method('foo2')->associated_metaclass;
19f02ab1 36
96245b5a 37ok( $t2_am, 'associated_metaclass is defined' );
38
39isa_ok(
40 $t2_am, 'Moose::Meta::Class',
41 'associated_metaclass is correct class'
42);
19f02ab1 43
44is( $t2_am->name(), 'Test2',
45 'associated_metaclass->name is Test2' );