5 use Test::LeakTrace 0.01;
6 use Test::Memory::Cycle;
9 use Moose::Util qw( apply_all_roles );
14 sub myname { "I'm a role" }
19 Moose::Meta::Class->create_anon_class->new_object;
21 'anonymous class with no roles is leak-free'
26 Moose::Meta::Role->initialize('MyRole2');
28 'Moose::Meta::Role->initialize is leak-free'
33 Moose::Meta::Class->create('MyClass2')->new_object;
35 'creating named class is leak-free'
40 = 'role application leaks because we end up applying the role more than once to the meta object';
43 Moose::Meta::Class->create( 'MyClass', roles => ['MyRole'] );
45 'named class with roles is leak-free'
50 Moose::Meta::Role->create( 'MyRole2', roles => ['MyRole'] );
52 'named role with roles is leak-free'
58 my $object = Moose::Meta::Class->create('MyClass2')->new_object;
59 apply_all_roles( $object, 'MyRole' );
61 'applying role to an instance is leak-free'
66 Moose::Meta::Role->create_anon_role;
68 'anonymous role is leak-free'
72 # fixing this leak currently triggers a bug in Carp
73 # we can un-TODO once that fix goes in allowing the leak
74 # in Eval::Closure to be fixed
75 local $TODO = 'Eval::Closure leaks a bit at the moment';
78 my $meta = Moose::Meta::Class->create_anon_class;
79 $meta->make_immutable;
81 'making an anon class immutable is leak-free'
86 my $meta3 = Moose::Meta::Class->create('MyClass3');
87 memory_cycle_ok( $meta3, 'named metaclass object is cycle-free' );
88 memory_cycle_ok( $meta3->new_object, 'MyClass3 object is cycle-free' );
90 my $anon_class = Moose::Meta::Class->create_anon_class;
91 memory_cycle_ok($anon_class, 'anon metaclass object is cycle-free' );
92 memory_cycle_ok( $anon_class->new_object, 'object from anon metaclass is cycle-free' );
94 $anon_class->make_immutable;
95 memory_cycle_ok($anon_class, 'immutable anon metaclass object is cycle-free' );
96 memory_cycle_ok( $anon_class->new_object, 'object from immutable anon metaclass is cycle-free' );
98 my $anon_role = Moose::Meta::Role->create_anon_role;
99 memory_cycle_ok($anon_role, 'anon role meta object is cycle-free' );