Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 104295
Status: open
Priority: 0/
Queue: Moose

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

Bug Information
Severity: Normal
Broken in: 2.1404
Fixed in: (no value)



Subject: Metaroles can declare conflicting trait aliases
package My::Trait1 { use Moose::Role; Moose::Util::meta_attribute_alias('MyTrait'); }; package My::Trait2 { use Moose::Role; Moose::Util::meta_attribute_alias('MyTrait'); }; package My::Class { use Moose; has a => ( is => 'ro', traits => ['MyTrait'], ); }; my $attr = My::Class->meta->get_attribute('a'); print "a does $_\n" for @{$attr->applied_traits}; ------- This action-at-a-distance, which often happens in packages that are quite far away from each other, can be quite confusing. Can we get at least a warning when clobbering an alias?
On Thu May 07 10:04:18 2015, DAKKAR wrote: Show quoted text
> package My::Trait1 { > use Moose::Role; > Moose::Util::meta_attribute_alias('MyTrait'); > }; > package My::Trait2 { > use Moose::Role; > Moose::Util::meta_attribute_alias('MyTrait'); > }; > > package My::Class { > use Moose; > has a => ( > is => 'ro', > traits => ['MyTrait'], > ); > }; > > my $attr = My::Class->meta->get_attribute('a'); > print "a does $_\n" for @{$attr->applied_traits}; > > ------- > > This action-at-a-distance, which often happens in packages that are > quite far away from each other, can be quite confusing. > > Can we get at least a warning when clobbering an alias?
The problem is that there's no centralized registry of trait names. Instead, creating an alias adds a "register_implementation" method to the class that created the alias. When the short name is used later, we calculate the possible full name for the trait and call "$full_name->register_implementation" is such a method exists. What we could do is simply add a package level variable to Moose::Util to track all the aliases as they're resolved and use that to throw an error on a dupe. I think that might be sufficient to fix this.