From 9e2ca78efe5d76f5308b9843081e5c90a461f6f1 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 23 Sep 2009 01:26:51 -0500 Subject: handle passing in no coderef (for existing methods) --- lib/MooseX/MethodTraits.pm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/MooseX') diff --git a/lib/MooseX/MethodTraits.pm b/lib/MooseX/MethodTraits.pm index 9644e45..91155af 100644 --- a/lib/MooseX/MethodTraits.pm +++ b/lib/MooseX/MethodTraits.pm @@ -1,6 +1,6 @@ package MooseX::MethodTraits; use Moose::Exporter; -use Scalar::Util qw(blessed); +use Scalar::Util qw(blessed reftype); =head1 NAME @@ -21,14 +21,18 @@ sub _generate_method_creators { for my $sub (keys %$with_traits) { my $spec = $with_traits->{$sub}; my $traits = $spec->{traits} || []; - my $munge = $spec->{munge} || sub { shift, {@_} }; + my $munge = $spec->{munge} || sub { + my $meta = shift; + my $name = shift; + my $method = reftype($_[0]) && reftype($_[0]) eq 'CODE' + ? shift : $meta->find_method_by_name($name); + return $method, {@_}; + }; my $code = sub { + my ($method, $args) = $munge->(@_); my $meta = shift; my $name = shift; - # XXX: need to do something with $args - these should be for - # initializing attributes in the method traits that are applied - my ($method, $args) = $munge->(@_); my $superclass = blessed($method) || $meta->method_metaclass; my $method_metaclass = Moose::Meta::Class->create_anon_class( -- cgit v1.2.3-54-g00ecf