Skip to content

Commit

Permalink
initial _make_delegation_method() wrapping
Browse files Browse the repository at this point in the history
...to allow us to generate custom accessors a la native traits:

    handles => {

        method_name => sub { ... accessor body (value in $_) ... }
    },

sooooooooooooooooo lazy.
  • Loading branch information
rsrchboy committed May 21, 2014
1 parent 39f50c2 commit 4c13c19
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/MooseX/AttributeShortcuts.pm
Expand Up @@ -281,6 +281,28 @@ use Moose::Util::TypeConstraints;
$class->add_method($self->builder => $self->anon_builder);
return;
};

# NOTE: remove_delegation() will automagically remove our accessors, as well

around _make_delegation_method => sub {
my ($orig, $self) = (shift, shift);
my ($name, $coderef) = @_;

### called with a: ref $coderef
return $self->$orig(@_)
unless 'CODE' eq ref $coderef;

my $custom_coderef = sub {
my $associated_class_instance = shift @_;

local $_ = $self->get_value($associated_class_instance);
return $associated_class_instance->$coderef($self, @_);
};

return $self->_process_accessors(custom => { $name => $custom_coderef });
};

return;
};
}

Expand Down

0 comments on commit 4c13c19

Please sign in to comment.