}
sub generate_role {
- my $self = shift;
+ my $self = shift;
+ my %args = @_;
- my $parameters = @_ == 1 ? shift
- : $self->construct_parameters(@_);
+ my $parameters = blessed($args{parameters})
+ ? $args{parameters}
+ : $self->construct_parameters(%{ $args{parameters} });
confess "A role generator is required to generate roles"
unless $self->has_role_generator;
}
sub apply {
- my $self = shift;
- my $class = shift;
- my %args = @_;
+ my $self = shift;
+ my $consumer = shift;
+ my %args = @_;
+
+ my $role = $self->generate_role(
+ consumer => $consumer,
+ parameters => \%args,
+ );
- my $role = $self->generate_role(%args);
- $role->apply($class, %args);
+ $role->apply($consumer, %args);
}
sub apply_parameterizable_role {
ok(MyPerson->meta->has_role_generator, "MyPerson has a role generator");
my $role = MyPerson->meta->generate_role(
- default_age => 7,
+ parameters => {
+ default_age => 7,
+ },
);
isa_ok($role, 'Moose::Meta::Role', 'generate_role created a role');