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;
28 use Carp qw(carp croak); # import extenral functions
39 my $meta = Class->meta;
40 isa_ok($meta, 'Mouse::Meta::Class');
42 is_deeply([$meta->superclasses], ['Mouse::Object'], "correctly inherting from Mouse::Object");
44 my $meta2 = Class->meta;
45 is($meta, $meta2, "same metaclass instance");
49 has_attribute get_attribute get_attribute_list get_all_attributes
50 has_method get_method get_method_list get_all_methods
53 ok($meta->has_attribute('pawn'));
54 my $attr = $meta->get_attribute('pawn');
55 isa_ok($attr, 'Mouse::Meta::Attribute');
56 is($attr->name, 'pawn', 'got the correct attribute');
58 my $list = [$meta->get_attribute_list];
59 is_deeply($list, [ 'pawn' ], "attribute list");
61 ok(!$meta->has_attribute('nonexistent_attribute'));
63 ok($meta->has_method('pawn'));
65 my $pawn = $meta->get_method('pawn');
67 is($pawn->name, 'pawn');
68 is($pawn->package_name, 'Class');
69 is($pawn->fully_qualified_name, 'Class::pawn');
73 my $king = $meta->get_method('king');
76 $meta->add_method(king => sub{ 'fool' });
77 isnt $king, $meta->get_method('king');
80 is( join(' ', sort $meta->get_method_list),
81 join(' ', sort qw(meta pawn king has_pawn MY_CONST stub stub_with_attr))
90 my $meta3 = Class->meta;
91 is($meta, $meta3, "same metaclass instance, even if use Mouse is performed again");
93 is($meta->name, 'Class', "name for the metaclass");
96 my $child_meta = Child->meta;
97 isa_ok($child_meta, 'Mouse::Meta::Class');
99 isnt($meta, $child_meta, "different metaclass instances for the two classes");
101 is_deeply([$child_meta->superclasses], ['Class'], "correct superclasses");
104 ok($child_meta->has_attribute('bishop'));
105 ok($child_meta->has_method('child_method'));
108 is( join(' ', sort $child_meta->get_method_list),
109 join(' ', sort qw(meta bishop child_method))
112 can_ok($child_meta, 'find_method_by_name');
113 is $child_meta->find_method_by_name('child_method')->fully_qualified_name, 'Child::child_method';
114 is $child_meta->find_method_by_name('pawn')->fully_qualified_name, 'Class::pawn';
117 is( join(' ', sort map{ $_->fully_qualified_name } grep{ $_->package_name ne 'Mouse::Object' } $child_meta->get_all_methods),
119 Child::bishop Child::child_method Child::meta
121 Class::MY_CONST Class::has_pawn Class::pawn Class::king Class::stub Class::stub_with_attr