4 use Test::More tests => 26;
9 use Scalar::Util qw(blessed weaken); # import external functions
13 predicate => 'has_pawn',
16 use constant MY_CONST => 42;
19 sub stub_with_attr :method;
26 use Carp qw(carp croak); # import extenral functions
37 my $meta = Class->meta;
38 isa_ok($meta, 'Mouse::Meta::Class');
40 is_deeply([$meta->superclasses], ['Mouse::Object'], "correctly inherting from Mouse::Object");
42 my $meta2 = Class->meta;
43 is($meta, $meta2, "same metaclass instance");
47 has_attribute get_attribute get_attribute_list get_all_attributes
48 has_method get_method get_method_list get_all_methods
51 ok($meta->has_attribute('pawn'));
52 my $attr = $meta->get_attribute('pawn');
53 isa_ok($attr, 'Mouse::Meta::Attribute');
54 is($attr->name, 'pawn', 'got the correct attribute');
56 my $list = [$meta->get_attribute_list];
57 is_deeply($list, [ 'pawn' ], "attribute list");
59 ok(!$meta->has_attribute('nonexistent_attribute'));
61 ok($meta->has_method('pawn'));
63 ok($meta->get_method('pawn'));
64 is($meta->get_method('pawn')->name, 'pawn');
65 is($meta->get_method('pawn')->package_name, 'Class');
68 is( join(' ', sort $meta->get_method_list),
69 join(' ', sort qw(meta pawn has_pawn MY_CONST stub stub_with_attr))
78 my $meta3 = Class->meta;
79 is($meta, $meta3, "same metaclass instance, even if use Mouse is performed again");
81 is($meta->name, 'Class', "name for the metaclass");
84 my $child_meta = Child->meta;
85 isa_ok($child_meta, 'Mouse::Meta::Class');
87 isnt($meta, $child_meta, "different metaclass instances for the two classes");
89 is_deeply([$child_meta->superclasses], ['Class'], "correct superclasses");
92 ok($child_meta->has_attribute('bishop'));
93 ok($child_meta->has_method('child_method'));
96 is( join(' ', sort $child_meta->get_method_list),
97 join(' ', sort qw(meta bishop child_method))
100 can_ok($child_meta, 'find_method_by_name');
101 is $child_meta->find_method_by_name('child_method')->fully_qualified_name, 'Child::child_method';
102 is $child_meta->find_method_by_name('pawn')->fully_qualified_name, 'Class::pawn';
105 local $TODO = 'should be Class::MY_CONST';
106 is( join(' ', sort map{ $_->fully_qualified_name } grep{ $_->package_name ne 'Mouse::Object' } $child_meta->get_all_methods),
108 Child::bishop Child::child_method Child::meta
110 Class::MY_CONST Class::has_pawn Class::pawn Class::stub Class::stub_with_attr