From: Arthur Axel 'fREW' Schmidt Date: Fri, 26 Apr 2013 19:04:31 +0000 (-0500) Subject: overriding delegate methods should work X-Git-Tag: v1.002000~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0dfeb3e75a3a2fe145b1b11bbc2cf2b3649f6afb;p=gitmo%2FMoo.git overriding delegate methods should work --- diff --git a/t/sub-and-handles.t b/t/sub-and-handles.t new file mode 100644 index 0000000..2c96ad7 --- /dev/null +++ b/t/sub-and-handles.t @@ -0,0 +1,59 @@ +use strictures 1; +use Test::More; + +{ + package DelegateBar; + + use Moo; + + sub bar { 'unextended!' } + + package Does::DelegateToBar; + + use Moo::Role; + + has _barrer => ( + is => 'ro', + default => sub { DelegateBar->new }, + handles => { _bar => 'bar' }, + ); + + sub get_barrer { $_[0]->_barrer } + + package ConsumesDelegateToBar; + + use Moo; + + with 'Does::DelegateToBar'; + + has bong => ( is => 'ro' ); + + package Does::OverrideDelegate; + + use Moo::Role; + + sub _bar { 'extended' } + + package A; + + use Moo; + extends 'ConsumesDelegateToBar'; + with 'Does::OverrideDelegate'; + + has '+_barrer' => ( is => 'rw' ); + + package B; + + use Moo; + extends 'ConsumesDelegateToBar'; + + sub _bar { 'extended' } + + has '+_barrer' => ( is => 'rw' ); +} + +is(A->new->_bar, 'extended', 'overriding delegate method with role works'); +is(B->new->_bar, 'extended', 'overriding delegate method directly works'); + +done_testing; +