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