Skip to content

Commit

Permalink
Fixed issue where a role generated on the fly could not be used as a …
Browse files Browse the repository at this point in the history
…trait
  • Loading branch information
aarondcohen authored and autarch committed Sep 17, 2016
1 parent d911341 commit a7e0e8f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Changes
Expand Up @@ -3,6 +3,12 @@ for, noteworthy changes.

{{$NEXT}}

[BUG FIXES}

- A role generated on the fly (as opposed to one in a file on disk) could
not be used as a trait. Fixed by Aaron Cohen. (RT#92089, PR#47).


2.1805 2016-08-19

[BUG FIXES]
Expand Down
4 changes: 2 additions & 2 deletions lib/Moose/Util.pm
Expand Up @@ -4,7 +4,7 @@ our $VERSION = '2.1806';
use strict;
use warnings;

use Module::Runtime 0.014 'use_package_optimistically', 'use_module', 'module_notional_filename';
use Module::Runtime 0.014 'use_package_optimistically', 'module_notional_filename';
use Data::OptList;
use Params::Util qw( _STRING );
use Sub::Exporter;
Expand Down Expand Up @@ -144,7 +144,7 @@ sub _apply_all_roles {
$meta = $role->[0];
}
else {
&use_module($role->[0], $role->[1] && $role->[1]{-version} ? $role->[1]{-version} : ());
_load_user_class( $role->[0] , $role->[1] );
$meta = find_meta( $role->[0] );
}

Expand Down
46 changes: 46 additions & 0 deletions t/bugs/find_custom_trait_rt_92089.t
@@ -0,0 +1,46 @@
use strict;
use warnings;

use Test::More;
use Test::Fatal;

{
package Custom::Trait;
use Moose::Role;

my $alias = 'Trait1';
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 );
}

is(
exception {
package Foo;
use Moose;
use Custom::Trait;

has field1 => ( is => 'rw', traits => [qw{Trait1}] );

Foo->new;
},
undef,
'Trait that is not an on-disk role works'
);

like(
exception {
package Bar;
use Moose;
use Custom::Trait;

has field1 => ( is => 'rw', traits => [qw{UndeclaredTrait}] );
Bar->new;
},
qr/\QCan't locate Moose::Meta::Attribute::Custom::Trait::UndeclaredTrait or UndeclaredTrait/,
'Traits with no alias or package cause an exception'
);

done_testing();
2 changes: 1 addition & 1 deletion t/exceptions/util.t
Expand Up @@ -97,7 +97,7 @@ use Moose::Util qw/apply_all_roles add_method_modifier/;

like(
$exception,
qr!Can't locate Not/A/Real/Package\.pm in \@INC!,
qr!You can only consume roles, Not::A::Real::Package is not a Moose role!,
"You can't consume a class which doesn't exist");

$exception = exception {
Expand Down

0 comments on commit a7e0e8f

Please sign in to comment.