6 use Scalar::Util 'weaken';
14 my $role = Moose::Meta::Role->create_anon_role(
16 improperly_freed => sub { 1 },
19 weaken($weak = $role);
23 $anon_class = Moose::Meta::Class->create_anon_class(
24 roles => [ $role->name ],
28 ok($weak, "we still have the role metaclass because the anonymous class that consumed it is still alive");
29 ok($name->can('improperly_freed'), "we have not blown away the role's symbol table");
32 ok(!$weak, "the role metaclass is freed after its last reference (from a consuming anonymous class) is freed");
34 ok(!$name->can('improperly_freed'), "we blew away the role's symbol table entries");
40 my $role = Moose::Meta::Role->create_anon_role(
42 improperly_freed => sub { 1 },
46 weaken($weak = $role);
50 $anon_class = Moose::Meta::Class->create_anon_class(
51 roles => [ $role->name ],
55 ok($weak, "we still have the role metaclass because the anonymous class that consumed it is still alive");
56 ok($name->can('improperly_freed'), "we have not blown away the role's symbol table");
59 ok($weak, "the role metaclass still exists because we told it not to weaken");
61 ok($name->can('improperly_freed'), "the symbol table still exists too");