6 use Test::More tests => 30;
9 use Scalar::Util 'reftype', 'isweak';
12 use_ok('Class::MOP::Instance');
15 can_ok( "Class::MOP::Instance", $_ ) for qw/
17 bless_instance_structure
22 get_all_slots_recursively
31 set_slot_value_with_init
35 inline_initialize_slot
36 inline_set_slot_value_with_init
48 isa_ok( my $mi_foo = Foo->meta->get_meta_instance, "Class::MOP::Instance" );
50 $mi_foo->add_slot("moosen");
52 is_deeply( [ $mi_foo->get_all_slots ], [ "moosen" ], "get slots" );
55 my $mi_bar = Bar->meta->get_meta_instance;
57 is_deeply( [ $mi_bar->get_all_slots ], [], "get slots" );
58 is_deeply( [ $mi_bar->get_all_slots_recursively ], ["moosen"], "get slots rec" );
60 $mi_bar->add_slot("elken");
62 is_deeply( [ sort $mi_bar->get_all_slots_recursively ], [qw/elken moosen/], "get slots rec" );
64 isa_ok( my $i_foo = $mi_foo->create_instance, "Foo" );
66 ok( !$mi_foo->get_slot_value( $i_foo, "moosen" ), "no value for slot");
68 $mi_foo->initialize_slot( $i_foo, "moosen" );
69 $mi_foo->set_slot_value( $i_foo, "moosen", "the value" );
71 is ( $mi_foo->get_slot_value( $i_foo, "moosen" ), "the value", "get slot value" );
73 eval 'sub Foo::moosen { ' . $mi_foo->inline_get_slot_value( '$_[0]', '"moosen"' ) . ' }';
74 ok( !$@, "compilation of inline get value had no error" );
76 is( $i_foo->moosen, "the value", "inline get value" );
78 $mi_foo->set_slot_value( $i_foo, "moosen", "the other value" );
80 is( $i_foo->moosen, "the other value", "inline get value");