From: Toby Inkster Date: Sun, 9 Dec 2012 12:36:26 +0000 (+0000) Subject: fix for 81181 X-Git-Tag: v1.001000~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cc3310eec740cbda10a75fdc5cd213dc2412802d;p=gitmo%2FMoo.git fix for 81181 --- diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index 3f2fa4a..372cba9 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -166,6 +166,9 @@ sub generate_method { foreach my $spec (@specs) { my ($proxy, $target, @args) = @$spec; $self->{captures} = {}; + if ( *{_getglob("${into}::${proxy}")}{CODE} ) { + die "You cannot overwrite a locally defined method ($proxy) with a delegation"; + } $methods{$proxy} = quote_sub "${into}::${proxy}" => $self->_generate_delegation($asserter, $target, \@args), diff --git a/t/accessor-handles.t b/t/accessor-handles.t index b88a700..d96abb8 100644 --- a/t/accessor-handles.t +++ b/t/accessor-handles.t @@ -74,4 +74,17 @@ is $bar->eat_curry, 'Curry!', 'handles works for currying'; is $bar->foobot, 'beep', 'asserter checks for existence not truth, on false value'; is $bar->foobar, 'bar', 'asserter checks for existence not truth, on undef '; + +{ + local $@; + ok !eval q{ + package Baz; + use Moo; + has foo => ( is => 'ro', handles => 'Robot' ); + sub smash { 1 }; + 1; + }, 'handles will not overwrite locally defined method'; + like $@, qr{You cannot overwrite a locally defined method \(smash\) with a delegation}; +} + done_testing;