From: gfx Date: Fri, 17 Sep 2010 10:04:34 +0000 (+0900) Subject: Make Delegations work with method modifiers X-Git-Tag: 0.70~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1134f6943d6fefc9f72055de5552b2ed7ccbec45;p=gitmo%2FMouse.git Make Delegations work with method modifiers --- diff --git a/lib/Mouse/Meta/Method/Delegation.pm b/lib/Mouse/Meta/Method/Delegation.pm index f8cad5d..916c1fc 100644 --- a/lib/Mouse/Meta/Method/Delegation.pm +++ b/lib/Mouse/Meta/Method/Delegation.pm @@ -10,12 +10,13 @@ sub _generate_delegation{ ($method_to_call, @curried_args) = @{$method_to_call}; } - my $reader = $attr->get_read_method_ref(); + # If it has a reader, we must use it to make method modifiers work + my $reader = $attr->get_read_method() || $attr->get_read_method_ref(); my $can_be_optimized = $attr->{_method_delegation_can_be_optimized}; if(!defined $can_be_optimized){ - my $tc = $attr->type_constraint; + my $tc = $attr->type_constraint; $attr->{_method_delegation_can_be_optimized} = (defined($tc) && $tc->is_a_type_of('Object')) diff --git a/t/001_mouse/019-handles.t b/t/001_mouse/019-handles.t index 3dbf314..4878cc6 100644 --- a/t/001_mouse/019-handles.t +++ b/t/001_mouse/019-handles.t @@ -4,6 +4,7 @@ use warnings; use Test::More; use Test::Exception; +my $before = 0; do { package Person; use Mouse; @@ -39,6 +40,7 @@ do { handles => [qw/name age/], ); + before me => sub { $before++ }; }; can_ok(Class => qw(person has_person person_name person_age name age quid)); @@ -66,6 +68,7 @@ is($object2->person_hello, 'Hello, Philbert', 'currying'); ok($object->quid, "we have a Shawn"); is($object->name, "Shawn", "name handle"); is($object->age, 21, "age handle"); +is $before, 2, 'delegations with method modifiers'; is($object->me->name, "Shawn", "me->name"); is($object->me->age, 21, "me->age");