17 sub make_anon_instance{
19 my $class = ref $self || $self;
21 my $anon_class = Class::MOP::Class->create_anon_class(superclasses => [$class]);
22 $anon_class_name = $anon_class->name;
23 $anon_meta_name = Scalar::Util::blessed($anon_class);
24 $anon_class->add_attribute( $_, reader => $_ ) for qw/bar baz/;
26 my $obj = $anon_class->new_object(bar => 'a', baz => 'b');
35 my $instance = Foo->make_anon_instance;
37 isa_ok($instance, $anon_class_name);
38 isa_ok($instance->meta, $anon_meta_name);
39 isa_ok($instance, 'Foo', '... Anonymous instance isa Foo');
41 ok($instance->can('foo'), '... Anonymous instance can foo');
42 ok($instance->meta->find_method_by_name('foo'), '... Anonymous instance has method foo');
44 ok($instance->meta->has_attribute('bar'), '... Anonymous instance still has attribute bar');
45 ok($instance->meta->has_attribute('baz'), '... Anonymous instance still has attribute baz');
46 is($instance->bar, 'a', '... Anonymous instance still has correct bar value');
47 is($instance->baz, 'b', '... Anonymous instance still has correct baz value');
49 is_deeply([$instance->meta->class_precedence_list],
50 [$anon_class_name, 'Foo'],
51 '... Anonymous instance has class precedence list',