From: Aankhen Date: Sat, 28 Apr 2007 08:32:46 +0000 (+0000) Subject: Moose::Meta::Method::Accessor: X-Git-Tag: 0_21~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c7759ac9a12706e58ab6e2be89008a5a3a497a36;p=gitmo%2FMoose.git Moose::Meta::Method::Accessor: * added pre- and post- sub body hooks in &generate_*_method methods. --- diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index a81b8db..57117e1 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -24,6 +24,7 @@ sub generate_accessor_method_inline { my $slot_name = sprintf "'%s'", $attr->slots; my $inv = '$_[0]'; my $code = 'sub { ' + . $self->_inline_pre_body($attr) . 'if (scalar(@_) == 2) {' . $self->_inline_check_required . $self->_inline_check_coercion @@ -32,6 +33,7 @@ sub generate_accessor_method_inline { . $self->_inline_trigger($inv, $value_name) . ' }' . $self->_inline_check_lazy + . $self->_inline_post_body($attr) . 'return ' . $self->_inline_auto_deref($self->_inline_get($inv)) . ' }'; @@ -54,10 +56,12 @@ sub generate_writer_method_inline { my $value_name = $attr->should_coerce ? '$val' : '$_[1]'; my $inv = '$_[0]'; my $code = 'sub { ' + . $self->_inline_pre_body($attr) . $self->_inline_check_required . $self->_inline_check_coercion . $self->_inline_check_constraint($value_name) . $self->_inline_store($inv, $value_name) + . $self->_inline_post_body($attr) . $self->_inline_trigger($inv, $value_name) . ' }'; @@ -78,8 +82,10 @@ sub generate_reader_method_inline { my $attr_name = $attr->name; my $code = 'sub {' + . $self->_inline_pre_body($attr) . 'confess "Cannot assign a value to a read-only accessor" if @_ > 1;' . $self->_inline_check_lazy + . $self->_inline_post_body($attr) . 'return ' . $self->_inline_auto_deref( '$_[0]->{$attr_name}' ) . ';' . '}';