6 use Test::More 'no_plan';
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 Foo->meta->add_attribute('moosen');
40 Bar->meta->add_attribute('elken');
43 my $mi_foo = Foo->meta->get_meta_instance;
44 isa_ok($mi_foo, "Class::MOP::Instance");
47 [ $mi_foo->get_all_slots ],
49 '... get all slots for Foo');
51 my $mi_bar = Bar->meta->get_meta_instance;
52 isa_ok($mi_bar, "Class::MOP::Instance");
54 isnt($mi_foo, $mi_bar, '... they are not the same instance');
57 [ sort $mi_bar->get_all_slots ],
58 [ "elken", "moosen" ],
59 '... get all slots for Bar');
61 my $i_foo = $mi_foo->create_instance;
62 isa_ok($i_foo, "Foo");
65 my $i_foo_2 = $mi_foo->create_instance;
66 isa_ok($i_foo_2, "Foo");
67 isnt($i_foo_2, $i_foo, '... not the same instance');
68 is_deeply($i_foo, $i_foo_2, '... but the same structure');
71 ok(!defined($mi_foo->get_slot_value( $i_foo, "moosen" )), "... no value for slot");
73 $mi_foo->set_slot_value( $i_foo, "moosen", "the value" );
75 is($mi_foo->get_slot_value( $i_foo, "moosen" ), "the value", "... get slot value");
77 ok(!$i_foo->can('moosen'), '... Foo cant moosen');
79 can_ok( $mi_foo, "set_slot_value_weak" );
82 $mi_foo->set_slot_value_weak( $i_foo, "moosen", $ref );
84 is( $mi_foo->get_slot_value( $i_foo, "moosen" ), $ref, "weak value is fetchable" );
86 ok( !isweak($mi_foo->get_slot_value( $i_foo, "moosen" )), "return value not weak" );
90 is( $mi_foo->get_slot_value( $i_foo, "moosen" ), undef, "weak value destroyed" );
94 $mi_foo->set_slot_value( $i_foo, "moosen", $ref );
98 is( reftype( $mi_foo->get_slot_value( $i_foo, "moosen" ) ), "ARRAY", "value not weak yet" );
100 $mi_foo->weaken_slot_value( $i_foo, "moosen" );
102 is( $mi_foo->get_slot_value( $i_foo, "moosen" ), undef, "weak value destroyed" );
107 $mi_foo->set_slot_value( $i_foo, "moosen", $ref );
110 $mi_foo->weaken_slot_value( $i_foo, "moosen" );
112 $mi_foo->strengthen_slot_value( $i_foo, "moosen" );
116 is( reftype( $mi_foo->get_slot_value( $i_foo, "moosen" ) ), "ARRAY", "weak value can be strengthened" );