From: Yuval Kogman Date: Fri, 8 Aug 2008 22:23:25 +0000 (+0000) Subject: accept fully named args to Class::MOP::Method::wrap X-Git-Tag: 0_64_01~75 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5caf45ce90def730e4c3743050c7354a78ed9800;p=gitmo%2FClass-MOP.git accept fully named args to Class::MOP::Method::wrap --- diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index 33ad8ce..a0731b3 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -566,9 +566,12 @@ Class::MOP::Method->meta->add_attribute( ); Class::MOP::Method->meta->add_method('wrap' => sub { - my $class = shift; - my $code = shift; - my %options = @_; + my ( $class, @args ) = @_; + + unshift @args, 'body' if @args % 2 == 1; + + my %options = @args; + my $code = $options{body}; ('CODE' eq ref($code)) || confess "You must supply a CODE reference to bless, not (" . ($code || 'undef') . ")"; @@ -577,7 +580,7 @@ Class::MOP::Method->meta->add_method('wrap' => sub { || confess "You must supply the package_name and name parameters"; # return the new object - $class->meta->new_object(body => $code, %options); + $class->meta->new_object(%options); }); Class::MOP::Method->meta->add_method('clone' => sub { diff --git a/lib/Class/MOP/Method.pm b/lib/Class/MOP/Method.pm index a9b93e1..76167fe 100644 --- a/lib/Class/MOP/Method.pm +++ b/lib/Class/MOP/Method.pm @@ -29,7 +29,12 @@ before spending too much time chasing this one down. # construction sub wrap { - my ( $class, $code, %params ) = @_; + my ( $class, @args ) = @_; + + unshift @args, 'body' if @args % 2 == 1; + + my %params = @args; + my $code = $params{body}; ('CODE' eq ref($code)) || confess "You must supply a CODE reference to bless, not (" . ($code || 'undef') . ")"; diff --git a/t/031_method_modifiers.t b/t/031_method_modifiers.t index d2b695d..8b42875 100644 --- a/t/031_method_modifiers.t +++ b/t/031_method_modifiers.t @@ -16,7 +16,7 @@ BEGIN { my $trace = ''; my $method = Class::MOP::Method->wrap( - sub { $trace .= 'primary' }, + body => sub { $trace .= 'primary' }, package_name => 'main', name => '__ANON__', );