fix punctuation
[gitmo/Moose.git] / t / roles / free_anonymous_roles.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use Test::More;
5 use Moose ();
6 use Scalar::Util 'weaken';
7
8 my $weak;
9 my $name;
10 do {
11     my $anon_class;
12
13     do {
14         my $role = Moose::Meta::Role->create_anon_role(
15             methods => {
16                 improperly_freed => sub { 1 },
17             },
18         );
19         weaken($weak = $role);
20
21         $name = $role->name;
22
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");
29     ok($name->can('improperly_freed'), "we have not blown away the role's symbol table");
30 };
31
32 ok(!$weak, "the role metaclass is freed after its last reference (from a consuming anonymous class) is freed");
33
34 ok(!$name->can('improperly_freed'), "we blew away the role's symbol table entries");
35
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
63 done_testing;