# included for completeness
Class::MOP::Instance->meta->add_attribute(
- Class::MOP::Attribute->new('associated_metaclass')
+ Class::MOP::Attribute->new('associated_metaclass',
+ reader => { associated_metaclass => \&Class::MOP::Instance::associated_metaclass },
+ ),
);
Class::MOP::Instance->meta->add_attribute(
- Class::MOP::Attribute->new('attributes')
+ Class::MOP::Attribute->new('_class_name',
+ init_arg => undef,
+ reader => { _class_name => \&Class::MOP::Instance::_class_name },
+ #lazy => 1, # not yet supported by Class::MOP but out our version does it anyway
+ #default => sub { $_[0]->associated_metaclass->name },
+ ),
+);
+
+Class::MOP::Instance->meta->add_attribute(
+ Class::MOP::Attribute->new('attributes',
+ reader => { attributes => \&Class::MOP::Instance::attributes },
+ ),
);
Class::MOP::Instance->meta->add_attribute(
- Class::MOP::Attribute->new('slots')
+ Class::MOP::Attribute->new('slots',
+ reader => { slots => \&Class::MOP::Instance::slots },
+ ),
);
Class::MOP::Instance->meta->add_attribute(
- Class::MOP::Attribute->new('slot_hash')
+ Class::MOP::Attribute->new('slot_hash',
+ reader => { slot_hash => \&Class::MOP::Instance::slot_hash },
+ ),
);
# assumption,.. but you can
# never tell <:)
'associated_metaclass' => $options->{associated_metaclass},
- 'attributes' => $options->{attributes},
- 'slots' => $options->{slots},
- 'slot_hash' => $options->{slot_hash},
+ 'attributes' => $options->{attributes},
+ 'slots' => $options->{slots},
+ 'slot_hash' => $options->{slot_hash},
} => $class;
# FIXME weak_ref => 1,
return $instance;
}
-sub associated_metaclass { (shift)->{'associated_metaclass'} }
+sub _class_name { $_[0]->{_class_name} ||= $_[0]->associated_metaclass->name }
+
+sub associated_metaclass { $_[0]{'associated_metaclass'} }
sub create_instance {
my $self = shift;
sub bless_instance_structure {
my ($self, $instance_structure) = @_;
- bless $instance_structure, $self->associated_metaclass->name;
+ bless $instance_structure, $self->_class_name;
}
sub clone_instance {