Commit | Line | Data |
587aca23 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
40483095 |
6 | use Test::More tests => 9; |
587aca23 |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
10 | use_ok('Class::MOP'); |
11 | } |
12 | |
40483095 |
13 | my $anon_class_id; |
14 | { |
15 | my $anon_class = Class::MOP::Class->create_anon_class(); |
16 | isa_ok($anon_class, 'Class::MOP::Class'); |
17 | |
18 | ($anon_class_id) = ($anon_class->name =~ /Class::MOP::Class::__ANON__::SERIAL::(\d+)/); |
19 | |
20 | ok(exists $main::Class::MOP::Class::__ANON__::SERIAL::{$anon_class_id . '::'}, '... the package exists'); |
21 | |
22 | like($anon_class->name, qr/Class::MOP::Class::__ANON__::SERIAL::[0-9]+/, '... got an anon class package name'); |
23 | |
24 | lives_ok { |
25 | $anon_class->add_method('foo' => sub { "__ANON__::foo" }); |
26 | } '... added a method to my anon-class'; |
27 | |
28 | my $instance = $anon_class->new_object(); |
29 | isa_ok($instance, $anon_class->name); |
30 | |
31 | is($instance->foo, '__ANON__::foo', '... got the right return value of our foo method'); |
32 | } |
587aca23 |
33 | |
40483095 |
34 | ok(!exists $main::Class::MOP::Class::__ANON__::SERIAL::{$anon_class_id . '::'}, '... the package no longer exists'); |
587aca23 |
35 | |
36 | # NOTE: |
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 |
40 | |
41 | my %conflicts; |
42 | foreach my $i (1 .. 1000) { |
43 | $conflicts{ Class::MOP::Class->create_anon_class()->name } = undef; |
44 | } |
45 | is(scalar(keys %conflicts), 1000, '... got as many classes as I would expect'); |
46 | |