Subject: | Roles generated on the fly can no longer be used as traits. |
I have code that registers new attribute traits based on import arguments. The code creates a new role on the fly and aliases it. This code works prior to 2.1102. It looks like the move from _load_user_class to use_module breaks this behavior by assuming that all roles that are found exist as files rather than as registered namespaces.
The commit that seems to be problematic:
https://github.com/moose/Moose/commit/718291686c1cb047a8e1ff98b44d6e83436de4b3
An example that compiles prior to the change:
{
package Custom::Trait;
use Moose::Role;
for my $number (1 .. 4) {
my $alias = "Fun$number";
my $new_role_name = __PACKAGE__ . "::$alias";
Moose::Meta::Role->initialize($new_role_name);
Moose::Exporter->setup_import_methods(exporting_package => $new_role_name);
Moose::Util::meta_attribute_alias($alias, $new_role_name);
}
}
{
package Foo;
use Moose;
use Custom::Trait;
has bar => (is => 'rw', traits => [qw{Fun1 Fun3}]);
}
my $foo = Foo->new;