8426fed867318586973d842e4a9ceb1901d8acb3
[gitmo/Mouse.git] / t / 030_roles / 036_free_anonymous_roles.t
1 #!/usr/bin/env perl
2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
5 use strict;
6 use warnings;
7 use Test::More;
8 use Mouse ();
9 use Scalar::Util 'weaken';
10
11 my $weak;
12 my $name;
13 do {
14     my $anon_class;
15
16     do {
17         my $role = Mouse::Meta::Role->create_anon_role(
18             methods => {
19                 improperly_freed => sub { 1 },
20             },
21         );
22         weaken($weak = $role);
23
24         $name = $role->name;
25
26         $anon_class = Mouse::Meta::Class->create_anon_class(
27             roles => [ $role->name ],
28         );
29     };
30
31     ok($weak, "we still have the role metaclass because the anonymous class that consumed it is still alive");
32     ok($name->can('improperly_freed'), "we have not blown away the role's symbol table");
33 };
34
35 ok(!$weak, "the role metaclass is freed after its last reference (from a consuming anonymous class) is freed");
36
37 ok(!$name->can('improperly_freed'), "we blew away the role's symbol table entries");
38
39 done_testing;