From: Yuval Kogman Date: Sun, 27 Jan 2008 15:45:32 +0000 (+0000) Subject: get_{init_args,attribute_values} X-Git-Tag: 0_53~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1a4705beda3d8970cbc37cc9d7a4e4619dd1eb8a;p=gitmo%2FClass-MOP.git get_{init_args,attribute_values} --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index da44190..2e51b9f 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -433,6 +433,27 @@ sub rebless_instance { } } +sub get_attribute_values { + my ($self, $instance) = @_; + + return +{ + map { $_->name => $_->get_value($instance) } + grep { $_->has_value($instance) } + $self->>compute_all_applicable_attributes + }; +} + +sub get_init_args { + my ($self, $instance) = @_; + + return +{ + map { $_->init_arg => $_->get_value($instance) } + grep { $_->has_value($instance) } + grep { defined($_->init_arg) } + $self->compute_all_applicable_attributes + }; +} + # Inheritance sub superclasses { @@ -1125,6 +1146,16 @@ shallow cloning is outside the scope of the meta-object protocol. I think Yuval "nothingmuch" Kogman put it best when he said that cloning is too I to be part of the MOP. +=item B + +Returns the values of the C<$instance>'s fields keyed by the attribute names. + +=item B + +Returns a hash reference where the keys are all the attributes' Cs +and the values are the instance's fields. Attributes without an C +will be skipped. + =item B This will change the class of C<$instance> to the class of the invoking diff --git a/lib/Class/MOP/Instance.pm b/lib/Class/MOP/Instance.pm index a9612a9..baac84b 100644 --- a/lib/Class/MOP/Instance.pm +++ b/lib/Class/MOP/Instance.pm @@ -122,16 +122,6 @@ sub rebless_instance_structure { bless $instance, $metaclass->name; } -sub get_all_slot_values { - my ($self, $instance) = @_; - - return +{ - map { $_->name => $_->get_value($instance) } - grep { $_->has_value($instance) } - $self->associated_metaclass->compute_all_applicable_attributes - }; -} - # inlinable operation snippets sub is_inlinable { 1 } @@ -284,8 +274,6 @@ require that the C<$instance_structure> is passed into them. =item B -=item B - =item B =item B