X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FMOP%2FInstance.pm;h=e64a4c28e2c7ac83e9f99a1b76583c8e5e2cc2e7;hb=bd2550f8320262fe1ab10f6c0eedc960889d869f;hp=5b94b63ab3160544051edb5f70756ca07b565233;hpb=3e2c8600b98f2c7c0c84d1a94a565c801ca7aa3d;p=gitmo%2FClass-MOP.git diff --git a/lib/Class/MOP/Instance.pm b/lib/Class/MOP/Instance.pm index 5b94b63..e64a4c2 100644 --- a/lib/Class/MOP/Instance.pm +++ b/lib/Class/MOP/Instance.pm @@ -6,12 +6,15 @@ use warnings; use Scalar::Util 'weaken', 'blessed'; -our $VERSION = '0.97_01'; +our $VERSION = '1.12'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; use base 'Class::MOP::Object'; +# make this not a valid method name, to avoid (most) attribute conflicts +my $RESERVED_MOP_SLOT = '<>'; + sub BUILDARGS { my ($class, @args) = @_; @@ -161,6 +164,21 @@ sub is_dependent_on_superclasses { return; # for meta instances that require updates on inherited slot changes } +sub _get_mop_slot { + my ($self, $instance) = @_; + $self->get_slot_value($instance, $RESERVED_MOP_SLOT); +} + +sub _set_mop_slot { + my ($self, $instance, $value) = @_; + $self->set_slot_value($instance, $RESERVED_MOP_SLOT, $value); +} + +sub _clear_mop_slot { + my ($self, $instance) = @_; + $self->deinitialize_slot($instance, $RESERVED_MOP_SLOT); +} + # inlinable operation snippets sub is_inlinable { 1 } @@ -175,6 +193,8 @@ sub inline_slot_access { sprintf q[%s->{"%s"}], $instance, quotemeta($slot_name); } +sub inline_get_is_lvalue { 1 } + sub inline_get_slot_value { my ($self, $instance, $slot_name) = @_; $self->inline_slot_access($instance, $slot_name); @@ -214,6 +234,21 @@ sub inline_rebless_instance_structure { "bless $instance => $class_variable"; } +sub _inline_get_mop_slot { + my ($self, $instance) = @_; + $self->inline_get_slot_value($instance, $RESERVED_MOP_SLOT); +} + +sub _inline_set_mop_slot { + my ($self, $instance, $value) = @_; + $self->inline_set_slot_value($instance, $RESERVED_MOP_SLOT, $value); +} + +sub _inline_clear_mop_slot { + my ($self, $instance) = @_; + $self->inline_deinitialize_slot($instance, $RESERVED_MOP_SLOT); +} + 1; __END__ @@ -360,6 +395,11 @@ actual class name. It returns a snippet of code that creates a new object for the class. This is something like C< bless {}, $class_name >. +=item B<< $metainstance->inline_get_is_lvalue >> + +Returns whether or not C is a valid lvalue. This can be +used to do extra optimizations when generating inlined methods. + =item B<< $metainstance->inline_slot_access($instance_variable, $slot_name) >> =item B<< $metainstance->inline_get_slot_value($instance_variable, $slot_name) >>