0_30
[gitmo/Class-MOP.git] / t / 018_anon_class.t
CommitLineData
587aca23 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 7;
7use Test::Exception;
8
9BEGIN {
10 use_ok('Class::MOP');
11}
12
13my $anon_class = Class::MOP::Class->create_anon_class();
14isa_ok($anon_class, 'Class::MOP::Class');
15
c3e7c446 16like($anon_class->name, qr/Class::MOP::Class::__ANON__::SERIAL::[0-9]+/, '... got an anon class package name');
587aca23 17
18lives_ok {
19 $anon_class->add_method('foo' => sub { "__ANON__::foo" });
20} '... added a method to my anon-class';
21
22my $instance = $anon_class->new_object();
23isa_ok($instance, $anon_class->name);
24
25is($instance->foo, '__ANON__::foo', '... got the right return value of our foo method');
26
27# NOTE:
28# I bumped this test up to 100_000 instances, and
29# still got not conflicts. If your application needs
30# more than that, your probably mst
31
32my %conflicts;
33foreach my $i (1 .. 1000) {
34 $conflicts{ Class::MOP::Class->create_anon_class()->name } = undef;
35}
36is(scalar(keys %conflicts), 1000, '... got as many classes as I would expect');
37