X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FMOP%2FInstance.pm;h=87d201f80ba618294179c82a690be5818a3507df;hb=d004c8d565f9b314da7652e9368aeb4587ffaa3d;hp=d11b1b6b84f5367b5a68687bff2e08a62b6814c9;hpb=80d7d6350a5d1efbd6a399ef724ab8258baff30c;p=gitmo%2FClass-MOP.git diff --git a/lib/Class/MOP/Instance.pm b/lib/Class/MOP/Instance.pm index d11b1b6..87d201f 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.91'; +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) = @_; @@ -70,22 +73,11 @@ sub _new { sub _class_name { $_[0]->{_class_name} ||= $_[0]->associated_metaclass->name } -sub associated_metaclass { $_[0]{'associated_metaclass'} } - sub create_instance { my $self = shift; bless {}, $self->_class_name; } -# for compatibility -sub bless_instance_structure { - Carp::cluck('The bless_instance_structure method is deprecated.' - . " It will be removed in a future release.\n"); - - my ($self, $instance_structure) = @_; - bless $instance_structure, $self->_class_name; -} - sub clone_instance { my ($self, $instance) = @_; bless { %$instance }, $self->_class_name; @@ -170,6 +162,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 } @@ -181,10 +188,11 @@ sub inline_create_instance { sub inline_slot_access { my ($self, $instance, $slot_name) = @_; - $slot_name =~ s/(['\\])/\\$1/g; # In '', only "'" and "\\" are meta characters. - sprintf q[%s->{'%s'}], $instance, $slot_name; + 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); @@ -224,6 +232,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__ @@ -370,6 +393,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) >> @@ -425,7 +453,7 @@ Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE -Copyright 2006-2009 by Infinity Interactive, Inc. +Copyright 2006-2010 by Infinity Interactive, Inc. L