Skip Menu |

This queue is for tickets about the Moo CPAN distribution.

Report information
The Basics
Id: 81181
Status: resolved
Priority: 0/
Queue: Moo

People
Owner: Nobody in particular
Requestors: djerius [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.000005
Fixed in: 1.001000



Subject: delegated methods override existing methods
I would like to delegate a subset of the methods provided by a role to an attribute; the rest of the methods will be provided by the class.

I expect that  this should work similarly to using a role or extending a class, namely that if I define a method in my class Moo would recognize that it existed and would not override it.
However, it doesn't look like this is the case. 

In the attached code I would like the methods foo, bar, and baz to be handled by class B.  B::baz correctly overrides My::Role2::baz, but My::Role::foo is called via the "ind" attribute instead of B::foo.
I need to explicitly override the delegation of B::bar after creating the "ind" attribute in order for B::bar to be called rather than My::Role::bar.


Subject: handles.pl
{ package My::Role; use Moo::Role; sub foo { print __PACKAGE__, "::foo\n" }; sub bar { print __PACKAGE__, "::bar\n" }; } { package My::Role2; use Moo::Role; sub baz { print __PACKAGE__, "::baz\n" }; } { package A; use Moo; with 'My::Role'; } { package B; use Moo; sub foo { print __PACKAGE__, "::foo\n" }; sub baz { print __PACKAGE__, "::baz\n" }; with 'My::Role2'; has ind => ( is => 'ro', handles => 'My::Role', default => sub { A->new } ); no warnings 'redefine', 'once'; *bar = sub { print __PACKAGE__, "::bar\n" }; } B->new->foo; B->new->bar; B->new->baz;
The Moose behaviour is to die with: "You cannot overwrite a locally defined method (foo) with a delegation"
On 2012-12-09T09:43:20Z, TOBYINK wrote: Show quoted text
> The Moose behaviour is to die with: > > "You cannot overwrite a locally defined method (foo) with a delegation"
This branch on git implements the above Moose error message for Moo: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo/ Moo.git;a=shortlog;h=refs/heads/delegation-overwriting-rt81181 Should similar messages happen for predicates, clearers, etc? What does Moose do? What about the super-secret "_assert_attribute" method? Should that overwrite a locally defined method?
This was fixed in 1.001000. The change triggered some issues in several downstream modules. Bugs have been filed for those issues.