Commit | Line | Data |
8b978dd5 |
1 | use strict; |
2 | use warnings; |
3 | |
efd3d14c |
4 | use Test::More tests => 23; |
0882828e |
5 | use Test::Exception; |
8b978dd5 |
6 | |
efd3d14c |
7 | use Class::MOP; |
8 | use Class::MOP::Class; |
8b978dd5 |
9 | |
10 | { |
11 | package Foo; |
aa448b16 |
12 | use metaclass; |
8b978dd5 |
13 | our $VERSION = '0.01'; |
14 | |
15 | package Bar; |
16 | our @ISA = ('Foo'); |
88dd563c |
17 | |
18 | our $AUTHORITY = 'cpan:JRANDOM'; |
8b978dd5 |
19 | } |
20 | |
aa448b16 |
21 | my $Foo = Foo->meta; |
8b978dd5 |
22 | isa_ok($Foo, 'Class::MOP::Class'); |
23 | |
aa448b16 |
24 | my $Bar = Bar->meta; |
8b978dd5 |
25 | isa_ok($Bar, 'Class::MOP::Class'); |
26 | |
27 | is($Foo->name, 'Foo', '... Foo->name == Foo'); |
28 | is($Bar->name, 'Bar', '... Bar->name == Bar'); |
29 | |
30 | is($Foo->version, '0.01', '... Foo->version == 0.01'); |
31 | is($Bar->version, undef, '... Bar->version == undef'); |
32 | |
88dd563c |
33 | is($Foo->authority, undef, '... Foo->authority == undef'); |
34 | is($Bar->authority, 'cpan:JRANDOM', '... Bar->authority == cpan:JRANDOM'); |
35 | |
36 | is($Foo->identifier, 'Foo-0.01', '... Foo->identifier == Foo-0.01'); |
37 | is($Bar->identifier, 'Bar-cpan:JRANDOM', '... Bar->identifier == Bar-cpan:JRANDOM'); |
38 | |
8b978dd5 |
39 | is_deeply([$Foo->superclasses], [], '... Foo has no superclasses'); |
40 | is_deeply([$Bar->superclasses], ['Foo'], '... Bar->superclasses == (Foo)'); |
41 | |
42 | $Foo->superclasses('UNIVERSAL'); |
43 | |
44 | is_deeply([$Foo->superclasses], ['UNIVERSAL'], '... Foo->superclasses == (UNIVERSAL) now'); |
45 | |
46 | is_deeply( |
47 | [ $Foo->class_precedence_list ], |
48 | [ 'Foo', 'UNIVERSAL' ], |
49 | '... Foo->class_precedence_list == (Foo, UNIVERSAL)'); |
50 | |
51 | is_deeply( |
52 | [ $Bar->class_precedence_list ], |
53 | [ 'Bar', 'Foo', 'UNIVERSAL' ], |
54 | '... Bar->class_precedence_list == (Bar, Foo, UNIVERSAL)'); |
55 | |
56 | # create a class using Class::MOP::Class ... |
57 | |
58 | my $Baz = Class::MOP::Class->create( |
88dd563c |
59 | 'Baz' => ( |
60 | version => '0.10', |
61 | authority => 'cpan:YOMAMA', |
8b978dd5 |
62 | superclasses => [ 'Bar' ] |
63 | )); |
64 | isa_ok($Baz, 'Class::MOP::Class'); |
aa448b16 |
65 | is(Baz->meta, $Baz, '... our metaclasses are singletons'); |
8b978dd5 |
66 | |
67 | is($Baz->name, 'Baz', '... Baz->name == Baz'); |
68 | is($Baz->version, '0.10', '... Baz->version == 0.10'); |
88dd563c |
69 | is($Baz->authority, 'cpan:YOMAMA', '... Baz->authority == YOMAMA'); |
70 | |
71 | is($Baz->identifier, 'Baz-0.10-cpan:YOMAMA', '... Baz->identifier == Baz-0.10-cpan:YOMAMA'); |
8b978dd5 |
72 | |
73 | is_deeply([$Baz->superclasses], ['Bar'], '... Baz->superclasses == (Bar)'); |
74 | |
75 | is_deeply( |
76 | [ $Baz->class_precedence_list ], |
77 | [ 'Baz', 'Bar', 'Foo', 'UNIVERSAL' ], |
78 | '... Baz->class_precedence_list == (Baz, Bar, Foo, UNIVERSAL)'); |
d41e86f2 |
79 | |