Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue where a role generated on the fly could not be used as a …
…trait
- Loading branch information
1 parent
d911341
commit a7e0e8f
Showing
4 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters