From: Yuval Kogman Date: Fri, 28 Apr 2006 02:05:36 +0000 (+0000) Subject: various fixes + weakening support for the Class::MOP instance layout X-Git-Tag: 0_29_02~39 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=84ef30d18bb35c6ac09d1e3f7d49a27d275c88e1;p=gitmo%2FClass-MOP.git various fixes + weakening support for the Class::MOP instance layout --- diff --git a/lib/Class/MOP/Instance.pm b/lib/Class/MOP/Instance.pm index 5c1c3c8..dcc13c7 100644 --- a/lib/Class/MOP/Instance.pm +++ b/lib/Class/MOP/Instance.pm @@ -101,6 +101,17 @@ sub set_slot_value { $instance->{$slot_name} = $value; } +sub set_weak_slot_value { + my ( $self, $instance, $slot_name, $value) = @_; + $self->set_slot_value( $instance, $slot_name, $value ); + $self->weeaken_slot_value( $instance, $slot_name ); +} + +sub weaken_slot_value { + my ( $self, $instance, $slot_name ) = @_; + weaken( $instance->{$slot_name} ); +} + # convenience method # non autovivifying stores will have this as { initialize_slot unless slot_initlized; set_slot_value } sub set_slot_value_with_init { @@ -127,7 +138,20 @@ sub inline_get_slot_value { sub inline_set_slot_value { my ($self, $instance, $slot_name, $value) = @_; - $self->_inline_slot_lvalue . " = $value", + $self->_inline_slot_lvalue( $instance, $slot_name ) . " = $value", +} + +sub inline_set_weak_slot_value { + my ( $self, $instance, $slot_name, $value ) = @_; + return "" + . $self->inline_set_slot_value( $instance, $slot_name, $value ) + . "; " + . $self->inline_weaken_slot_value( $instance, $slot_name ); +} + +sub inline_weaken_slot_value { + my ( $self, $instance, $slot_name ) = @_; + return 'Scalar::Util::weaken( ' . $self->_inline_slot_lvalue( $instance, $slot_name ) . ')'; } sub inline_set_slot_value_with_init { @@ -146,7 +170,7 @@ sub inline_slot_initialized { sub _inline_slot_lvalue { my ($self, $instance, $slot_name) = @_; - $self->inline_slot_value; + $self->inline_get_slot_value( $instance, $slot_name ); } 1; @@ -233,4 +257,4 @@ L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -=cut \ No newline at end of file +=cut