From: Shawn M Moore Date: Thu, 29 Jan 2009 00:01:59 +0000 (+0000) Subject: Change the API of generate_role to a hash so we can specify more X-Git-Tag: 0.05~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1a8744bd532c206c08642902bdc8c473b09682c9;p=gitmo%2FMooseX-Role-Parameterized.git Change the API of generate_role to a hash so we can specify more things --- diff --git a/lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm b/lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm index c72c405..d965575 100644 --- a/lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm +++ b/lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm @@ -59,10 +59,12 @@ sub construct_parameters { } 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; @@ -81,12 +83,16 @@ sub generate_role { } 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 { diff --git a/t/002-role-block.t b/t/002-role-block.t index b30f256..e126b1a 100644 --- a/t/002-role-block.t +++ b/t/002-role-block.t @@ -33,7 +33,9 @@ do { 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'); diff --git a/t/006-requires.t b/t/006-requires.t index 9bc9ba0..d80ed52 100644 --- a/t/006-requires.t +++ b/t/006-requires.t @@ -21,7 +21,11 @@ do { sub requires_names { map { - MyRole::Requires->meta->generate_role(requires => $_)->name + MyRole::Requires->meta->generate_role( + parameters => { + requires => $_, + }, + )->name } @_ } diff --git a/t/007-excludes.t b/t/007-excludes.t index f7673d8..076d6d1 100644 --- a/t/007-excludes.t +++ b/t/007-excludes.t @@ -24,7 +24,11 @@ Moose::Meta::Role->create("Role::B"); sub excludes_roles { map { - MyRole::Excluder->meta->generate_role(exclude => $_)->name + MyRole::Excluder->meta->generate_role( + parameters => { + exclude => $_, + }, + )->name } @_ }