From: Yuval Kogman Date: Wed, 19 Aug 2009 21:37:45 +0000 (+0300) Subject: Add {get,set}_raw_value methods X-Git-Tag: 0.94~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7e5efe1512942869afb34fa2b58616c0aac98998;p=gitmo%2FClass-MOP.git Add {get,set}_raw_value methods Side-effect free versions of {get,set}_value --- diff --git a/lib/Class/MOP/Attribute.pm b/lib/Class/MOP/Attribute.pm index 6b26e95..28e41cd 100644 --- a/lib/Class/MOP/Attribute.pm +++ b/lib/Class/MOP/Attribute.pm @@ -305,7 +305,10 @@ sub set_initial_value { ); } -sub set_value { +sub set_value { shift->set_raw_value(@_) } +sub get_value { shift->get_raw_value(@_) } + +sub set_raw_value { my ($self, $instance, $value) = @_; Class::MOP::Class->initialize(ref($instance)) @@ -313,7 +316,7 @@ sub set_value { ->set_slot_value($instance, $self->name, $value); } -sub get_value { +sub get_raw_value { my ($self, $instance) = @_; Class::MOP::Class->initialize(ref($instance)) @@ -827,6 +830,12 @@ It's unlikely that you'll need to call this method yourself. Sets the value without going through the accessor. Note that this works even with read-only attributes. +=item B<< $attr->set_raw_value($instance, $value) >> + +Sets the value with no side effects such as a trigger. + +This doesn't actually apply to Class::MOP attributes, only to subclasses. + =item B<< $attr->set_initial_value($instance, $value) >> Sets the value without going through the accessor. This method is only @@ -837,6 +846,12 @@ called when the instance is first being initialized. Returns the value without going through the accessor. Note that this works even with write-only accessors. +=item B<< $sttr->get_raw_value($instance) >> + +Returns the value without any side effects such as lazy attributes. + +Doesn't actually apply to Class::MOP attributes, only to subclasses. + =item B<< $attr->has_value($instance) >> Return a boolean indicating whether the attribute has been set in diff --git a/t/014_attribute_introspection.t b/t/014_attribute_introspection.t index 34b09cc..8eb82ce 100644 --- a/t/014_attribute_introspection.t +++ b/t/014_attribute_introspection.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 69; +use Test::More tests => 71; use Test::Exception; use Class::MOP; @@ -41,6 +41,8 @@ use Class::MOP; slots get_value set_value + get_raw_value + set_raw_value set_initial_value has_value clear_value