Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 92089
Status: resolved
Priority: 0/
Queue: Moose

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

Bug Information
Severity: Important
Broken in: 2.1103-TRIAL
Fixed in: 2.1806



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;
On Sun Jan 12 20:35:14 2014, MORNINDED wrote: Show quoted text
> 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;
I think you can work around this by adding the full name to %INC: $INC{'Custom/Trait/Fun1.pm'} = 1; I'm not sure if the issue you reported is really a bug or "just the way it is" with packages created on the fly.
Reworked the original PR a bit in https://github.com/moose/Moose/pull/135
On 2016-09-17 15:12:50, DROLSKY wrote: Show quoted text
> Reworked the original PR a bit in https://github.com/moose/Moose/pull/135
This was merged and will be in 2.1806. thanks!