From: Stevan Little Date: Fri, 23 Nov 2007 20:38:03 +0000 (+0000) Subject: adding in the last few bits X-Git-Tag: 0_47~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5da16d1b161d2a6bd31d2b7a243cc6483db43dd8;p=gitmo%2FClass-MOP.git adding in the last few bits --- diff --git a/Changes b/Changes index 96398c9..acf2053 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,11 @@ Revision history for Perl extension Class-MOP. - added the linearized_isa method instead of constantly pruning duplicate classes (this will be even more useful in the 5.10-compat version coming soon) + + * Class::MOP::Attribute + - added the get_read_method_ref and get_write_method_ref + methods which allow you to retrieve a CODE ref which + can always be used to read or write an attribute. 0.45 Thurs. Nov. 13, 2007 * Class::MOP::Attribute diff --git a/README b/README index 429861f..e44b3af 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -Class::MOP version 0.42 +Class::MOP version 0.46 =========================== See the individual module documentation for more information diff --git a/lib/Class/MOP/Attribute.pm b/lib/Class/MOP/Attribute.pm index 3da3d96..767ec1d 100644 --- a/lib/Class/MOP/Attribute.pm +++ b/lib/Class/MOP/Attribute.pm @@ -9,7 +9,7 @@ use Class::MOP::Method::Accessor; use Carp 'confess'; use Scalar::Util 'blessed', 'reftype', 'weaken'; -our $VERSION = '0.17'; +our $VERSION = '0.18'; our $AUTHORITY = 'cpan:STEVAN'; use base 'Class::MOP::Object'; @@ -136,6 +136,26 @@ sub init_arg { $_[0]->{'$!init_arg'} } sub get_read_method { $_[0]->reader || $_[0]->accessor } sub get_write_method { $_[0]->writer || $_[0]->accessor } +sub get_read_method_ref { + my $self = shift; + if (my $reader = $self->get_read_method) { + return $self->associated_class->get_method($reader); + } + else { + return sub { $self->get_value(@_) }; + } +} + +sub get_write_method_ref { + my $self = shift; + if (my $writer = $self->get_write_method) { + return $self->assocaited_class->get_method($writer); + } + else { + return sub { $self->set_value(@_) }; + } +} + sub is_default_a_coderef { ('CODE' eq (reftype($_[0]->{'$!default'} || $_[0]->{default}) || '')) } @@ -546,9 +566,20 @@ just one, which is the name of the attribute. =item B -Return the name of a method suitable for reading / writing the value of the -attribute in the associated class. Suitable for use whether C and -C or C was used. +Return the name of a method name suitable for reading / writing the value +of the attribute in the associated class. Suitable for use whether +C and C or C was used. + +=item B + +=item B + +Return the CODE reference of a method suitable for reading / writing the +value of the attribute in the associated class. Suitable for use whether +C and C or C was specified or not. + +NOTE: If not reader/writer/accessor was specified, this will use the +attribute get_value/set_value methods, which can be very inefficient. =back