X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FMOP%2FInstance.pm;h=749bbc6528af547e37d2ceba6b282846b4ee95eb;hb=0b5d46da1eaa4f9d54e15c9c809b6de141d483a8;hp=7349abc9eda62d4e8b0f8ea60199be5aa4a32367;hpb=7c7fd8691722d6afa446e53d1f4c9e8f9657075d;p=gitmo%2FClass-MOP.git diff --git a/lib/Class/MOP/Instance.pm b/lib/Class/MOP/Instance.pm index 7349abc..749bbc6 100644 --- a/lib/Class/MOP/Instance.pm +++ b/lib/Class/MOP/Instance.pm @@ -6,29 +6,47 @@ use warnings; use Scalar::Util 'weaken', 'blessed'; -our $VERSION = '0.65'; +our $VERSION = '0.64_01'; +$VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; use base 'Class::MOP::Object'; -sub new { +sub BUILDARGS { my ($class, @args) = @_; if ( @args == 1 ) { - unshift @args, "metaclass"; + unshift @args, "associated_metaclass"; } elsif ( @args >= 2 && blessed($args[0]) && $args[0]->isa("Class::MOP::Class") ) { # compat mode my ( $meta, @attrs ) = @args; - @args = ( metaclass => $meta, attributes => \@attrs ); + @args = ( associated_metaclass => $meta, attributes => \@attrs ); } my %options = @args; - # FIXME lazy_build $options{slots} ||= [ map { $_->slots } @{ $options{attributes} || [] } ]; + $options{slot_hash} = { map { $_ => undef } @{ $options{slots} } }; # FIXME lazy_build + + return \%options; +} + +sub new { + my $class = shift; + my $options = $class->BUILDARGS(@_); # FIXME replace with a proper constructor - my $instance = bless { + my $instance = $class->_new(%$options); + + # FIXME weak_ref => 1, + weaken($instance->{'associated_metaclass'}); + + return $instance; +} + +sub _new { + my ( $class, %options ) = @_; + bless { # NOTE: # I am not sure that it makes # sense to pass in the meta @@ -39,32 +57,31 @@ sub new { # which is *probably* a safe # assumption,.. but you can # never tell <:) - 'meta' => $options{metaclass}, # FIXME rename to associated metaclass with a compat alias? - 'slots' => $options{slots}, - 'slot_hash' => { map { $_ => undef } @{ $options{slots} } }, # FIXME lazy_build + 'associated_metaclass' => $options{associated_metaclass}, + 'attributes' => $options{attributes}, + 'slots' => $options{slots}, + 'slot_hash' => $options{slot_hash}, } => $class; - - # FIXME weak_ref => 1, - weaken($instance->{'meta'}); - - return $instance; } -sub associated_metaclass { (shift)->{'meta'} } +sub _class_name { $_[0]->{_class_name} ||= $_[0]->associated_metaclass->name } + +sub associated_metaclass { $_[0]{'associated_metaclass'} } sub create_instance { my $self = shift; - $self->bless_instance_structure({}); + bless {}, $self->_class_name; } +# for compatibility sub bless_instance_structure { my ($self, $instance_structure) = @_; - bless $instance_structure, $self->associated_metaclass->name; + bless $instance_structure, $self->_class_name; } sub clone_instance { my ($self, $instance) = @_; - $self->bless_instance_structure({ %$instance }); + bless { %$instance }, $self->_class_name; } # operations on meta instance @@ -74,6 +91,11 @@ sub get_all_slots { return @{$self->{'slots'}}; } +sub get_all_attributes { + my $self = shift; + return @{$self->{attributes}}; +} + sub is_valid_slot { my ($self, $slot_name) = @_; exists $self->{'slot_hash'}->{$slot_name}; @@ -135,6 +157,10 @@ sub rebless_instance_structure { bless $instance, $metaclass->name; } +sub is_dependent_on_superclasses { + return; # for meta instances that require updates on inherited slot changes +} + # inlinable operation snippets sub is_inlinable { 1 } @@ -215,15 +241,18 @@ F for details). =over 4 -=item B +=item B Creates a new instance meta-object and gathers all the slots from the list of C<@attrs> given. +=item B + +Processes arguments for compatibility. + =item B -This will return a B instance which is related -to this class. +Returns the metaclass of L. =back @@ -233,16 +262,19 @@ to this class. =item B -This creates the appropriate structure needed for the instance and -then calls C to bless it into the class. +This creates the appropriate structure needed for the instance and blesses it. =item B This does just exactly what it says it does. +This method has been deprecated but remains for compatibility reasons. None of +the subclasses of L ever bothered to actually make use of +it, so it was deemed unnecessary fluff. + =item B -This too does just exactly what it says it does. +Creates a shallow clone of $instance_structure. =back @@ -266,6 +298,13 @@ given to this object in C. This will return true if C<$slot_name> is a valid slot name. +=item B + +This method returns true when the meta instance must be recreated on any +superclass changes. + +Defaults to false. + =back =head2 Operations on Instance Structures