Commit | Line | Data |
c3398f5b |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
986ff64a |
4 | use Test::More tests => 14; |
c3398f5b |
5 | |
6 | do { |
7 | package Class; |
8 | use Mouse; |
9 | |
10 | has pawn => ( |
11 | is => 'rw', |
12 | predicate => 'has_pawn', |
13 | ); |
14 | |
15 | no Mouse; |
16 | }; |
17 | |
18 | my $meta = Class->meta; |
306290e8 |
19 | isa_ok($meta, 'Mouse::Meta::Class'); |
c3398f5b |
20 | |
21 | is_deeply([$meta->superclasses], ['Mouse::Object'], "correctly inherting from Mouse::Object"); |
22 | |
23 | my $meta2 = Class->meta; |
24 | is($meta, $meta2, "same metaclass instance"); |
25 | |
f89acace |
26 | can_ok($meta, 'name', 'get_attribute_map'); |
c3398f5b |
27 | |
986ff64a |
28 | ok($meta->has_attribute('pawn')); |
c3398f5b |
29 | my $attr = $meta->get_attribute('pawn'); |
306290e8 |
30 | isa_ok($attr, 'Mouse::Meta::Attribute'); |
c3398f5b |
31 | is($attr->name, 'pawn', 'got the correct attribute'); |
32 | |
33 | my $map = $meta->get_attribute_map; |
34 | is_deeply($map, { pawn => $attr }, "attribute map"); |
35 | |
986ff64a |
36 | ok(!$meta->has_attribute('nonexistent_attribute')); |
37 | |
c3398f5b |
38 | eval " |
39 | package Class; |
40 | use Mouse; |
41 | no Mouse; |
42 | "; |
43 | |
44 | my $meta3 = Class->meta; |
45 | is($meta, $meta3, "same metaclass instance, even if use Mouse is performed again"); |
46 | |
47 | is($meta->name, 'Class', "name for the metaclass"); |
48 | |
49 | do { |
50 | package Child; |
51 | use Mouse; |
52 | extends 'Class'; |
53 | }; |
54 | |
55 | my $child_meta = Child->meta; |
306290e8 |
56 | isa_ok($child_meta, 'Mouse::Meta::Class'); |
c3398f5b |
57 | |
58 | isnt($meta, $child_meta, "different metaclass instances for the two classes"); |
59 | |
60 | is_deeply([$child_meta->superclasses], ['Class'], "correct superclasses"); |