Skip Menu |

This queue is for tickets about the Moo CPAN distribution.

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

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

Bug Information
Severity: Important
Broken in: 1.004002
Fixed in: (no value)



Subject: attributes in a role override existing attributes
My understanding is that when consuming a role neither existing methods nor attributes would be overridden. However that doesn't seem to be the case for attributes. It seems that the last attribute loaded is the one which is implemented, rather than the first. Attached are two tests; one using Moo, the other Moose. The Moose one passes, the Moo one doesn't.
Subject: test-moo.pl
#! perl use Test::More; { package R1; use Moo::Role; has attr => ( is => 'ro', default => sub { __PACKAGE__ } ); sub meth { __PACKAGE__ } } { package R2; use Moo::Role; has attr => ( is => 'ro', default => sub { __PACKAGE__ }); sub meth { __PACKAGE__ } } { package A; use Moo; has attr => ( is => 'ro', default => sub { __PACKAGE__ }); with 'R1'; with 'R2'; } is( A->new->attr, 'A', "don't override existing attribute in A" ); is( A->new->meth, 'R1', 'get method from R1' );
Subject: test-moose.pl
#! perl use Test::More; { package R1; use Moose::Role; has attr => ( is => 'ro', default => sub { __PACKAGE__ } ); sub meth { __PACKAGE__ } } { package R2; use Moose::Role; has attr => ( is => 'ro', default => sub { __PACKAGE__ }); sub meth { __PACKAGE__ } } { package A; use Moose; has attr => ( is => 'ro', default => sub { __PACKAGE__ }); with 'R1'; with 'R2'; } is( A->new->attr, 'A', "don't override existing attribute in A" ); is( A->new->meth, 'R1', 'get method from R1' );
On Wed Mar 12 19:29:37 2014, DJERIUS wrote: Show quoted text
> My understanding is that when consuming a role neither existing > methods nor attributes would be overridden. > > However that doesn't seem to be the case for attributes. It seems > that the last attribute loaded is the one which is implemented, rather > than the first. > > Attached are two tests; one using Moo, the other Moose. The Moose one > passes, the Moo one doesn't.
Here's a possible fix: https://github.com/moose/Moo/pull/4
Fixed in git, using your patch with some additional changes on top.
Fixed in 1.007000
On Wed Jan 21 10:03:10 2015, haarg wrote: Show quoted text
> Fixed in 1.007000
Thanks!