From: Jesse Luehrs Date: Sun, 4 Oct 2009 03:45:40 +0000 (-0500) Subject: fix passing args to a code execute helper (gphat++) X-Git-Tag: 0.93~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6372311536b9b8292112606d45ace03d2c3dd12a;p=gitmo%2FMoose.git fix passing args to a code execute helper (gphat++) --- diff --git a/lib/Moose/Meta/Attribute/Native/MethodProvider/Code.pm b/lib/Moose/Meta/Attribute/Native/MethodProvider/Code.pm index 79f2421..7588ad0 100644 --- a/lib/Moose/Meta/Attribute/Native/MethodProvider/Code.pm +++ b/lib/Moose/Meta/Attribute/Native/MethodProvider/Code.pm @@ -7,7 +7,7 @@ our $AUTHORITY = 'cpan:STEVAN'; sub execute : method { my ( $attr, $reader, $writer ) = @_; - return sub { $reader->(@_)->(@_) }; + return sub { my ($self, @args) = @_; $reader->($self)->(@args) }; } no Moose::Role; diff --git a/t/070_native_traits/209_trait_code.t b/t/070_native_traits/209_trait_code.t index 832f48b..09159ae 100644 --- a/t/070_native_traits/209_trait_code.t +++ b/t/070_native_traits/209_trait_code.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 2; +use Test::More tests => 3; { package Thingy; @@ -14,11 +14,23 @@ use Test::More tests => 2; required => 1, handles => { 'invoke_callback' => 'execute' }, ); + + has multiplier => ( + traits => ['Code'], + is => 'ro', + isa => 'CodeRef', + required => 1, + handles => { 'multiply' => 'execute' }, + ); } my $i = 0; -my $thingy = Thingy->new(callback => sub { ++$i }); +my $thingy = Thingy->new( + callback => sub { ++$i }, + multiplier => sub { $_[0] * 2 } +); is($i, 0); $thingy->invoke_callback; is($i, 1); +is($thingy->multiply(3), 6);