Add another MOOSE_TEST_MD option, MooseX
[gitmo/Moose.git] / t / roles / free_anonymous_roles.t
CommitLineData
db121d24 1#!/usr/bin/env perl
2use strict;
3use warnings;
a28e50e4 4use Test::More;
db121d24 5use Moose ();
6use Scalar::Util 'weaken';
7
8my $weak;
941d8c32 9my $name;
db121d24 10do {
11 my $anon_class;
12
13 do {
941d8c32 14 my $role = Moose::Meta::Role->create_anon_role(
15 methods => {
16 improperly_freed => sub { 1 },
17 },
18 );
db121d24 19 weaken($weak = $role);
20
941d8c32 21 $name = $role->name;
22
db121d24 23 $anon_class = Moose::Meta::Class->create_anon_class(
24 roles => [ $role->name ],
25 );
26 };
27
28 ok($weak, "we still have the role metaclass because the anonymous class that consumed it is still alive");
941d8c32 29 ok($name->can('improperly_freed'), "we have not blown away the role's symbol table");
db121d24 30};
31
d1765290 32ok(!$weak, "the role metaclass is freed after its last reference (from a consuming anonymous class) is freed");
db121d24 33
941d8c32 34ok(!$name->can('improperly_freed'), "we blew away the role's symbol table entries");
a28e50e4 35
6f73c555 36do {
37 my $anon_class;
38
39 do {
40 my $role = Moose::Meta::Role->create_anon_role(
41 methods => {
42 improperly_freed => sub { 1 },
43 },
44 weaken => 0,
45 );
46 weaken($weak = $role);
47
48 $name = $role->name;
49
50 $anon_class = Moose::Meta::Class->create_anon_class(
51 roles => [ $role->name ],
52 );
53 };
54
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");
57};
58
59ok($weak, "the role metaclass still exists because we told it not to weaken");
60
61ok($name->can('improperly_freed'), "the symbol table still exists too");
62
a28e50e4 63done_testing;