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 :  /proc/self/root/proc/self/root/usr/share/doc/perl-Moose/t/roles/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/proc/self/root/usr/share/doc/perl-Moose/t/roles/free_anonymous_roles.t
use strict;
use warnings;
use Test::More;
use Moose ();
use Scalar::Util 'weaken';

my $weak;
my $name;
do {
    my $anon_class;

    do {
        my $role = Moose::Meta::Role->create_anon_role(
            methods => {
                improperly_freed => sub { 1 },
            },
        );
        weaken($weak = $role);

        $name = $role->name;

        $anon_class = Moose::Meta::Class->create_anon_class(
            roles => [ $role->name ],
        );
    };

    ok($weak, "we still have the role metaclass because the anonymous class that consumed it is still alive");
    ok($name->can('improperly_freed'), "we have not blown away the role's symbol table");
};

ok(!$weak, "the role metaclass is freed after its last reference (from a consuming anonymous class) is freed");

ok(!$name->can('improperly_freed'), "we blew away the role's symbol table entries");

do {
    my $anon_class;

    do {
        my $role = Moose::Meta::Role->create_anon_role(
            methods => {
                improperly_freed => sub { 1 },
            },
            weaken => 0,
        );
        weaken($weak = $role);

        $name = $role->name;

        $anon_class = Moose::Meta::Class->create_anon_class(
            roles => [ $role->name ],
        );
    };

    ok($weak, "we still have the role metaclass because the anonymous class that consumed it is still alive");
    ok($name->can('improperly_freed'), "we have not blown away the role's symbol table");
};

ok($weak, "the role metaclass still exists because we told it not to weaken");

ok($name->can('improperly_freed'), "the symbol table still exists too");

done_testing;

Hry