X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F046_rebless_instance.t;h=7eb0f68b3dd8ae17edbecbd701c769e3a1fcc23b;hb=0708313d80515eebcc37dd2cfa6537ca3971c827;hp=f5e8b0e9608a0e1ee28692284d6e3e09b25b18a5;hpb=3e2c8600b98f2c7c0c84d1a94a565c801ca7aa3d;p=gitmo%2FClass-MOP.git diff --git a/t/046_rebless_instance.t b/t/046_rebless_instance.t index f5e8b0e..7eb0f68 100644 --- a/t/046_rebless_instance.t +++ b/t/046_rebless_instance.t @@ -47,6 +47,18 @@ throws_ok { LeftField->meta->rebless_instance($foo) } throws_ok { Class::MOP::Class->initialize("NonExistent")->rebless_instance($foo) } qr/You may rebless only into a subclass of \(Child\), of which \(NonExistent\) isn't\./; +Parent->meta->rebless_instance_back($foo); +is(blessed($foo), 'Parent', 'Parent->new gives a Parent'); +is($foo->whoami, "parent", 'Parent->whoami gives parent'); +is($foo->parent, "parent", 'Parent->parent gives parent'); +dies_ok { $foo->child } "Parent->child method doesn't exist"; + +throws_ok { LeftField->meta->rebless_instance_back($foo) } + qr/You may rebless only into a superclass of \(Parent\), of which \(LeftField\) isn't\./; + +throws_ok { Class::MOP::Class->initialize("NonExistent")->rebless_instance_back($foo) } + qr/You may rebless only into a superclass of \(Parent\), of which \(NonExistent\) isn't\./; + # make sure our ->meta is still sane my $bar = Parent->new; is(blessed($bar), 'Parent', "sanity check"); @@ -73,4 +85,15 @@ ok($bar->meta->has_method('child'), 'metaclass has "child" method'); is(blessed($bar->meta->new_object), 'Child', 'new_object gives a Child'); +Parent->meta->rebless_instance_back($bar); +is(blessed($bar), 'Parent', "sanity check"); +is(blessed($bar->meta), 'Class::MOP::Class', "meta gives a Class::MOP::Class"); +is($bar->meta->name, 'Parent', "this Class::MOP::Class instance is for Parent"); + +ok($bar->meta->has_method('new'), 'metaclass has "new" method'); +ok($bar->meta->has_method('whoami'), 'metaclass has "whoami" method'); +ok($bar->meta->has_method('parent'), 'metaclass has "parent" method'); + +is(blessed($bar->meta->new_object), 'Parent', 'new_object gives a Parent'); + done_testing;