-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
required
is not applied with role consuming in run-time
#88
Comments
required
is not applied with consuming role in run-time
required
is not applied with consuming role in run-time required
is not applied with role consuming in run-time
@potatogim I am having problems to reproduce. Can you please add minimal example ? |
@sergeykolychev : Sure. package MyRole;
use Moose::Role;
has 'name' =>
(
is => 'ro',
isa => 'Str',
required => 1
);
no Moose::Role;
package MyClass;
use Moose;
use Moose::Util;
sub BUILD
{
my $self = shift;
my $args = shift;
Moose::Util::apply_all_roles($self, 'MyRole');
}
__PACKAGE__->meta->make_immutable;
package main;
my $obj = MyClass->new();
1; It throws an exception like below
but, If change Moose to Mouse
Even though we can use Meta-constructor or MouseX::Traits like below(AFAIK, overriding package MyRole;
use Mouse::Role;
has 'name' =>
(
is => 'ro',
isa => 'Str',
required => 1
);
no Mouse::Role;
package MyClass;
use Mouse;
# Role consuming
with 'MouseX::Traits';
around 'new' => sub
{
my $orig = shift;
my $self = shift;
$self->with_traits('MyRole')->$orig(@_);
};
__PACKAGE__->meta->make_immutable(inline_constructor => 0);
package main;
my $obj = MyClass->new();
printf "name: %s\n", $obj->name;
1;
|
@potatogim pretty interesting usage, do you just want full parity with Moose in this case or you have a need in your application to apply roles on objects ? |
Hi @potatogim, |
@sergeykolychev : It is the latter :) |
Hello!
I'm trying to consume a role that has an attribute is specified
required
in run-time.In Moose, it works gracefully but Mouse does not throw exception even though required attribute is not specified in constructor(
MyPackage->new(...)
).The text was updated successfully, but these errors were encountered: