7 use File::Spec::Functions;
9 use Test::More tests => 35;
14 use lib catdir($FindBin::Bin, 'lib');
16 # make sure the Class::MOP::Class->meta does the right thing
18 my $meta = Class::MOP::Class->meta();
19 isa_ok($meta, 'Class::MOP::Class');
21 my $new_meta = $meta->new_object('package' => 'Class::MOP::Class');
22 isa_ok($new_meta, 'Class::MOP::Class');
23 is($new_meta, $meta, '... it still creates the singleton');
25 my $cloned_meta = $meta->clone_object($meta);
26 isa_ok($cloned_meta, 'Class::MOP::Class');
27 is($cloned_meta, $meta, '... it creates the singleton even if you try to clone it');
29 # make sure other metaclasses do the right thing
36 my $foo_meta = Foo->meta;
37 isa_ok($foo_meta, 'Class::MOP::Class');
39 is($meta->new_object('package' => 'Foo'), $foo_meta, '... got the right Foo->meta singleton');
40 is($meta->clone_object($foo_meta), $foo_meta, '... cloning got the right Foo->meta singleton');
42 # make sure subclassed of Class::MOP::Class do the right thing
44 my $my_meta = MyMetaClass->meta;
45 isa_ok($my_meta, 'Class::MOP::Class');
47 my $new_my_meta = $my_meta->new_object('package' => 'MyMetaClass');
48 isa_ok($new_my_meta, 'Class::MOP::Class');
49 is($new_my_meta, $my_meta, '... even subclasses still create the singleton');
51 my $cloned_my_meta = $meta->clone_object($my_meta);
52 isa_ok($cloned_my_meta, 'Class::MOP::Class');
53 is($cloned_my_meta, $my_meta, '... and subclasses creates the singleton even if you try to clone it');
55 is($my_meta->new_object('package' => 'Foo'), $foo_meta, '... got the right Foo->meta singleton (w/subclass)');
56 is($meta->clone_object($foo_meta), $foo_meta, '... cloning got the right Foo->meta singleton (w/subclass)');
58 # now create a metaclass for real
60 my $bar_meta = $my_meta->new_object('package' => 'Bar');
61 isa_ok($bar_meta, 'Class::MOP::Class');
63 is($bar_meta->name, 'Bar', '... got the right name for the Bar metaclass');
64 is($bar_meta->version, undef, '... Bar does not exists, so it has no version');
66 $bar_meta->superclasses('Foo');
68 # check with MyMetaClass
72 use metaclass 'MyMetaClass';
75 my $baz_meta = Baz->meta;
76 isa_ok($baz_meta, 'Class::MOP::Class');
77 isa_ok($baz_meta, 'MyMetaClass');
79 is($my_meta->new_object('package' => 'Baz'), $baz_meta, '... got the right Baz->meta singleton');
80 is($my_meta->clone_object($baz_meta), $baz_meta, '... cloning got the right Baz->meta singleton');
82 $baz_meta->superclasses('Bar');
84 # now create a regular objects for real
86 my $foo = $foo_meta->new_object();
89 my $bar = $bar_meta->new_object();
93 my $baz = $baz_meta->new_object();
98 my $cloned_foo = $foo_meta->clone_object($foo);
99 isa_ok($cloned_foo, 'Foo');
101 isnt($cloned_foo, $foo, '... $cloned_foo is a new object different from $foo');
106 $foo_meta->clone_object($meta);
107 } '... this dies as expected';
115 FooBar->meta->add_attribute('test');
118 my $attr = FooBar->meta->get_attribute('test');
119 isa_ok($attr, 'Class::MOP::Attribute');
121 my $attr_clone = $attr->clone();
122 isa_ok($attr_clone, 'Class::MOP::Attribute');
124 isnt($attr, $attr_clone, '... we successfully cloned our attributes');
125 is($attr->associated_class,
126 $attr_clone->associated_class,
127 '... we successfully did not clone our associated metaclass');