2 package MooseX::Singleton::Meta::Instance;
4 use Scalar::Util 'weaken';
6 extends 'Moose::Meta::Instance';
9 my ($self, $instance) = @_;
11 return $instance if blessed $instance;
12 return $instance->instance;
16 my ($self, $instance, $slot_name) = @_;
17 $self->is_slot_initialized($instance, $slot_name) ? $self->instantiate($instance)->{$slot_name} : undef;
21 my ($self, $instance, $slot_name, $value) = @_;
22 $self->instantiate($instance)->{$slot_name} = $value;
25 sub deinitialize_slot {
26 my ( $self, $instance, $slot_name ) = @_;
27 delete $self->instantiate($instance)->{$slot_name};
30 sub is_slot_initialized {
31 my ($self, $instance, $slot_name, $value) = @_;
32 exists $self->instantiate($instance)->{$slot_name} ? 1 : 0;
35 sub weaken_slot_value {
36 my ($self, $instance, $slot_name) = @_;
37 weaken $self->instantiate($instance)->{$slot_name};
40 sub inline_slot_access {
41 my ($self, $instance, $slot_name) = @_;
42 sprintf "%s->meta->instance_metaclass->instantiate(%s)->{%s}", $instance, $instance, $slot_name;