From: Arthur Axel 'fREW' Schmidt Date: Fri, 26 Apr 2013 19:04:31 +0000 (-0500) Subject: overriding delegate methods should work X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d1a419000401f658a6a74b54dcb924a103c30232;p=gitmo%2FMoose.git overriding delegate methods should work --- diff --git a/t/bugs/sub-and-handles.t b/t/bugs/sub-and-handles.t new file mode 100644 index 0000000..f183bd8 --- /dev/null +++ b/t/bugs/sub-and-handles.t @@ -0,0 +1,61 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +{ + package DelegateBar; + + use Moose; + + sub bar { 'unextended!' } + + package Does::DelegateToBar; + + use Moose::Role; + + has _barrer => ( + is => 'ro', + default => sub { DelegateBar->new }, + handles => { _bar => 'bar' }, + ); + + sub get_barrer { $_[0]->_barrer } + + package ConsumesDelegateToBar; + + use Moose; + + with 'Does::DelegateToBar'; + + has bong => ( is => 'ro' ); + + package Does::OverrideDelegate; + + use Moose::Role; + + sub _bar { 'extended' } + + package A; + + use Moose; + extends 'ConsumesDelegateToBar'; + with 'Does::OverrideDelegate'; + + has '+_barrer' => ( is => 'rw' ); + + package B; + + use Moose; + 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; +