exists $instance->{$slot_name} ? 1 : 0;
}
+sub set_slot_value_weak {
+ my ($self, $instance, $slot_name, $value) = @_;
+ $self->set_slot_value($instance, $slot_name, $value);
+ $self->weaken_slot_value($instance, $slot_name);
+}
+
+sub weaken_slot_value {
+ my ($self, $instance, $slot_name) = @_;
+ weaken $instance->{$slot_name};
+}
+
+sub strengthen_slot_value {
+ my ($self, $instance, $slot_name) = @_;
+ $self->set_slot_value($instance, $slot_name, $self->get_slot_value($instance, $slot_name));
+}
+
1;
__END__
=item B<is_slot_initialized ($instance_structure, $slot_name)>
+=item B<set_slot_value_weak ($instance_structure, $slot_name, $ref_value)>
+
+=item B<weaken_slot_value>
+
+=item B<strengthen_slot_value>
+
=back
=head1 AUTHOR
it under the same terms as Perl itself.
=cut
+
use strict;
use warnings;
-use Test::More tests => 22;
+use Test::More 'no_plan';
use Test::Exception;
+use Scalar::Util qw/isweak reftype/;
+
BEGIN {
use_ok('Class::MOP::Instance');
}
is($mi_foo->get_slot_value( $i_foo, "moosen" ), "the value", "... get slot value");
ok(!$i_foo->can('moosen'), '... Foo cant moosen');
+
+can_ok( $mi_foo, "set_slot_value_weak" );
+
+my $ref = [];
+$mi_foo->set_slot_value_weak( $i_foo, "moosen", $ref );
+
+is( $mi_foo->get_slot_value( $i_foo, "moosen" ), $ref, "weak value is fetchable" );
+
+ok( !isweak($mi_foo->get_slot_value( $i_foo, "moosen" )), "return value not weak" );
+
+undef $ref;
+
+is( $mi_foo->get_slot_value( $i_foo, "moosen" ), undef, "weak value destroyed" );
+
+$ref = [];
+
+$mi_foo->set_slot_value( $i_foo, "moosen", $ref );
+
+undef $ref;
+
+is( reftype( $mi_foo->get_slot_value( $i_foo, "moosen" ) ), "ARRAY", "value not weak yet" );
+
+$mi_foo->weaken_slot_value( $i_foo, "moosen" );
+
+is( $mi_foo->get_slot_value( $i_foo, "moosen" ), undef, "weak value destroyed" );
+
+
+$ref = [];
+
+$mi_foo->set_slot_value( $i_foo, "moosen", $ref );
+
+
+$mi_foo->weaken_slot_value( $i_foo, "moosen" );
+
+$mi_foo->strengthen_slot_value( $i_foo, "moosen" );
+
+undef $ref;
+
+is( reftype( $mi_foo->get_slot_value( $i_foo, "moosen" ) ), "ARRAY", "weak value can be strengthened" );
+
+