forked from xslate/p5-Mouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making sure that applying a role in runtime to an instance properly checks for the existence of the role's required attributes in that instance.
- Loading branch information
1 parent
25ebc09
commit 6dc4c93
Showing
5 changed files
with
70 additions
and
14 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
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,53 @@ | ||
#!perl | ||
use strict; | ||
use Test::More tests => 4; | ||
use Test::Exception; | ||
|
||
{ | ||
package Role; | ||
use Mouse::Role; | ||
has 'name' => | ||
(isa => 'Str', is => 'ro', required => 1); | ||
|
||
} | ||
|
||
{ | ||
package RoleInitArg; | ||
use Mouse::Role; | ||
has 'name' => | ||
(isa => 'Str', init_arg => 'Name', is => 'ro', required => 1); | ||
|
||
} | ||
|
||
{ | ||
package User; | ||
use Mouse; | ||
has 'name' => | ||
(isa => 'Str', is => 'ro'); | ||
|
||
sub BUILD | ||
{ | ||
my $self = shift; | ||
Mouse::Util::apply_all_roles($self, 'Role') | ||
} | ||
} | ||
|
||
{ | ||
package UserInitArg; | ||
use Mouse; | ||
has 'name' => | ||
(isa => 'Str', init_arg => 'Name', is => 'ro'); | ||
|
||
sub BUILD | ||
{ | ||
my $self = shift; | ||
Mouse::Util::apply_all_roles($self, 'RoleInitArg') | ||
} | ||
} | ||
|
||
package main; | ||
|
||
lives_ok { User->new(name => 'Tim') }, 'lives with plain attribute'; | ||
lives_ok { UserInitArg->new(Name => 'Tim') }, 'lives with init_arg'; | ||
dies_ok { User->new() }, 'dies without plain attribute'; | ||
dies_ok { UserInitArg->new() }, 'dies without init_arg'; |
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