Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /usr/share/doc/perl-Moose/t/bugs/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/perl-Moose/t/bugs/DEMOLISH_fails_without_metaclass.t
use strict;
use warnings;

use Test::More;
use Test::Fatal;

{
    package MyClass;
    use Moose;

    sub DEMOLISH { }
}

my $object = MyClass->new;

# Removing the metaclass simulates the case where the metaclass object
# goes out of scope _before_ the object itself, which under normal
# circumstances only happens during global destruction.
Class::MOP::remove_metaclass_by_name('MyClass');

# The bug happened when DEMOLISHALL called
# Class::MOP::class_of($object) and did not get a metaclass object
# back.
is( exception { $object->DESTROY }, undef, 'can call DESTROY on an object without a metaclass object in the CMOP cache' );


MyClass->meta->make_immutable;
Class::MOP::remove_metaclass_by_name('MyClass');

# The bug didn't manifest for immutable objects, but this test should
# help us prevent it happening in the future.
is( exception { $object->DESTROY }, undef, 'can call DESTROY on an object without a metaclass object in the CMOP cache (immutable version)' );

done_testing;

Hry