4 package MooseX::InsideOut::Meta::Instance;
7 extends 'Moose::Meta::Instance';
9 use Hash::Util::FieldHash::Compat qw(fieldhash);
10 use Scalar::Util qw(refaddr weaken);
12 # don't touch this or I beat you
13 # this is only a package variable for inlinability
14 fieldhash our %__attr;
19 #my $instance = \(my $dummy);
20 my $instance = $self->SUPER::create_instance;
22 $__attr{refaddr $instance} = {};
23 return bless $instance => $self->associated_metaclass->name;
27 my ($self, $instance, $slot_name) = @_;
29 return $__attr{refaddr $instance}->{$slot_name};
33 my ($self, $instance, $slot_name, $value) = @_;
35 return $__attr{refaddr $instance}->{$slot_name} = $value;
38 sub deinitialize_slot {
39 my ($self, $instance, $slot_name) = @_;
41 return delete $__attr{refaddr $instance}->{$slot_name};
44 sub is_slot_initialized {
45 my ($self, $instance, $slot_name) = @_;
47 return exists $__attr{refaddr $instance}->{$slot_name};
50 sub weaken_slot_value {
51 my ($self, $instance, $slot_name) = @_;
53 weaken $__attr{refaddr $instance}->{$slot_name};
56 sub inline_create_instance {
57 my ($self, $class_variable) = @_;
59 #'my $instance = \(my $dummy);',
60 # hardcoding superclass -- can't think of a good way to avoid that
61 'my $instance = Moose::Meta::Instance->create_instance;',
63 '$%s::__attr{%s} = {};',
65 'Scalar::Util::refaddr($instance)',
68 'bless $instance => %s;',
74 sub inline_slot_access {
75 my ($self, $instance, $slot_name) = @_;
76 return sprintf '$%s::__attr{%s}->{%s}',
78 'Scalar::Util::refaddr ' . $instance,
84 my ($class, $instance) = @_;
86 return Data::Dumper::Dumper($__attr{refaddr $instance});