6 use Test::More tests => 39;
9 use Scalar::Util qw/isweak reftype/;
12 use_ok('Class::MOP::Instance');
15 can_ok( "Class::MOP::Instance", $_ ) for qw/
19 bless_instance_structure
34 inline_initialize_slot
35 inline_is_slot_initialized
36 inline_weaken_slot_value
37 inline_strengthen_slot_value
44 Foo->meta->add_attribute('moosen');
50 Bar->meta->add_attribute('elken');
53 my $mi_foo = Foo->meta->get_meta_instance;
54 isa_ok($mi_foo, "Class::MOP::Instance");
57 [ $mi_foo->get_all_slots ],
59 '... get all slots for Foo');
61 my $mi_bar = Bar->meta->get_meta_instance;
62 isa_ok($mi_bar, "Class::MOP::Instance");
64 isnt($mi_foo, $mi_bar, '... they are not the same instance');
67 [ sort $mi_bar->get_all_slots ],
68 [ "elken", "moosen" ],
69 '... get all slots for Bar');
71 my $i_foo = $mi_foo->create_instance;
72 isa_ok($i_foo, "Foo");
75 my $i_foo_2 = $mi_foo->create_instance;
76 isa_ok($i_foo_2, "Foo");
77 isnt($i_foo_2, $i_foo, '... not the same instance');
78 is_deeply($i_foo, $i_foo_2, '... but the same structure');
81 ok(!defined($mi_foo->get_slot_value( $i_foo, "moosen" )), "... no value for slot");
83 $mi_foo->set_slot_value( $i_foo, "moosen", "the value" );
85 is($mi_foo->get_slot_value( $i_foo, "moosen" ), "the value", "... get slot value");
86 ok(!$i_foo->can('moosen'), '... Foo cant moosen');
90 $mi_foo->set_slot_value( $i_foo, "moosen", $ref );
91 $mi_foo->weaken_slot_value( $i_foo, "moosen" );
93 ok( isweak($i_foo->{moosen}), '... white box test of weaken' );
94 is( $mi_foo->get_slot_value( $i_foo, "moosen" ), $ref, "weak value is fetchable" );
95 ok( !isweak($mi_foo->get_slot_value( $i_foo, "moosen" )), "return value not weak" );
99 is( $mi_foo->get_slot_value( $i_foo, "moosen" ), undef, "weak value destroyed" );
103 $mi_foo->set_slot_value( $i_foo, "moosen", $ref );
107 is( reftype( $mi_foo->get_slot_value( $i_foo, "moosen" ) ), "ARRAY", "value not weak yet" );
109 $mi_foo->weaken_slot_value( $i_foo, "moosen" );
111 is( $mi_foo->get_slot_value( $i_foo, "moosen" ), undef, "weak value destroyed" );
115 $mi_foo->set_slot_value( $i_foo, "moosen", $ref );
116 $mi_foo->weaken_slot_value( $i_foo, "moosen" );
117 ok( isweak($i_foo->{moosen}), '... white box test of weaken' );
118 $mi_foo->strengthen_slot_value( $i_foo, "moosen" );
119 ok( !isweak($i_foo->{moosen}), '... white box test of weaken' );
123 is( reftype( $mi_foo->get_slot_value( $i_foo, "moosen" ) ), "ARRAY", "weak value can be strengthened" );