6 use Test::More tests => 9;
15 my $anon_class = Class::MOP::Class->create_anon_class();
16 isa_ok($anon_class, 'Class::MOP::Class');
18 ($anon_class_id) = ($anon_class->name =~ /Class::MOP::Class::__ANON__::SERIAL::(\d+)/);
20 ok(exists $main::Class::MOP::Class::__ANON__::SERIAL::{$anon_class_id . '::'}, '... the package exists');
22 like($anon_class->name, qr/Class::MOP::Class::__ANON__::SERIAL::[0-9]+/, '... got an anon class package name');
25 $anon_class->add_method('foo' => sub { "__ANON__::foo" });
26 } '... added a method to my anon-class';
28 my $instance = $anon_class->new_object();
29 isa_ok($instance, $anon_class->name);
31 is($instance->foo, '__ANON__::foo', '... got the right return value of our foo method');
34 ok(!exists $main::Class::MOP::Class::__ANON__::SERIAL::{$anon_class_id . '::'}, '... the package no longer exists');
37 # I bumped this test up to 100_000 instances, and
38 # still got not conflicts. If your application needs
39 # more than that, your probably mst
42 foreach my $i (1 .. 1000) {
43 $conflicts{ Class::MOP::Class->create_anon_class()->name } = undef;
45 is(scalar(keys %conflicts), 1000, '... got as many classes as I would expect');