Make Mouse::Util::load_class return the argument class name, which can remove several...
[gitmo/Mouse.git] / t / 030_roles / 036_free_anonymous_roles.t
CommitLineData
7a50b450 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More tests => 4;
43408273 5use Mouse::Role ();
7a50b450 6use Scalar::Util 'weaken';
7
8my $weak;
9my $name;
10do {
11 my $anon_class;
12
13 do {
14 my $role = Mouse::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 = Mouse::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
32ok(!$weak, "the role metaclass is freed after its last reference (from a consuming anonymous class) is freed");
33
34ok(!$name->can('improperly_freed'), "we blew away the role's symbol table entries");