Commit | Line | Data |
db121d24 |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
a28e50e4 |
4 | use Test::More; |
db121d24 |
5 | use Moose (); |
6 | use Scalar::Util 'weaken'; |
7 | |
8 | my $weak; |
941d8c32 |
9 | my $name; |
db121d24 |
10 | do { |
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 |
32 | ok(!$weak, "the role metaclass is freed after its last reference (from a consuming anonymous class) is freed"); |
db121d24 |
33 | |
941d8c32 |
34 | ok(!$name->can('improperly_freed'), "we blew away the role's symbol table entries"); |
a28e50e4 |
35 | |
6f73c555 |
36 | do { |
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 | |
59 | ok($weak, "the role metaclass still exists because we told it not to weaken"); |
60 | |
61 | ok($name->can('improperly_freed'), "the symbol table still exists too"); |
62 | |
a28e50e4 |
63 | done_testing; |